From 1e0c5837d6c727ee7ef71bb01b899bc58cce6022 Mon Sep 17 00:00:00 2001 From: Christian Loch Date: Mon, 20 Apr 2020 23:43:01 +0200 Subject: [PATCH] Implement display updates --- components/display/display.c | 158 +++++++++++++++++++++++++++-------- components/display/display.h | 3 +- main/main.c | 7 +- 3 files changed, 128 insertions(+), 40 deletions(-) diff --git a/components/display/display.c b/components/display/display.c index ccbda5f..089f858 100644 --- a/components/display/display.c +++ b/components/display/display.c @@ -168,71 +168,159 @@ color_t temp_color(int32_t temp_raw) { return col; } -int32_t last_temp_raw = 0; -uint32_t last_pressure_raw = 0; -uint32_t last_humidity_raw = 0; -int32_t last_temp2_raw = 0; -uint32_t last_pressure2_raw = 0; -uint32_t last_humidity2_raw = 0; +void print_temp1(int32_t temp_raw) +{ + // Calc temperature pre and post comma values + int32_t temp_pre = temp_raw / 100; + int32_t temp_post = (abs(temp_raw) % 100) / 10; + char temp_str[12]; + sprintf(temp_str, "% 2.2d,%.1d", temp_pre, temp_post); -void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, - int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) + TFT_setFont(DEJAVU18_FONT, NULL); + tft_fg = temp_color(temp_raw); + TFT_print(temp_str, layout.innenLeft, layout.tempBaseline); +} + +void print_temp2(int32_t temp_raw) { // Calc temperature pre and post comma values int32_t temp_pre = temp_raw / 100; int32_t temp_post = (abs(temp_raw) % 100) / 10; char temp_str[12]; sprintf(temp_str, "% 2.2d,%.1d", temp_pre, temp_post); - int32_t temp2_pre = temp2_raw / 100; - int32_t temp2_post = (abs(temp2_raw) % 100) / 10; - char temp2_str[12]; - sprintf(temp2_str, "% 2.2d,%.1d", temp2_pre, temp2_post); - // Calc humidity pre and post comma values - uint32_t humid_pre = humidity_raw / 1024; - uint32_t humid_post = (humidity_raw - humid_pre*1024) * 10 / 1024; - char humid_str[12]; - sprintf(humid_str, "%2.2d,%.1d", humid_pre, humid_post); - uint32_t humid2_pre = humidity2_raw / 1024; - uint32_t humid2_post = (humidity2_raw - humid2_pre*1024) * 10 / 1024; - char humid2_str[12]; - sprintf(humid2_str, "%2.2d,%.1d", humid2_pre, humid2_post); + TFT_setFont(DEJAVU18_FONT, NULL); + tft_fg = temp_color(temp_raw); + TFT_print(temp_str, layout.aussenLeft, layout.tempBaseline); +} +void print_press1(uint32_t pressure_raw) +{ // Calc pressure values uint32_t press = pressure_raw / 100; char press_str[12]; sprintf(press_str, "%d", press); - uint32_t press2 = pressure2_raw / 100; - char press2_str[12]; - sprintf(press2_str, "%d", press2); + TFT_setFont(UBUNTU16_FONT, NULL); + tft_fg = TFT_WHITE; + TFT_print(press_str, layout.innenLeft, layout.pressBaseline); +} +void print_press2(uint32_t pressure_raw) +{ + // Calc pressure values + uint32_t press = pressure_raw / 100; + char press_str[12]; + sprintf(press_str, "%d", press); TFT_setFont(UBUNTU16_FONT, NULL); - TFT_fillScreen(TFT_BLACK); tft_fg = TFT_WHITE; + TFT_print(press_str, layout.aussenLeft, layout.pressBaseline); +} +void print_humid1(uint32_t humidity_raw) +{ + // Calc humidity pre and post comma values + uint32_t humid_pre = humidity_raw / 1024; + uint32_t humid_post = (humidity_raw - humid_pre*1024) * 10 / 1024; + char humid_str[12]; + sprintf(humid_str, "%2.2d,%.1d", humid_pre, humid_post); + TFT_setFont(UBUNTU16_FONT, NULL); + tft_fg = TFT_WHITE; + TFT_print(humid_str, layout.innenLeft, layout.humBaseline); +} + +void print_humid2(uint32_t humidity_raw) +{ + // Calc humidity pre and post comma values + uint32_t humid_pre = humidity_raw / 1024; + uint32_t humid_post = (humidity_raw - humid_pre*1024) * 10 / 1024; + char humid_str[12]; + sprintf(humid_str, "%2.2d,%.1d", humid_pre, humid_post); + TFT_setFont(UBUNTU16_FONT, NULL); + tft_fg = TFT_WHITE; + TFT_print(humid_str, layout.aussenLeft, layout.humBaseline); +} + +int32_t last_temp_raw = 0; +uint32_t last_pressure_raw = 0; +uint32_t last_humidity_raw = 0; +int32_t last_temp2_raw = 0; +uint32_t last_pressure2_raw = 0; +uint32_t last_humidity2_raw = 0; + +void update_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, + int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) +{ + if (temp_raw != last_temp_raw) { + print_temp1(temp_raw); + last_temp_raw = temp_raw; + } + if (temp2_raw != last_temp2_raw) { + print_temp2(temp2_raw); + last_temp2_raw = temp2_raw; + } + + if (pressure_raw != last_pressure_raw) { + print_press1(pressure_raw); + last_pressure_raw = pressure_raw; + } + if (pressure2_raw != last_pressure2_raw) { + print_press2(pressure2_raw); + last_pressure2_raw = pressure2_raw; + } + + if (humidity_raw != last_humidity_raw) { + print_humid1(humidity_raw); + last_humidity_raw = humidity_raw; + } + if (humidity2_raw != last_humidity2_raw) { + print_humid2(humidity2_raw); + last_humidity2_raw = humidity2_raw; + } + + last_pressure_raw = pressure_raw; + last_humidity_raw = humidity_raw; + last_temp2_raw = temp2_raw; + last_pressure2_raw = pressure2_raw; + last_humidity2_raw = humidity2_raw; +} + + +void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, + int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw) +{ + // HEADER + TFT_setFont(UBUNTU16_FONT, NULL); + tft_fg = TFT_WHITE; TFT_print("25.12.2031 08:31", layout.dateTimeLeft, layout.datetimeBaseline); TFT_drawFastHLine(0, 20, 160, TFT_WHITE); + // IN OUT LABEL TFT_print("Innen", layout.innenLeft, layout.innenBaseline); TFT_print("Aussen", layout.aussenLeft, layout.aussenBaseline); + // VALUES + print_temp1(temp_raw); + print_temp2(temp2_raw); + print_humid1(humidity_raw); + print_humid2(humidity2_raw); + print_press1(pressure_raw); + print_press2(pressure2_raw); + + // UNIT LABELS TFT_setFont(DEJAVU18_FONT, NULL); - tft_fg = temp_color(temp_raw); - TFT_print(temp_str, layout.innenLeft, layout.tempBaseline); - tft_fg = temp_color(temp2_raw); - TFT_print(temp2_str, layout.aussenLeft, layout.tempBaseline); tft_fg = TFT_WHITE; TFT_print(" C", layout.unitLeft, layout.tempBaseline); TFT_drawCircle(layout.unitLeft+3, layout.tempBaseline+3, 3, TFT_WHITE); - TFT_setFont(UBUNTU16_FONT, NULL); - TFT_print(humid_str, layout.innenLeft, layout.humBaseline); - TFT_print(humid2_str, layout.aussenLeft, layout.humBaseline); TFT_print("%", layout.unitLeft, layout.humBaseline); - - TFT_print(press_str, layout.innenLeft, layout.pressBaseline); - TFT_print(press2_str, layout.aussenLeft, layout.pressBaseline); TFT_print("hPa", layout.unitLeft, layout.pressBaseline); + + last_temp_raw = temp_raw; + last_pressure_raw = pressure_raw; + last_humidity_raw = humidity_raw; + last_temp2_raw = temp2_raw; + last_pressure2_raw = pressure2_raw; + last_humidity2_raw = humidity2_raw; } esp_err_t init_display() diff --git a/components/display/display.h b/components/display/display.h index 6851d7f..cd4b611 100644 --- a/components/display/display.h +++ b/components/display/display.h @@ -19,7 +19,8 @@ esp_err_t init_display(); void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw); -//void update_temp1(int32_t temp1); +void update_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw, + int32_t temp2_raw, uint32_t pressure2_raw, uint32_t humidity2_raw); void test_tft_lib(); diff --git a/main/main.c b/main/main.c index 031ebe8..e6385d9 100644 --- a/main/main.c +++ b/main/main.c @@ -495,13 +495,12 @@ void app_main(void) // server = start_webserver(); init_display(); - - + read_sensor(&dev, &temp, &pressure, &humidity); + read_sensor(&dev2, &temp2, &pressure2, &humidity2); + display_data(temp, pressure, humidity, temp2, pressure2, humidity2); while (1) { read_sensor(&dev, &temp, &pressure, &humidity); read_sensor(&dev2, &temp2, &pressure2, &humidity2); - printf("%i °C, %i hPa, %i %%\r\n", temp, pressure, humidity); - printf("%i °C, %i hPa, %i %%\r\n", temp2, pressure2, humidity2); display_data(temp, pressure, humidity, temp2, pressure2, humidity2); vTaskDelay(1000 / portTICK_PERIOD_MS); }