From 49a5240c521fe64d0ba1f97bfef527e9c57242f0 Mon Sep 17 00:00:00 2001 From: Christian Loch Date: Mon, 20 Apr 2020 19:48:33 +0200 Subject: [PATCH] Add Eva's temp to color functions --- components/display/display.c | 65 ++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/components/display/display.c b/components/display/display.c index 5b97d0c..ccbda5f 100644 --- a/components/display/display.c +++ b/components/display/display.c @@ -114,6 +114,67 @@ layout_t create_layout() return layout; } +uint8_t interpolation(int32_t arg) { + int32_t i32_val = arg * 256 / 1000; + uint8_t u8_val = (uint8_t)i32_val; + return u8_val; +} + +color_t temp_color(int32_t temp_raw) { + color_t col = { 0 }; + if (temp_raw >= 3500) + col.r = 255; + else if (temp_raw < 3500 && temp_raw > 2500) { + int32_t diff = 3500 - temp_raw; + col.r = 255; + col.g = interpolation(diff); + } + else if (temp_raw == 2500) { + col.r = 255; + col.g = 255; + } + else if (temp_raw < 2500 && temp_raw > 1500) { + int32_t diff = temp_raw - 1500; + col.r = interpolation(diff); + col.g = 255; + } + else if (temp_raw == 1500) + col.g = 255; + else if (temp_raw < 1500 && temp_raw > 500) { + int32_t diff = 1500 - temp_raw; + col.g = 255; + col.b = interpolation(diff); + } + else if (temp_raw == 500) { + col.g = 255; + col.b = 255; + } + else if (temp_raw < 500 && temp_raw > -500) { + int32_t diff = temp_raw + 500; + col.g = interpolation(diff); + col.b = 255; + } + else if (temp_raw == -500) + col.b = 255; + else if (temp_raw < -500 && temp_raw > -1500) { + int32_t diff = -500 - temp_raw; + col.r = interpolation(diff); + col.b = 255; + } + else if (temp_raw <= -1500) { + col.r = 255; + col.b = 255; + } + 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 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) { @@ -156,9 +217,9 @@ void display_data(int32_t temp_raw, uint32_t pressure_raw, uint32_t humidity_raw TFT_print("Aussen", layout.aussenLeft, layout.aussenBaseline); TFT_setFont(DEJAVU18_FONT, NULL); - tft_fg = TFT_RED; + tft_fg = temp_color(temp_raw); TFT_print(temp_str, layout.innenLeft, layout.tempBaseline); - tft_fg = TFT_YELLOW; + 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);