Dynamically load screens to save RAM.
Todo: make debug screen show things again.
This commit is contained in:
parent
98e13492ea
commit
d11f49a43d
82
Raumtermostat/Raumtermostat.code-workspace
Normal file
82
Raumtermostat/Raumtermostat.code-workspace
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -14,8 +14,8 @@ board = seeed_xiao_esp32c3
|
|||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board_build.partitions = min_spiffs.csv
|
board_build.partitions = min_spiffs.csv
|
||||||
upload_protocol = espota
|
;upload_protocol = espota
|
||||||
upload_port = TMP-EG-WoZi.fritz.box
|
;upload_port = TMP-EG-WoZi.fritz.box
|
||||||
lib_deps =
|
lib_deps =
|
||||||
moononournation/GFX Library for Arduino@^1.5.3
|
moononournation/GFX Library for Arduino@^1.5.3
|
||||||
lvgl/lvgl@^9.2.2
|
lvgl/lvgl@^9.2.2
|
||||||
|
|||||||
@ -123,7 +123,7 @@ void setup(void)
|
|||||||
measurementTick.attach(MEASINT_S,measure);
|
measurementTick.attach(MEASINT_S,measure);
|
||||||
mqtt.begin();
|
mqtt.begin();
|
||||||
getLocalTime(&glblData.bootTime);
|
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();
|
measure();
|
||||||
esp_reset_reason_t reason = esp_reset_reason();
|
esp_reset_reason_t reason = esp_reset_reason();
|
||||||
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW)) {
|
if ((reason != ESP_RST_DEEPSLEEP) && (reason != ESP_RST_SW)) {
|
||||||
@ -151,7 +151,7 @@ void loop()
|
|||||||
if(newHistory){
|
if(newHistory){
|
||||||
newHistory=false;
|
newHistory=false;
|
||||||
chart_autoscale();
|
chart_autoscale();
|
||||||
lv_chart_refresh(objects.chart);
|
|
||||||
}
|
}
|
||||||
if(millis() - minutesTick > 60000){
|
if(millis() - minutesTick > 60000){
|
||||||
minutesTick = millis();
|
minutesTick = millis();
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
#include <Arduino.h>
|
|
||||||
#include "actions.h"
|
#include "actions.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
bool arc_pressed = false;
|
bool arc_pressed = false;
|
||||||
bool animating = false;
|
bool animating = false;
|
||||||
@ -9,432 +8,467 @@ float curr_temp = 0.0;
|
|||||||
int32_t scale_max = 0, scale_min = 0, lastSelChartValue = 0;
|
int32_t scale_max = 0, scale_min = 0, lastSelChartValue = 0;
|
||||||
lv_point_t lastChartPt;
|
lv_point_t lastChartPt;
|
||||||
|
|
||||||
void update_sensorNstatus(float temp, float hum, float seaLevelPress, bool presAlarm){
|
void update_sensorNstatus(float temp, float hum, float seaLevelPress,
|
||||||
glblData.temp = temp;
|
bool presAlarm) {
|
||||||
glblData.hum = hum;
|
glblData.temp = temp;
|
||||||
glblData.seaLevelPress = seaLevelPress;
|
glblData.hum = hum;
|
||||||
glblData.presAlarm = presAlarm;
|
glblData.seaLevelPress = seaLevelPress;
|
||||||
update_status();
|
glblData.presAlarm = presAlarm;
|
||||||
|
update_status();
|
||||||
}
|
}
|
||||||
void update_clockdots(void){
|
void update_clockdots(void) {
|
||||||
static bool dotState = false;
|
if (ui_getCurrentScreen() != objects.mainScr) {
|
||||||
dotState = !dotState;
|
return;
|
||||||
char* time = lv_label_get_text(objects.time_txt);
|
}
|
||||||
if(dotState){
|
static bool dotState = false;
|
||||||
time[3] = ':';
|
dotState = !dotState;
|
||||||
lv_label_set_text(objects.time_txt, time);
|
char *time = lv_label_get_text(objects.time_txt);
|
||||||
}else{
|
if (dotState) {
|
||||||
time[3] = ' ';
|
time[3] = ':';
|
||||||
lv_label_set_text(objects.time_txt, time);
|
lv_label_set_text(objects.time_txt, time);
|
||||||
}
|
} else {
|
||||||
|
time[3] = ' ';
|
||||||
|
lv_label_set_text(objects.time_txt, time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void alarm_ani_cb(void * var, int32_t v)
|
void ui_settemp(float tmp) {
|
||||||
{
|
if (ui_getCurrentScreen() != objects.mainScr) {
|
||||||
if(v > -1 && v < 256){
|
return;
|
||||||
lv_led_set_brightness(objects.alarmLED, v);
|
}
|
||||||
setBacklight((v<<4) | 0x00FF,100);
|
lv_arc_set_value(objects.temp_arc, (int32_t)(tmp));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void alarm_ani_end_cb(lv_anim_t *var)
|
void update_status(void) {
|
||||||
{
|
static unsigned long fullOnTime = millis();
|
||||||
lv_obj_add_flag(objects.alarmLED, LV_OBJ_FLAG_HIDDEN);
|
switch (glblData.override) {
|
||||||
setBacklight(BL_BRIGHTNESS,250);
|
case OVR_NONE:
|
||||||
lv_led_set_brightness(objects.alarmLED, 0);
|
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);
|
||||||
|
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(objects.time_txt, buffer);
|
||||||
|
if (!arc_pressed && !animating) {
|
||||||
|
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.temp);
|
||||||
|
} else {
|
||||||
|
glblData.settemp = lv_arc_get_value(objects.temp_arc);
|
||||||
|
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.settemp);
|
||||||
|
}
|
||||||
|
if (glblData.enBuff) {
|
||||||
|
lv_obj_remove_flag(objects.bufferIcn, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
} else {
|
||||||
|
lv_obj_add_flag(objects.bufferIcn, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
|
switch (glblData.override) {
|
||||||
|
case OVR_NONE:
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
case OVR_ALWAYSOFF:
|
||||||
|
lv_obj_set_style_text_color(objects.bufferIcn, lv_color_hex(0xFFAA0000),
|
||||||
|
LV_STATE_DEFAULT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (glblData.heating) {
|
||||||
|
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); //relay off
|
||||||
|
lv_obj_add_flag(objects.heaterIcn, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_settemp(float tmp){
|
void update_wifi_strength(wifistrength_t strength, wifimode_t mode) {
|
||||||
lv_arc_set_value(objects.temp_arc, (int32_t) (tmp));
|
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);
|
||||||
|
} else {
|
||||||
|
Serial.println("WiFi mode STA, updating icon");
|
||||||
|
lv_obj_set_style_text_color(objects.wifiIcn, lv_color_hex(0xf0f0f0),
|
||||||
|
LV_STATE_DEFAULT);
|
||||||
|
}
|
||||||
|
switch (strength) {
|
||||||
|
case WIFISTRENGTH_HIGH:
|
||||||
|
lv_label_set_text(objects.wifiIcn, ICON_WIFI_HIGH);
|
||||||
|
break;
|
||||||
|
case WIFISTRENGTH_MED:
|
||||||
|
lv_label_set_text(objects.wifiIcn, ICON_WIFI_MED);
|
||||||
|
break;
|
||||||
|
case WIFISTRENGTH_LOW:
|
||||||
|
lv_label_set_text(objects.wifiIcn, ICON_WIFI_LOW);
|
||||||
|
break;
|
||||||
|
case WIFISTRENGTH_OFF:
|
||||||
|
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_label_set_text(objects.wifiIcn, ICON_WIFI_OFF);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_status(void){
|
void chartDrawingCB(lv_event_t *e) {
|
||||||
tm timeinfo;
|
lv_event_code_t code = lv_event_get_code(e);
|
||||||
getLocalTime(&timeinfo);
|
lv_obj_t *chart = lv_event_get_target_obj(e);
|
||||||
char buffer[15];
|
|
||||||
strftime(buffer, sizeof(buffer), "%H : %M", &timeinfo);
|
if (code == LV_EVENT_DRAW_POST_END) {
|
||||||
static unsigned long fullOnTime = millis();
|
ChartsEnum currChart = ui_getCurrentChart();
|
||||||
lv_label_set_text_fmt(objects.press_txt,"%4.2f hPa",glblData.seaLevelPress);
|
int32_t id = lv_chart_get_pressed_point(objects.chart);
|
||||||
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_chart_series_t *ser = lv_chart_get_series_next(chart, NULL);
|
||||||
lv_label_set_text(objects.time_txt,buffer);
|
// while(ser) {
|
||||||
if(!arc_pressed && !animating){
|
lv_area_t chart_obj_coords;
|
||||||
lv_label_set_text_fmt(objects.temp_txt,"%2.1f °C",glblData.temp);
|
lv_obj_get_coords(chart, &chart_obj_coords);
|
||||||
}else{
|
lv_layer_t *layer = lv_event_get_layer(e);
|
||||||
glblData.settemp = lv_arc_get_value(objects.temp_arc);
|
if (currChart == CHART_ID_TEMP) {
|
||||||
lv_label_set_text_fmt(objects.temp_txt,"%2.1f °C",glblData.settemp);
|
lv_draw_line_dsc_t draw_line_dsc;
|
||||||
|
lv_draw_line_dsc_init(&draw_line_dsc);
|
||||||
|
draw_line_dsc.color = lv_color_hex(0xaa0000);
|
||||||
|
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.p2.x = chart_obj_coords.x2 - 5;
|
||||||
|
draw_line_dsc.p2.y = draw_line_dsc.p1.y;
|
||||||
|
lv_draw_line(layer, &draw_line_dsc);
|
||||||
}
|
}
|
||||||
if(glblData.enBuff){
|
|
||||||
lv_obj_remove_flag(objects.bufferIcn, LV_OBJ_FLAG_HIDDEN);
|
if (id != LV_CHART_POINT_NONE) {
|
||||||
}else{
|
lv_chart_get_point_pos_by_id(chart, ser, id, &lastChartPt);
|
||||||
lv_obj_add_flag(objects.bufferIcn, LV_OBJ_FLAG_HIDDEN);
|
int32_t *y_array = lv_chart_get_y_array(objects.chart, ser);
|
||||||
|
lastSelChartValue = y_array[id];
|
||||||
|
} else if (lastChartPt.x == -1) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
switch(glblData.override){
|
/*Draw a rectangle above the clicked point*/
|
||||||
case OVR_NONE:
|
|
||||||
lv_obj_set_style_text_color(objects.bufferIcn,lv_color_hex(0xFFfafafa),LV_STATE_DEFAULT);
|
lv_draw_rect_dsc_t draw_rect_dsc;
|
||||||
if(glblData.temp < glblData.settemp-TMP_HYST){
|
lv_draw_rect_dsc_init(&draw_rect_dsc);
|
||||||
glblData.heating = true;
|
draw_rect_dsc.bg_color = lv_color_black();
|
||||||
}
|
draw_rect_dsc.bg_opa = LV_OPA_50;
|
||||||
else if(glblData.temp > glblData.settemp+TMP_HYST){
|
draw_rect_dsc.radius = 3;
|
||||||
glblData.heating = false;
|
|
||||||
}
|
lv_area_t rect_area;
|
||||||
break;
|
// rect_area.x1 = lastChartPt.x - 35;
|
||||||
case OVR_ALWAYSON:
|
rect_area.x1 = chart_obj_coords.x1 + lastChartPt.x - 35;
|
||||||
lv_obj_set_style_text_color(objects.bufferIcn,lv_color_hex(0xFF00AA00),LV_STATE_DEFAULT);
|
if (rect_area.x1 < chart_obj_coords.x1) {
|
||||||
if(glblData.temp < glblData.settemp+3.0){ //allow for 3degC overheating
|
rect_area.x1 = chart_obj_coords.x1;
|
||||||
glblData.heating = true;
|
} else if (rect_area.x1 + 70 > chart_obj_coords.x2) {
|
||||||
}
|
rect_area.x1 = chart_obj_coords.x2 - 70;
|
||||||
else{
|
|
||||||
glblData.heating = false;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if(glblData.heating){
|
rect_area.x2 = rect_area.x1 + 70;
|
||||||
if(ledcRead(PWM_REL) == 0){
|
rect_area.y1 =
|
||||||
ledcWrite(PWM_REL, 0xff); //turn on relay
|
chart_obj_coords.y1 +
|
||||||
fullOnTime = millis();
|
5; // lastChartPt.y - 30; -->always draw it at the top of the chart
|
||||||
lv_obj_set_style_text_color(objects.heaterIcn,lv_color_hex(0xFFAA0000),LV_STATE_DEFAULT);
|
rect_area.y2 = chart_obj_coords.y1 + 25; // lastChartPt.y - 10;
|
||||||
}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
|
lv_draw_rect(layer, &draw_rect_dsc, &rect_area);
|
||||||
ledcWrite(PWM_REL, 0x7f); //lower relay to 50%
|
|
||||||
lv_obj_set_style_text_color(objects.heaterIcn,lv_color_hex(0xFF00AA00),LV_STATE_DEFAULT);
|
/*Draw the value as label to the center of the rectangle*/
|
||||||
}
|
char buf[16];
|
||||||
lv_obj_remove_flag(objects.heaterIcn, LV_OBJ_FLAG_HIDDEN);
|
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY "nan");
|
||||||
}else{
|
switch (ui_getCurrentChart()) {
|
||||||
ledcWrite(PWM_REL, 0); //turn off relay
|
case CHART_ID_TEMP:
|
||||||
lv_obj_add_flag(objects.heaterIcn, LV_OBJ_FLAG_HIDDEN);
|
if (lastSelChartValue > INT32_MIN)
|
||||||
|
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);
|
||||||
|
break;
|
||||||
|
case CHART_ID_PRESS:
|
||||||
|
if (lastSelChartValue > INT32_MIN)
|
||||||
|
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY "%d hPa",
|
||||||
|
lastSelChartValue);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(glblData.presAlarm == true){
|
lv_draw_label_dsc_t draw_label_dsc;
|
||||||
lv_obj_remove_flag(objects.alarmLED, LV_OBJ_FLAG_HIDDEN);
|
lv_draw_label_dsc_init(&draw_label_dsc);
|
||||||
lv_anim_t alarmAni;
|
draw_label_dsc.color = lv_color_white();
|
||||||
lv_anim_init(&alarmAni);
|
draw_label_dsc.text = buf;
|
||||||
lv_anim_set_values(&alarmAni, 0, 255);
|
draw_label_dsc.text_local = 1;
|
||||||
lv_anim_set_duration(&alarmAni, 600);
|
draw_label_dsc.align = LV_TEXT_ALIGN_CENTER;
|
||||||
lv_anim_set_playback_delay(&alarmAni, 0);
|
lv_area_t label_area = rect_area;
|
||||||
lv_anim_set_playback_duration(&alarmAni, 600);
|
lv_area_set_height(&label_area,
|
||||||
lv_anim_set_repeat_delay(&alarmAni, 100);
|
lv_font_get_line_height(draw_label_dsc.font));
|
||||||
lv_anim_set_repeat_count(&alarmAni,7);
|
lv_area_align(&rect_area, &label_area, LV_ALIGN_CENTER, 0, 0);
|
||||||
lv_anim_set_exec_cb(&alarmAni, alarm_ani_cb);
|
lv_draw_label(layer, &draw_label_dsc, &label_area);
|
||||||
lv_anim_set_path_cb(&alarmAni, lv_anim_path_ease_in_out);
|
|
||||||
lv_anim_set_completed_cb(&alarmAni,alarm_ani_end_cb);
|
// ser = lv_chart_get_series_next(chart, ser);
|
||||||
lv_anim_start(&alarmAni);
|
//}
|
||||||
ui_exitSleep();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_wifi_strength(wifistrength_t strength, wifimode_t mode){
|
void chart_autoscale(void) {
|
||||||
if(mode != WIFIMODE_STA){
|
if (ui_getCurrentScreen() != objects.chartScr) {
|
||||||
Serial.println("WiFi mode not STA, not updating icon");
|
return;
|
||||||
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xFF0000EE),LV_STATE_DEFAULT);
|
}
|
||||||
}else{
|
int32_t *numbers = lv_chart_get_y_array(objects.chart, objects.chart_series);
|
||||||
Serial.println("WiFi mode STA, updating icon");
|
int32_t max = INT32_MIN, min = INT32_MAX;
|
||||||
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xf0f0f0),LV_STATE_DEFAULT);
|
uint32_t delta, factor = 1, gridFactor = 1;
|
||||||
}
|
for (uint16_t i = 0; i < HISTLEN; i++) {
|
||||||
switch(strength){
|
if (numbers[i] > max)
|
||||||
case WIFISTRENGTH_HIGH:
|
max = numbers[i];
|
||||||
lv_label_set_text(objects.wifiIcn,ICON_WIFI_HIGH);
|
if (numbers[i] < min)
|
||||||
break;
|
min = numbers[i];
|
||||||
case WIFISTRENGTH_MED:
|
}
|
||||||
lv_label_set_text(objects.wifiIcn,ICON_WIFI_MED);
|
delta = max - min;
|
||||||
break;
|
if (ui_getCurrentChart() == CHART_ID_TEMP) {
|
||||||
case WIFISTRENGTH_LOW:
|
min = min / 10;
|
||||||
lv_label_set_text(objects.wifiIcn,ICON_WIFI_LOW);
|
max = (max + 9) / 10; // round up
|
||||||
break;
|
delta = (delta + 9) / 10; // round up
|
||||||
case WIFISTRENGTH_OFF:
|
factor = 10;
|
||||||
lv_label_set_text(objects.wifiIcn,ICON_WIFI_OFF);
|
}
|
||||||
break;
|
while (delta > 51) {
|
||||||
case WIFISTRENGTH_ERROR:
|
delta = (delta + 9) / 10;
|
||||||
lv_obj_set_style_text_color(objects.wifiIcn,lv_color_hex(0xFF0000),LV_STATE_DEFAULT);
|
gridFactor = gridFactor * 10;
|
||||||
lv_label_set_text(objects.wifiIcn,ICON_WIFI_OFF);
|
}
|
||||||
break;
|
if (delta < 6) { // major tick every 1.0
|
||||||
}
|
scale_min = min;
|
||||||
|
scale_max = min + 5 * gridFactor;
|
||||||
|
// lv_scale_set_total_tick_count(objects.y_scale, 26);
|
||||||
|
// lv_scale_set_major_tick_every(objects.y_scale, 5);
|
||||||
|
} else if (delta < 11) { // major tick every 2.0
|
||||||
|
min /= 2 * gridFactor;
|
||||||
|
min *= 2 * gridFactor;
|
||||||
|
scale_min = min;
|
||||||
|
scale_max = min + 10 * gridFactor;
|
||||||
|
} else if (delta < 26) { // major tick every 5.0
|
||||||
|
min /= 5 * gridFactor;
|
||||||
|
min *= 5 * gridFactor;
|
||||||
|
scale_min = min;
|
||||||
|
scale_max = min + 25 * gridFactor;
|
||||||
|
} else if (delta < 51) { // major tick every 10.0
|
||||||
|
min /= 10 * gridFactor;
|
||||||
|
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
|
||||||
|
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_scale_set_range(objects.y_scale, scale_min, scale_max);
|
||||||
|
lv_chart_refresh(objects.chart);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chartDrawingCB(lv_event_t * e){
|
void zoomAniWrapper(void *var, int32_t val) {
|
||||||
lv_event_code_t code = lv_event_get_code(e);
|
lv_obj_t *obj = (lv_obj_t *)var;
|
||||||
lv_obj_t * chart = lv_event_get_target_obj(e);
|
int32_t x = -(lv_obj_get_width(obj) * val) / (6 * 255);
|
||||||
|
int32_t y = -(lv_obj_get_height(obj) * val) / (6 * 255);
|
||||||
if(code == LV_EVENT_DRAW_POST_END) {
|
lv_obj_set_pos(obj, x, y);
|
||||||
ChartsEnum currChart = ui_getCurrentChart();
|
lv_obj_set_style_transform_scale(obj, 255 + val / 4, 0);
|
||||||
int32_t id = lv_chart_get_pressed_point(objects.chart);
|
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_chart_series_t * ser = lv_chart_get_series_next(chart, NULL);
|
lv_obj_set_style_text_opa(objects.outTemp_txt, 255 - val, 0);
|
||||||
//while(ser) {
|
lv_obj_set_style_text_opa(objects.time_txt, 255 - val, 0);
|
||||||
lv_area_t chart_obj_coords;
|
}
|
||||||
lv_obj_get_coords(chart, &chart_obj_coords);
|
void zomFinishedCB(lv_anim_t *var) {
|
||||||
lv_layer_t * layer = lv_event_get_layer(e);
|
if (arc_pressed) {
|
||||||
if(currChart == CHART_ID_TEMP){
|
arc_pressed = false;
|
||||||
lv_draw_line_dsc_t draw_line_dsc;
|
animating = false;
|
||||||
lv_draw_line_dsc_init(&draw_line_dsc);
|
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.temp);
|
||||||
draw_line_dsc.color = lv_color_hex(0xaa0000);
|
} else if (ui_getCurrentScreen() == objects.mainScr) {
|
||||||
draw_line_dsc.dash_gap = 1;
|
// only set arc pressed true if main screen is
|
||||||
draw_line_dsc.dash_width = 2;
|
// still active, otherwise we'll lock screen
|
||||||
draw_line_dsc.p1.x = chart_obj_coords.x1+5;
|
// switching
|
||||||
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;
|
arc_pressed = true;
|
||||||
draw_line_dsc.p2.x = chart_obj_coords.x2-5;
|
animating = false;
|
||||||
draw_line_dsc.p2.y = draw_line_dsc.p1.y;
|
lv_label_set_text_fmt(objects.temp_txt, "%2.1f °C", glblData.settemp);
|
||||||
lv_draw_line(layer,&draw_line_dsc);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(id != LV_CHART_POINT_NONE){
|
|
||||||
lv_chart_get_point_pos_by_id(chart, ser, id, &lastChartPt);
|
|
||||||
int32_t * y_array = lv_chart_get_y_array(objects.chart, ser);
|
|
||||||
lastSelChartValue = y_array[id];
|
|
||||||
}else if(lastChartPt.x == -1){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
/*Draw a rectangle above the clicked point*/
|
|
||||||
|
|
||||||
lv_draw_rect_dsc_t draw_rect_dsc;
|
|
||||||
lv_draw_rect_dsc_init(&draw_rect_dsc);
|
|
||||||
draw_rect_dsc.bg_color = lv_color_black();
|
|
||||||
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;
|
|
||||||
if(rect_area.x1 < chart_obj_coords.x1){
|
|
||||||
rect_area.x1 = chart_obj_coords.x1;
|
|
||||||
}else if(rect_area.x1 + 70 > chart_obj_coords.x2){
|
|
||||||
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.y2 = chart_obj_coords.y1 + 25; //lastChartPt.y - 10;
|
|
||||||
lv_draw_rect(layer, &draw_rect_dsc, &rect_area);
|
|
||||||
|
|
||||||
/*Draw the value as label to the center of the rectangle*/
|
|
||||||
char buf[16];
|
|
||||||
lv_snprintf(buf, sizeof(buf), LV_SYMBOL_DUMMY"nan");
|
|
||||||
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);
|
|
||||||
break;
|
|
||||||
case CHART_ID_HUM:
|
|
||||||
if(lastSelChartValue > INT32_MIN)
|
|
||||||
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);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
lv_draw_label_dsc_t draw_label_dsc;
|
|
||||||
lv_draw_label_dsc_init(&draw_label_dsc);
|
|
||||||
draw_label_dsc.color = lv_color_white();
|
|
||||||
draw_label_dsc.text = buf;
|
|
||||||
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_align(&rect_area, &label_area, LV_ALIGN_CENTER, 0, 0);
|
|
||||||
lv_draw_label(layer, &draw_label_dsc, &label_area);
|
|
||||||
|
|
||||||
// ser = lv_chart_get_series_next(chart, ser);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void chart_autoscale(void){
|
void action_zoom_set_temp(lv_event_t *e) {
|
||||||
int32_t* numbers = lv_chart_get_y_array(objects.chart,objects.chart_series);
|
if ((int)lv_event_get_user_data(e) == 1) {
|
||||||
int32_t max=INT32_MIN,min=INT32_MAX;
|
if (arc_pressed == false && animating == false) {
|
||||||
uint32_t delta,factor = 1,gridFactor=1;
|
animating = true;
|
||||||
for(uint16_t i=0; i<HISTLEN; i++){
|
lv_anim_t a;
|
||||||
if(numbers[i] > max)
|
lv_anim_init(&a);
|
||||||
max = numbers[i];
|
lv_anim_set_var(&a, objects.temp_txt);
|
||||||
if(numbers[i] < min)
|
lv_anim_set_values(&a, 0, 255);
|
||||||
min = numbers[i];
|
lv_anim_set_duration(&a, 200);
|
||||||
|
lv_anim_set_exec_cb(&a, zoomAniWrapper);
|
||||||
|
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||||
|
lv_anim_set_completed_cb(&a, zomFinishedCB);
|
||||||
|
lv_anim_start(&a);
|
||||||
}
|
}
|
||||||
delta = max-min;
|
} else {
|
||||||
if(ui_getCurrentChart() == CHART_ID_TEMP){
|
if (arc_pressed == true && animating == false) {
|
||||||
min = min/10;
|
animating = true;
|
||||||
max = (max+9)/10; //round up
|
lv_anim_t a;
|
||||||
delta = (delta+9)/10; //round up
|
lv_anim_init(&a);
|
||||||
factor = 10;
|
lv_anim_set_var(&a, objects.temp_txt);
|
||||||
|
lv_anim_set_values(&a, 255, 0);
|
||||||
|
lv_anim_set_delay(&a, 3000);
|
||||||
|
lv_anim_set_duration(&a, 200);
|
||||||
|
lv_anim_set_exec_cb(&a, zoomAniWrapper);
|
||||||
|
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
||||||
|
lv_anim_set_completed_cb(&a, zomFinishedCB);
|
||||||
|
lv_anim_start(&a);
|
||||||
}
|
}
|
||||||
while(delta > 51){
|
}
|
||||||
delta = (delta+9)/10;
|
// lv_label_set_text_fmt(objects.temp_txt,"%2.1f
|
||||||
gridFactor = gridFactor * 10;
|
// °C",lv_arc_get_value(objects.temp_arc)/2.0);
|
||||||
}
|
update_status();
|
||||||
if(delta < 6){ //major tick every 1.0
|
|
||||||
scale_min = min;
|
|
||||||
scale_max = min+5*gridFactor;
|
|
||||||
//lv_scale_set_total_tick_count(objects.y_scale, 26);
|
|
||||||
//lv_scale_set_major_tick_every(objects.y_scale, 5);
|
|
||||||
}else if(delta < 11){ //major tick every 2.0
|
|
||||||
min /= 2*gridFactor;
|
|
||||||
min *= 2*gridFactor;
|
|
||||||
scale_min = min;
|
|
||||||
scale_max = min+10*gridFactor;
|
|
||||||
}else if(delta < 26){ //major tick every 5.0
|
|
||||||
min /= 5*gridFactor;
|
|
||||||
min *= 5*gridFactor;
|
|
||||||
scale_min = min;
|
|
||||||
scale_max = min+25*gridFactor;
|
|
||||||
}else if(delta < 51){ //major tick every 10.0
|
|
||||||
min /= 10*gridFactor;
|
|
||||||
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
|
|
||||||
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_scale_set_range(objects.y_scale, scale_min, scale_max);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void zoomAniWrapper(void *var, int32_t val){
|
static void anim_height_cb(void *var, int32_t v) {
|
||||||
lv_obj_t* obj = (lv_obj_t*) var;
|
lv_obj_t *obj = (lv_obj_t *)var;
|
||||||
int32_t x = -(lv_obj_get_width(obj)*val)/(6*255);
|
lv_obj_set_height(obj, v);
|
||||||
int32_t y = -(lv_obj_get_height(obj)*val)/(6*255);
|
|
||||||
lv_obj_set_pos(obj, x, y);
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
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
|
|
||||||
arc_pressed = true;
|
|
||||||
animating = false;
|
|
||||||
lv_label_set_text_fmt(objects.temp_txt,"%2.1f °C",glblData.settemp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void action_zoom_set_temp(lv_event_t * e){
|
void action_switch_screens(lv_event_t *e) {
|
||||||
if((int)lv_event_get_user_data(e) == 1){
|
lv_dir_t gestDir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
||||||
if(arc_pressed == false && animating == false){
|
lastChartPt.x = -1; // clear labels on chart change
|
||||||
animating = true;
|
int32_t chartheight = lv_obj_get_height(objects.chart);
|
||||||
lv_anim_t a;
|
switch (gestDir) {
|
||||||
lv_anim_init(&a);
|
case LV_DIR_LEFT:
|
||||||
lv_anim_set_var(&a, objects.temp_txt);
|
case LV_DIR_RIGHT:
|
||||||
lv_anim_set_values(&a, 0, 255);
|
break;
|
||||||
lv_anim_set_duration(&a, 200);
|
case LV_DIR_BOTTOM:
|
||||||
lv_anim_set_exec_cb(&a, zoomAniWrapper);
|
lv_anim_t a;
|
||||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
lv_anim_init(&a);
|
||||||
lv_anim_set_completed_cb(&a,zomFinishedCB);
|
lv_anim_set_exec_cb(&a, anim_height_cb);
|
||||||
lv_anim_start(&a);
|
lv_anim_set_var(&a, objects.chart);
|
||||||
}
|
lv_anim_set_values(&a, chartheight, 0);
|
||||||
|
lv_anim_set_duration(&a, 200);
|
||||||
|
lv_anim_set_path_cb(&a, lv_anim_path_bounce);
|
||||||
|
lv_anim_start(&a);
|
||||||
|
lv_anim_set_values(&a, 0, chartheight);
|
||||||
|
lv_anim_set_delay(&a, 200);
|
||||||
|
lv_anim_start(&a);
|
||||||
|
if (ui_getCurrentChart() == CHART_ID_LEN - 1) {
|
||||||
|
loadChart(1);
|
||||||
|
} else {
|
||||||
|
loadChart(ui_getCurrentChart() + 1);
|
||||||
}
|
}
|
||||||
else{
|
lv_indev_wait_release(lv_indev_active());
|
||||||
if(arc_pressed == true && animating == false){
|
break;
|
||||||
animating = true;
|
case LV_DIR_TOP:
|
||||||
lv_anim_t a;
|
break;
|
||||||
lv_anim_init(&a);
|
}
|
||||||
lv_anim_set_var(&a, objects.temp_txt);
|
|
||||||
lv_anim_set_values(&a, 255, 0);
|
|
||||||
lv_anim_set_delay(&a,3000);
|
|
||||||
lv_anim_set_duration(&a, 200);
|
|
||||||
lv_anim_set_exec_cb(&a, zoomAniWrapper);
|
|
||||||
lv_anim_set_path_cb(&a, lv_anim_path_ease_in_out);
|
|
||||||
lv_anim_set_completed_cb(&a,zomFinishedCB);
|
|
||||||
lv_anim_start(&a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//lv_label_set_text_fmt(objects.temp_txt,"%2.1f °C",lv_arc_get_value(objects.temp_arc)/2.0);
|
|
||||||
update_status();
|
|
||||||
}
|
}
|
||||||
|
void showChartScreen(lv_event_t *e) {
|
||||||
|
if (ui_getCurrentScreen() != objects.chartScr) {
|
||||||
static void anim_height_cb(void * var, int32_t v)
|
create_screen_chart();
|
||||||
{
|
|
||||||
lv_obj_t* obj = (lv_obj_t*) var;
|
|
||||||
lv_obj_set_height(obj, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
void action_switch_screens(lv_event_t * e){
|
|
||||||
lv_dir_t gestDir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
|
||||||
lastChartPt.x = -1; //clear labels on chart change
|
|
||||||
int32_t chartheight = lv_obj_get_height(objects.chart);
|
|
||||||
switch (gestDir){
|
|
||||||
case LV_DIR_LEFT:
|
|
||||||
case LV_DIR_RIGHT:
|
|
||||||
break;
|
|
||||||
case LV_DIR_BOTTOM:
|
|
||||||
lv_anim_t a;
|
|
||||||
lv_anim_init(&a);
|
|
||||||
lv_anim_set_exec_cb(&a, anim_height_cb);
|
|
||||||
lv_anim_set_var(&a, objects.chart);
|
|
||||||
lv_anim_set_values(&a, chartheight, 0);
|
|
||||||
lv_anim_set_duration(&a, 200);
|
|
||||||
lv_anim_set_path_cb(&a, lv_anim_path_bounce);
|
|
||||||
lv_anim_start(&a);
|
|
||||||
lv_anim_set_values(&a, 0, chartheight);
|
|
||||||
lv_anim_set_delay(&a, 200);
|
|
||||||
lv_anim_start(&a);
|
|
||||||
if(ui_getCurrentChart() == CHART_ID_LEN-1){
|
|
||||||
loadChart(1);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
loadChart(ui_getCurrentChart()+1);
|
|
||||||
}
|
|
||||||
lv_indev_wait_release(lv_indev_active());
|
|
||||||
break;
|
|
||||||
case LV_DIR_TOP:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void showChartScreen(lv_event_t * e){
|
|
||||||
loadChart(0);
|
loadChart(0);
|
||||||
loadScreen(SCREEN_ID_CHART);
|
}
|
||||||
|
loadScreen(objects.chartScr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showDebugScreen(lv_event_t * e){
|
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){
|
void rebootESP(lv_event_t *e) { ESP.restart(); }
|
||||||
ESP.restart();
|
|
||||||
|
void showMainScreen(lv_event_t *e) {
|
||||||
|
if (ui_getCurrentScreen() != objects.mainScr) {
|
||||||
|
create_screen_main();
|
||||||
|
update_status();
|
||||||
|
ui_settemp(glblData.settemp);
|
||||||
|
}
|
||||||
|
loadScreen(objects.mainScr);
|
||||||
|
Serial.println("Main screen loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void showMainScreen(lv_event_t * e){
|
void action_show_cursors_cb(lv_event_t *e) {
|
||||||
loadScreen(SCREEN_ID_MAIN);
|
static int32_t last_id = -1;
|
||||||
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(e);
|
||||||
|
|
||||||
|
last_id = lv_chart_get_pressed_point(obj);
|
||||||
|
if (last_id != LV_CHART_POINT_NONE) {
|
||||||
|
lv_chart_set_cursor_point(obj, objects.chart_cursor, NULL, last_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void action_show_cursors_cb(lv_event_t * e){
|
void draw_event_cb(lv_event_t *e) {
|
||||||
static int32_t last_id = -1;
|
lv_obj_t *obj = (lv_obj_t *)lv_event_get_target(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 =
|
||||||
last_id = lv_chart_get_pressed_point(obj);
|
(lv_draw_dsc_base_t *)lv_draw_task_get_draw_dsc(draw_task);
|
||||||
if(last_id != LV_CHART_POINT_NONE) {
|
lv_draw_label_dsc_t *label_draw_dsc = lv_draw_task_get_label_dsc(draw_task);
|
||||||
lv_chart_set_cursor_point(obj, objects.chart_cursor, NULL, last_id);
|
if (base_dsc->part == LV_PART_INDICATOR) {
|
||||||
}
|
if (label_draw_dsc) {
|
||||||
}
|
uint8_t major_tick = lv_scale_get_major_tick_every(obj);
|
||||||
|
if (base_dsc->id1 == 0) {
|
||||||
|
label_draw_dsc->color = lv_color_black();
|
||||||
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_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) {
|
|
||||||
uint8_t major_tick = lv_scale_get_major_tick_every(obj);
|
|
||||||
if(base_dsc->id1 == 0){
|
|
||||||
label_draw_dsc->color = lv_color_black();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -17,24 +17,12 @@ lv_obj_t *tick_value_change_obj;
|
|||||||
|
|
||||||
void create_screen_main() {
|
void create_screen_main() {
|
||||||
lv_obj_t *obj = lv_obj_create(0);
|
lv_obj_t *obj = lv_obj_create(0);
|
||||||
objects.main = obj;
|
objects.mainScr = obj;
|
||||||
lv_obj_set_pos(obj, 0, 0);
|
lv_obj_set_pos(obj, 0, 0);
|
||||||
lv_obj_set_size(obj, 240, 240);
|
lv_obj_set_size(obj, 240, 240);
|
||||||
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)0);
|
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)0);
|
||||||
{
|
{
|
||||||
lv_obj_t *parent_obj = obj;
|
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
|
// tempArc
|
||||||
lv_obj_t *obj = lv_arc_create(parent_obj);
|
lv_obj_t *obj = lv_arc_create(parent_obj);
|
||||||
@ -151,7 +139,7 @@ void create_screen_main() {
|
|||||||
|
|
||||||
void create_screen_chart() {
|
void create_screen_chart() {
|
||||||
lv_obj_t *obj = lv_obj_create(0);
|
lv_obj_t *obj = lv_obj_create(0);
|
||||||
objects.second = obj;
|
objects.chartScr = obj;
|
||||||
lv_obj_set_pos(obj, 0, 0);
|
lv_obj_set_pos(obj, 0, 0);
|
||||||
lv_obj_set_size(obj, 240, 240);
|
lv_obj_set_size(obj, 240, 240);
|
||||||
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)1);
|
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() {
|
void create_screen_debug() {
|
||||||
lv_obj_t *obj = lv_obj_create(0);
|
lv_obj_t *obj = lv_obj_create(0);
|
||||||
objects.debug = obj;
|
objects.debugScr = obj;
|
||||||
lv_obj_set_pos(obj, 0, 0);
|
lv_obj_set_pos(obj, 0, 0);
|
||||||
lv_obj_set_size(obj, 240, 240);
|
lv_obj_set_size(obj, 240, 240);
|
||||||
lv_obj_add_event_cb(obj, action_switch_screens, LV_EVENT_GESTURE, (void *)1);
|
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();
|
|
||||||
}
|
|
||||||
|
|||||||
@ -8,9 +8,9 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct _objects_t {
|
typedef struct _objects_t {
|
||||||
lv_obj_t *main;
|
lv_obj_t *mainScr;
|
||||||
lv_obj_t *second;
|
lv_obj_t *chartScr;
|
||||||
lv_obj_t *debug;
|
lv_obj_t *debugScr;
|
||||||
lv_obj_t *temp_arc;
|
lv_obj_t *temp_arc;
|
||||||
lv_obj_t *temp_txt;
|
lv_obj_t *temp_txt;
|
||||||
lv_obj_t *hum_txt;
|
lv_obj_t *hum_txt;
|
||||||
@ -26,7 +26,6 @@ typedef struct _objects_t {
|
|||||||
lv_obj_t *heaterIcn;
|
lv_obj_t *heaterIcn;
|
||||||
lv_obj_t *bufferIcn;
|
lv_obj_t *bufferIcn;
|
||||||
lv_obj_t *wifiIcn;
|
lv_obj_t *wifiIcn;
|
||||||
lv_obj_t *alarmLED;
|
|
||||||
lv_obj_t *outTemp_txt;
|
lv_obj_t *outTemp_txt;
|
||||||
lv_obj_t *time_txt;
|
lv_obj_t *time_txt;
|
||||||
lv_chart_cursor_t *chart_cursor;
|
lv_chart_cursor_t *chart_cursor;
|
||||||
@ -36,9 +35,10 @@ typedef struct _objects_t {
|
|||||||
extern objects_t objects;
|
extern objects_t objects;
|
||||||
|
|
||||||
typedef enum ScreensEnum {
|
typedef enum ScreensEnum {
|
||||||
SCREEN_ID_MAIN = 1,
|
SCREEN_ID_MAIN = 0,
|
||||||
SCREEN_ID_CHART = 2,
|
SCREEN_ID_CHART = 1,
|
||||||
SCREEN_ID_DEBUG = 3
|
SCREEN_ID_DEBUG = 2,
|
||||||
|
SCREEN_ID_LEN
|
||||||
}ScreensEnum;
|
}ScreensEnum;
|
||||||
|
|
||||||
typedef enum ChartsEnum {
|
typedef enum ChartsEnum {
|
||||||
@ -51,6 +51,7 @@ typedef enum ChartsEnum {
|
|||||||
|
|
||||||
void create_screen_main();
|
void create_screen_main();
|
||||||
void create_screen_chart();
|
void create_screen_chart();
|
||||||
|
void create_screen_debug();
|
||||||
void create_screens();
|
void create_screens();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,20 +15,19 @@ TouchDrvCSTXXX touch;
|
|||||||
Ticker fadeTicker;
|
Ticker fadeTicker;
|
||||||
bool isPressed = false,sleeping=false;
|
bool isPressed = false,sleeping=false;
|
||||||
unsigned long lastTouch;
|
unsigned long lastTouch;
|
||||||
static int16_t currentScreen = -1;
|
static lv_obj_t *currentScreen = NULL;
|
||||||
static enum ChartsEnum currentChart = CHART_ID_TEMP;
|
static enum ChartsEnum currentChart = CHART_ID_TEMP;
|
||||||
|
/*
|
||||||
static lv_obj_t *getLvglObjectFromIndex(int32_t index) {
|
static lv_obj_t *getLvglObjectFromIndex(int32_t index) {
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return ((lv_obj_t **)&objects)[index];
|
return ((lv_obj_t **)&objects)[index];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void loadScreen(ScreensEnum screenId) {
|
void loadScreen(lv_obj_t* screen) {
|
||||||
currentScreen = screenId - 1;
|
lv_scr_load_anim(screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 0, true);
|
||||||
lv_obj_t *screen = getLvglObjectFromIndex(currentScreen);
|
currentScreen = screen;
|
||||||
lv_scr_load_anim(screen, LV_SCR_LOAD_ANIM_FADE_IN, 200, 0, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fadeBrightness(uint16_t _newBrightness) {
|
void fadeBrightness(uint16_t _newBrightness) {
|
||||||
@ -88,8 +87,8 @@ void loadChart(uint8_t chartId){
|
|||||||
chart_autoscale();
|
chart_autoscale();
|
||||||
}
|
}
|
||||||
|
|
||||||
ScreensEnum ui_getCurrentScreen(void){
|
lv_obj_t* ui_getCurrentScreen(void){
|
||||||
return (ScreensEnum) (currentScreen + 1);
|
return currentScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChartsEnum ui_getCurrentChart(void){
|
ChartsEnum ui_getCurrentChart(void){
|
||||||
@ -97,8 +96,11 @@ ChartsEnum ui_getCurrentChart(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ui_init() {
|
void ui_init() {
|
||||||
create_screens();
|
lv_disp_t *dispp = lv_disp_get_default();
|
||||||
loadScreen(SCREEN_ID_MAIN);
|
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){
|
bool ui_isSleeping(void){
|
||||||
@ -163,9 +165,9 @@ void displayWake(){
|
|||||||
delay(50);
|
delay(50);
|
||||||
|
|
||||||
touch.setPins(TouchRST, TouchInt);
|
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
|
Wire.setClock(200000); //设置频率400KHZ
|
||||||
if(touch.begin(Wire, TouchI2CAddr, SDA, SCL)){
|
if(touch.begin(Wire, TouchI2CAddr, TouchSDA, TouchSCL)){
|
||||||
Serial.println("Touch screen initialization done");
|
Serial.println("Touch screen initialization done");
|
||||||
}
|
}
|
||||||
attachInterrupt(TouchInt, []() {
|
attachInterrupt(TouchInt, []() {
|
||||||
|
|||||||
@ -9,8 +9,8 @@
|
|||||||
|
|
||||||
#define TouchInt 8
|
#define TouchInt 8
|
||||||
#define TouchRST 9
|
#define TouchRST 9
|
||||||
#define SCL 7
|
#define TouchSCL 7
|
||||||
#define SDA 6
|
#define TouchSDA 6
|
||||||
|
|
||||||
#define TouchI2CAddr 0x15
|
#define TouchI2CAddr 0x15
|
||||||
|
|
||||||
@ -45,11 +45,11 @@ bool ui_isSleeping(void);
|
|||||||
void ui_tick();
|
void ui_tick();
|
||||||
void DisplayInit(void);
|
void DisplayInit(void);
|
||||||
void log_print(lv_log_level_t level, const char * buf);
|
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 loadChart(uint8_t chartId);
|
||||||
void ui_chart_autoscale(void);
|
void ui_chart_autoscale(void);
|
||||||
float ui_getSetTemp(void);
|
float ui_getSetTemp(void);
|
||||||
ScreensEnum ui_getCurrentScreen(void);
|
lv_obj_t* ui_getCurrentScreen(void);
|
||||||
ChartsEnum ui_getCurrentChart(void);
|
ChartsEnum ui_getCurrentChart(void);
|
||||||
void displaySleep();
|
void displaySleep();
|
||||||
void displayWake();
|
void displayWake();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user