Dynamically load screens to save RAM.

Todo: make debug screen show things again.
This commit is contained in:
Moirtz Wagner 2025-11-09 19:22:40 +01:00
parent 98e13492ea
commit d11f49a43d
8 changed files with 543 additions and 446 deletions

View File

@ -0,0 +1,82 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"files.associations": {
"styles.h": "c",
"string.h": "c",
"system_error": "cpp",
"random": "c",
"screens.h": "c",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ratio": "cpp",
"regex": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"format": "cpp",
"ui.h": "c",
"lvgl.h": "c",
"symbols.h": "c",
"arduino.h": "c",
"actions.h": "c",
"glbldata.h": "c",
"vars.h": "c"
}
}
}

View File

@ -14,8 +14,8 @@ board = seeed_xiao_esp32c3
monitor_speed = 115200
framework = arduino
board_build.partitions = min_spiffs.csv
upload_protocol = espota
upload_port = TMP-EG-WoZi.fritz.box
;upload_protocol = espota
;upload_port = TMP-EG-WoZi.fritz.box
lib_deps =
moononournation/GFX Library for Arduino@^1.5.3
lvgl/lvgl@^9.2.2

View File

@ -123,7 +123,7 @@ void setup(void)
measurementTick.attach(MEASINT_S,measure);
mqtt.begin();
getLocalTime(&glblData.bootTime);
lv_label_set_text_fmt(objects.debugTxt, "IP:\n %s\n\nHostname:\n %s\n\nMqtt-Server:\n %s\n\nMqtt-Port:\n %d\n\nMqtt-Topic:\n %s\n\nHeatBuffer:\n %d",glblData.myIP,Settings::prefs.hostname,Settings::prefs.mqtt_server,Settings::prefs.mqtt_port, Settings::prefs.mqtt_topic,glblData.enBuff);
//lv_label_set_text_fmt(objects.debugTxt, "IP:\n %s\n\nHostname:\n %s\n\nMqtt-Server:\n %s\n\nMqtt-Port:\n %d\n\nMqtt-Topic:\n %s\n\nHeatBuffer:\n %d",glblData.myIP,Settings::prefs.hostname,Settings::prefs.mqtt_server,Settings::prefs.mqtt_port, Settings::prefs.mqtt_topic,glblData.enBuff);
measure();
esp_reset_reason_t reason = esp_reset_reason();
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW)) {
@ -151,7 +151,7 @@ void loop()
if(newHistory){
newHistory=false;
chart_autoscale();
lv_chart_refresh(objects.chart);
}
if(millis() - minutesTick > 60000){
minutesTick = millis();

View File

@ -1,6 +1,5 @@
#include <Arduino.h>
#include "actions.h"
#include <Arduino.h>
bool arc_pressed = false;
bool animating = false;
@ -9,7 +8,8 @@ float curr_temp = 0.0;
int32_t scale_max = 0, scale_min = 0, lastSelChartValue = 0;
lv_point_t lastChartPt;
void update_sensorNstatus(float temp, float hum, float seaLevelPress, bool presAlarm){
void update_sensorNstatus(float temp, float hum, float seaLevelPress,
bool presAlarm) {
glblData.temp = temp;
glblData.hum = hum;
glblData.seaLevelPress = seaLevelPress;
@ -17,6 +17,9 @@ void update_sensorNstatus(float temp, float hum, float seaLevelPress, bool presA
update_status();
}
void update_clockdots(void) {
if (ui_getCurrentScreen() != objects.mainScr) {
return;
}
static bool dotState = false;
dotState = !dotState;
char *time = lv_label_get_text(objects.time_txt);
@ -29,35 +32,66 @@ void update_clockdots(void){
}
}
static void alarm_ani_cb(void * var, int32_t v)
{
if(v > -1 && v < 256){
lv_led_set_brightness(objects.alarmLED, v);
setBacklight((v<<4) | 0x00FF,100);
}
}
static void alarm_ani_end_cb(lv_anim_t *var)
{
lv_obj_add_flag(objects.alarmLED, LV_OBJ_FLAG_HIDDEN);
setBacklight(BL_BRIGHTNESS,250);
lv_led_set_brightness(objects.alarmLED, 0);
}
void ui_settemp(float tmp) {
if (ui_getCurrentScreen() != objects.mainScr) {
return;
}
lv_arc_set_value(objects.temp_arc, (int32_t)(tmp));
}
void update_status(void) {
static unsigned long fullOnTime = millis();
switch (glblData.override) {
case OVR_NONE:
if (glblData.temp < glblData.settemp - TMP_HYST) {
glblData.heating = true;
} else if (glblData.temp > glblData.settemp + TMP_HYST) {
glblData.heating = false;
}
break;
case OVR_ALWAYSON:
if (glblData.temp < glblData.settemp + 3.0) { // allow for 3degC overheating
glblData.heating = true;
} else {
glblData.heating = false;
}
break;
case OVR_ALWAYSOFF:
if (glblData.temp < 12) { // ensure minimum of 12°C
glblData.heating = true;
} else {
glblData.heating = false;
}
break;
}
if (glblData.heating) {
if (ledcRead(PWM_REL) == 0) {
ledcWrite(PWM_REL, 0xff); // turn on relay
fullOnTime = millis();
} else if (millis() - fullOnTime > 1000 &&
glblData.relPowerSave ==
true) { // if relay is on for more than 1 sec, reduce to
// 50% if powersave mode is enabled
ledcWrite(PWM_REL, 0x7f); // lower relay to 50%
}
} else {
ledcWrite(PWM_REL, 0); // turn off relay
}
if (ui_getCurrentScreen() != objects.mainScr) {
return;
}
tm timeinfo;
getLocalTime(&timeinfo);
char buffer[15];
strftime(buffer, sizeof(buffer), "%H : %M", &timeinfo);
static unsigned long fullOnTime = millis();
lv_label_set_text_fmt(objects.press_txt, "%4.2f hPa", glblData.seaLevelPress);
lv_label_set_text_fmt(objects.hum_txt, "%2.0f %%rH", glblData.hum);
lv_label_set_text_fmt(objects.outTemp_txt,ICON_THERMOMETER_SNOW "%2.1f °C",glblData.outTemp);
lv_label_set_text_fmt(objects.outTemp_txt, ICON_THERMOMETER_SNOW "%2.1f °C",
glblData.outTemp);
lv_label_set_text(objects.time_txt, buffer);
if (!arc_pressed && !animating) {
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.temp);
@ -72,73 +106,46 @@ void update_status(void){
}
switch (glblData.override) {
case OVR_NONE:
lv_obj_set_style_text_color(objects.bufferIcn,lv_color_hex(0xFFfafafa),LV_STATE_DEFAULT);
if(glblData.temp < glblData.settemp-TMP_HYST){
glblData.heating = true;
}
else if(glblData.temp > glblData.settemp+TMP_HYST){
glblData.heating = false;
}
lv_obj_set_style_text_color(objects.bufferIcn, lv_color_hex(0xFFfafafa),
LV_STATE_DEFAULT);
break;
case OVR_ALWAYSON:
lv_obj_set_style_text_color(objects.bufferIcn,lv_color_hex(0xFF00AA00),LV_STATE_DEFAULT);
if(glblData.temp < glblData.settemp+3.0){ //allow for 3degC overheating
glblData.heating = true;
}
else{
glblData.heating = false;
}
lv_obj_set_style_text_color(objects.bufferIcn, lv_color_hex(0xFF00AA00),
LV_STATE_DEFAULT);
break;
case OVR_ALWAYSOFF:
lv_obj_set_style_text_color(objects.bufferIcn,lv_color_hex(0xFFAA0000),LV_STATE_DEFAULT);
if(glblData.temp < 12){ //ensure minimum of 12°C
glblData.heating = true;
}
else{
glblData.heating = false;
}
lv_obj_set_style_text_color(objects.bufferIcn, lv_color_hex(0xFFAA0000),
LV_STATE_DEFAULT);
break;
}
if (glblData.heating) {
if(ledcRead(PWM_REL) == 0){
ledcWrite(PWM_REL, 0xff); //turn on relay
fullOnTime = millis();
lv_obj_set_style_text_color(objects.heaterIcn,lv_color_hex(0xFFAA0000),LV_STATE_DEFAULT);
}else if(millis() - fullOnTime > 1000 && glblData.relPowerSave == true){ //if relay is on for more than 1 sec, reduce to 50% if powersave mode is enabled
ledcWrite(PWM_REL, 0x7f); //lower relay to 50%
lv_obj_set_style_text_color(objects.heaterIcn,lv_color_hex(0xFF00AA00),LV_STATE_DEFAULT);
if (ledcRead(PWM_REL) < 0xff) { //relay in power save mode
lv_obj_set_style_text_color(objects.heaterIcn, lv_color_hex(0xFF00AA00),
LV_STATE_DEFAULT);
} else{ //relay full on
lv_obj_set_style_text_color(objects.heaterIcn, lv_color_hex(0xFFAA0000),
LV_STATE_DEFAULT);
}
lv_obj_remove_flag(objects.heaterIcn, LV_OBJ_FLAG_HIDDEN);
} else {
ledcWrite(PWM_REL, 0); //turn off relay
ledcWrite(PWM_REL, 0); //relay off
lv_obj_add_flag(objects.heaterIcn, LV_OBJ_FLAG_HIDDEN);
}
if(glblData.presAlarm == true){
lv_obj_remove_flag(objects.alarmLED, LV_OBJ_FLAG_HIDDEN);
lv_anim_t alarmAni;
lv_anim_init(&alarmAni);
lv_anim_set_values(&alarmAni, 0, 255);
lv_anim_set_duration(&alarmAni, 600);
lv_anim_set_playback_delay(&alarmAni, 0);
lv_anim_set_playback_duration(&alarmAni, 600);
lv_anim_set_repeat_delay(&alarmAni, 100);
lv_anim_set_repeat_count(&alarmAni,7);
lv_anim_set_exec_cb(&alarmAni, alarm_ani_cb);
lv_anim_set_path_cb(&alarmAni, lv_anim_path_ease_in_out);
lv_anim_set_completed_cb(&alarmAni,alarm_ani_end_cb);
lv_anim_start(&alarmAni);
ui_exitSleep();
}
}
void update_wifi_strength(wifistrength_t strength, wifimode_t mode) {
if (ui_getCurrentScreen() != objects.mainScr) {
return;
}
if (ui_getCurrentScreen() == objects.mainScr) {
if (mode != WIFIMODE_STA) {
Serial.println("WiFi mode not STA, not updating icon");
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xFF0000EE),LV_STATE_DEFAULT);
lv_obj_set_style_text_color(objects.wifiIcn, lv_color_hex(0xFF0000EE),
LV_STATE_DEFAULT);
} else {
Serial.println("WiFi mode STA, updating icon");
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xf0f0f0),LV_STATE_DEFAULT);
lv_obj_set_style_text_color(objects.wifiIcn, lv_color_hex(0xf0f0f0),
LV_STATE_DEFAULT);
}
switch (strength) {
case WIFISTRENGTH_HIGH:
@ -154,11 +161,13 @@ void update_wifi_strength(wifistrength_t strength, wifimode_t mode){
lv_label_set_text(objects.wifiIcn, ICON_WIFI_OFF);
break;
case WIFISTRENGTH_ERROR:
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xFF0000),LV_STATE_DEFAULT);
lv_obj_set_style_text_color(objects.wifiIcn, lv_color_hex(0xFF0000),
LV_STATE_DEFAULT);
lv_label_set_text(objects.wifiIcn, ICON_WIFI_OFF);
break;
}
}
}
void chartDrawingCB(lv_event_t *e) {
lv_event_code_t code = lv_event_get_code(e);
@ -180,7 +189,12 @@ void chartDrawingCB(lv_event_t * e){
draw_line_dsc.dash_gap = 1;
draw_line_dsc.dash_width = 2;
draw_line_dsc.p1.x = chart_obj_coords.x1 + 5;
draw_line_dsc.p1.y = lv_obj_get_y2(objects.y_scale) - (lv_obj_get_height(objects.y_scale)*(lv_arc_get_value(objects.temp_arc)-scale_min)*10)/((scale_max-scale_min)*10) -1;
draw_line_dsc.p1.y =
lv_obj_get_y2(objects.y_scale) -
(lv_obj_get_height(objects.y_scale) *
(lv_arc_get_value(objects.temp_arc) - scale_min) * 10) /
((scale_max - scale_min) * 10) -
1;
draw_line_dsc.p2.x = chart_obj_coords.x2 - 5;
draw_line_dsc.p2.y = draw_line_dsc.p1.y;
lv_draw_line(layer, &draw_line_dsc);
@ -201,7 +215,6 @@ void chartDrawingCB(lv_event_t * e){
draw_rect_dsc.bg_opa = LV_OPA_50;
draw_rect_dsc.radius = 3;
lv_area_t rect_area;
// rect_area.x1 = lastChartPt.x - 35;
rect_area.x1 = chart_obj_coords.x1 + lastChartPt.x - 35;
@ -211,7 +224,9 @@ void chartDrawingCB(lv_event_t * e){
rect_area.x1 = chart_obj_coords.x2 - 70;
}
rect_area.x2 = rect_area.x1 + 70;
rect_area.y1 = chart_obj_coords.y1 + 5; //lastChartPt.y - 30; -->always draw it at the top of the chart
rect_area.y1 =
chart_obj_coords.y1 +
5; // lastChartPt.y - 30; -->always draw it at the top of the chart
rect_area.y2 = chart_obj_coords.y1 + 25; // lastChartPt.y - 10;
lv_draw_rect(layer, &draw_rect_dsc, &rect_area);
@ -221,15 +236,18 @@ void chartDrawingCB(lv_event_t * e){
switch (ui_getCurrentChart()) {
case CHART_ID_TEMP:
if (lastSelChartValue > INT32_MIN)
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"%0.1f °C", lastSelChartValue/10.0);
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY "%0.1f °C",
lastSelChartValue / 10.0);
break;
case CHART_ID_HUM:
if (lastSelChartValue > INT32_MIN)
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"%d %%rH", lastSelChartValue);
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY "%d %%rH",
lastSelChartValue);
break;
case CHART_ID_PRESS:
if (lastSelChartValue > INT32_MIN)
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"%d hPa", lastSelChartValue);
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY "%d hPa",
lastSelChartValue);
break;
}
lv_draw_label_dsc_t draw_label_dsc;
@ -239,7 +257,8 @@ void chartDrawingCB(lv_event_t * e){
draw_label_dsc.text_local = 1;
draw_label_dsc.align = LV_TEXT_ALIGN_CENTER;
lv_area_t label_area = rect_area;
lv_area_set_height(&label_area, lv_font_get_line_height(draw_label_dsc.font));
lv_area_set_height(&label_area,
lv_font_get_line_height(draw_label_dsc.font));
lv_area_align(&rect_area, &label_area, LV_ALIGN_CENTER, 0, 0);
lv_draw_label(layer, &draw_label_dsc, &label_area);
@ -249,6 +268,9 @@ void chartDrawingCB(lv_event_t * e){
}
void chart_autoscale(void) {
if (ui_getCurrentScreen() != objects.chartScr) {
return;
}
int32_t *numbers = lv_chart_get_y_array(objects.chart, objects.chart_series);
int32_t max = INT32_MIN, min = INT32_MAX;
uint32_t delta, factor = 1, gridFactor = 1;
@ -289,14 +311,17 @@ void chart_autoscale(void){
min *= 10 * gridFactor;
scale_min = min;
scale_max = min + 50 * gridFactor;
}else{ //major tick every 50.0 should never happen because of scaler in while loop above
} else { // major tick every 50.0 should never happen because of scaler in
// while loop above
min /= 50 * gridFactor;
min *= 50 * gridFactor;
scale_min = min;
scale_max = min + 250 * gridFactor;
}
lv_chart_set_range(objects.chart, LV_CHART_AXIS_PRIMARY_Y, scale_min*factor, scale_max*factor);
lv_chart_set_range(objects.chart, LV_CHART_AXIS_PRIMARY_Y, scale_min * factor,
scale_max * factor);
lv_scale_set_range(objects.y_scale, scale_min, scale_max);
lv_chart_refresh(objects.chart);
}
void zoomAniWrapper(void *var, int32_t val) {
@ -307,14 +332,18 @@ void zoomAniWrapper(void *var, int32_t val){
lv_obj_set_style_transform_scale(obj, 255 + val / 4, 0);
lv_obj_set_style_text_opa(objects.hum_txt, 255 - val, 0);
lv_obj_set_style_text_opa(objects.press_txt, 255 - val, 0);
lv_obj_set_style_text_opa(objects.outTemp_txt, 255 - val, 0);
lv_obj_set_style_text_opa(objects.time_txt, 255 - val, 0);
}
void zomFinishedCB(lv_anim_t *var) {
if (arc_pressed) {
arc_pressed = false;
animating = false;
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.temp);
}else if(ui_getCurrentScreen() == SCREEN_ID_MAIN){ // only set arc pressed true if main screen is still active, otherwise we'll lock screen switching
} else if (ui_getCurrentScreen() == objects.mainScr) {
// only set arc pressed true if main screen is
// still active, otherwise we'll lock screen
// switching
arc_pressed = true;
animating = false;
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.settemp);
@ -335,8 +364,7 @@ void action_zoom_set_temp(lv_event_t * e){
lv_anim_set_completed_cb(&a, zomFinishedCB);
lv_anim_start(&a);
}
}
else{
} else {
if (arc_pressed == true && animating == false) {
animating = true;
lv_anim_t a;
@ -351,13 +379,12 @@ void action_zoom_set_temp(lv_event_t * e){
lv_anim_start(&a);
}
}
//lv_label_set_text_fmt(objects.temp_txt,"%2.1f °C",lv_arc_get_value(objects.temp_arc)/2.0);
// lv_label_set_text_fmt(objects.temp_txt,"%2.1f
// °C",lv_arc_get_value(objects.temp_arc)/2.0);
update_status();
}
static void anim_height_cb(void * var, int32_t v)
{
static void anim_height_cb(void *var, int32_t v) {
lv_obj_t *obj = (lv_obj_t *)var;
lv_obj_set_height(obj, v);
}
@ -384,8 +411,7 @@ void action_switch_screens(lv_event_t * e){
lv_anim_start(&a);
if (ui_getCurrentChart() == CHART_ID_LEN - 1) {
loadChart(1);
}
else{
} else {
loadChart(ui_getCurrentChart() + 1);
}
lv_indev_wait_release(lv_indev_active());
@ -395,20 +421,30 @@ void action_switch_screens(lv_event_t * e){
}
}
void showChartScreen(lv_event_t *e) {
if (ui_getCurrentScreen() != objects.chartScr) {
create_screen_chart();
loadChart(0);
loadScreen(SCREEN_ID_CHART);
}
loadScreen(objects.chartScr);
}
void showDebugScreen(lv_event_t *e) {
loadScreen(SCREEN_ID_DEBUG);
if (ui_getCurrentScreen() != objects.debugScr) {
create_screen_debug();
}
loadScreen(objects.debugScr);
}
void rebootESP(lv_event_t * e){
ESP.restart();
}
void rebootESP(lv_event_t *e) { ESP.restart(); }
void showMainScreen(lv_event_t *e) {
loadScreen(SCREEN_ID_MAIN);
if (ui_getCurrentScreen() != objects.mainScr) {
create_screen_main();
update_status();
ui_settemp(glblData.settemp);
}
loadScreen(objects.mainScr);
Serial.println("Main screen loaded");
}
void action_show_cursors_cb(lv_event_t *e) {
@ -421,12 +457,11 @@ void action_show_cursors_cb(lv_event_t * e){
}
}
void draw_event_cb(lv_event_t * e)
{
void draw_event_cb(lv_event_t *e) {
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
lv_draw_task_t *draw_task = lv_event_get_draw_task(e);
lv_draw_dsc_base_t * base_dsc = (lv_draw_dsc_base_t*) lv_draw_task_get_draw_dsc(draw_task);
lv_draw_dsc_base_t *base_dsc =
(lv_draw_dsc_base_t *)lv_draw_task_get_draw_dsc(draw_task);
lv_draw_label_dsc_t *label_draw_dsc = lv_draw_task_get_label_dsc(draw_task);
if (base_dsc->part == LV_PART_INDICATOR) {
if (label_draw_dsc) {
@ -434,7 +469,6 @@ void draw_event_cb(lv_event_t * e)
if (base_dsc->id1 == 0) {
label_draw_dsc->color = lv_color_black();
}
}
}
}

View File

@ -17,24 +17,12 @@ lv_obj_t *tick_value_change_obj;
void create_screen_main() {
lv_obj_t *obj = lv_obj_create(0);
objects.main = obj;
objects.mainScr = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 240, 240);
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)0);
{
lv_obj_t *parent_obj = obj;
{
lv_obj_t *obj = lv_led_create(parent_obj);
objects.alarmLED = obj;
lv_obj_set_size(obj, 100, 100);
lv_obj_center(obj);
lv_led_set_color(obj, lv_color_hex(0xffff4411));
lv_led_set_brightness(obj, 0);
lv_obj_set_style_shadow_width(obj, 20, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_set_style_shadow_spread(obj, 16, LV_PART_MAIN | LV_STATE_DEFAULT);
lv_obj_add_flag(obj, LV_OBJ_FLAG_HIDDEN);
}
{
// tempArc
lv_obj_t *obj = lv_arc_create(parent_obj);
@ -151,7 +139,7 @@ void create_screen_main() {
void create_screen_chart() {
lv_obj_t *obj = lv_obj_create(0);
objects.second = obj;
objects.chartScr = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 240, 240);
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)1);
@ -271,7 +259,7 @@ void create_screen_chart() {
void create_screen_debug() {
lv_obj_t *obj = lv_obj_create(0);
objects.debug = obj;
objects.debugScr = obj;
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, 240, 240);
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)1);
@ -315,13 +303,3 @@ void create_screen_debug() {
}
}
void create_screens() {
lv_disp_t *dispp = lv_disp_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_GREEN), lv_palette_main(LV_PALETTE_RED), true, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
create_screen_main();
create_screen_chart();
create_screen_debug();
}

View File

@ -8,9 +8,9 @@ extern "C" {
#endif
typedef struct _objects_t {
lv_obj_t *main;
lv_obj_t *second;
lv_obj_t *debug;
lv_obj_t *mainScr;
lv_obj_t *chartScr;
lv_obj_t *debugScr;
lv_obj_t *temp_arc;
lv_obj_t *temp_txt;
lv_obj_t *hum_txt;
@ -26,7 +26,6 @@ typedef struct _objects_t {
lv_obj_t *heaterIcn;
lv_obj_t *bufferIcn;
lv_obj_t *wifiIcn;
lv_obj_t *alarmLED;
lv_obj_t *outTemp_txt;
lv_obj_t *time_txt;
lv_chart_cursor_t *chart_cursor;
@ -36,9 +35,10 @@ typedef struct _objects_t {
extern objects_t objects;
typedef enum ScreensEnum {
SCREEN_ID_MAIN = 1,
SCREEN_ID_CHART = 2,
SCREEN_ID_DEBUG = 3
SCREEN_ID_MAIN = 0,
SCREEN_ID_CHART = 1,
SCREEN_ID_DEBUG = 2,
SCREEN_ID_LEN
}ScreensEnum;
typedef enum ChartsEnum {
@ -51,6 +51,7 @@ typedef enum ChartsEnum {
void create_screen_main();
void create_screen_chart();
void create_screen_debug();
void create_screens();

View File

@ -15,20 +15,19 @@ TouchDrvCSTXXX touch;
Ticker fadeTicker;
bool isPressed = false,sleeping=false;
unsigned long lastTouch;
static int16_t currentScreen = -1;
static lv_obj_t *currentScreen = NULL;
static enum ChartsEnum currentChart = CHART_ID_TEMP;
/*
static lv_obj_t *getLvglObjectFromIndex(int32_t index) {
if (index == -1) {
return 0;
}
return ((lv_obj_t **)&objects)[index];
}
void loadScreen(ScreensEnum screenId) {
currentScreen = screenId - 1;
lv_obj_t *screen = getLvglObjectFromIndex(currentScreen);
lv_scr_load_anim(screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 0, false);
*/
void loadScreen(lv_obj_t* screen) {
lv_scr_load_anim(screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 0, true);
currentScreen = screen;
}
void fadeBrightness(uint16_t _newBrightness) {
@ -88,8 +87,8 @@ void loadChart(uint8_t chartId){
chart_autoscale();
}
ScreensEnum ui_getCurrentScreen(void){
return (ScreensEnum) (currentScreen + 1);
lv_obj_t* ui_getCurrentScreen(void){
return currentScreen;
}
ChartsEnum ui_getCurrentChart(void){
@ -97,8 +96,11 @@ ChartsEnum ui_getCurrentChart(void){
}
void ui_init() {
create_screens();
loadScreen(SCREEN_ID_MAIN);
lv_disp_t *dispp = lv_disp_get_default();
lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(LV_PALETTE_GREEN), lv_palette_main(LV_PALETTE_RED), true, LV_FONT_DEFAULT);
lv_disp_set_theme(dispp, theme);
create_screen_main();
loadScreen(objects.mainScr);
}
bool ui_isSleeping(void){
@ -163,9 +165,9 @@ void displayWake(){
delay(50);
touch.setPins(TouchRST, TouchInt);
Wire.begin(SDA,SCL); //初始化IIC设置引脚 SCL:22 SDA:21
Wire.begin(TouchSDA,TouchSCL); //初始化IIC设置引脚 SCL:22 SDA:21
Wire.setClock(200000); //设置频率400KHZ
if(touch.begin(Wire, TouchI2CAddr, SDA, SCL)){
if(touch.begin(Wire, TouchI2CAddr, TouchSDA, TouchSCL)){
Serial.println("Touch screen initialization done");
}
attachInterrupt(TouchInt, []() {

View File

@ -9,8 +9,8 @@
#define TouchInt 8
#define TouchRST 9
#define SCL 7
#define SDA 6
#define TouchSCL 7
#define TouchSDA 6
#define TouchI2CAddr 0x15
@ -45,11 +45,11 @@ bool ui_isSleeping(void);
void ui_tick();
void DisplayInit(void);
void log_print(lv_log_level_t level, const char * buf);
void loadScreen(ScreensEnum screenId);
void loadScreen(lv_obj_t *screen);
void loadChart(uint8_t chartId);
void ui_chart_autoscale(void);
float ui_getSetTemp(void);
ScreensEnum ui_getCurrentScreen(void);
lv_obj_t* ui_getCurrentScreen(void);
ChartsEnum ui_getCurrentChart(void);
void displaySleep();
void displayWake();