From 1fb32d8f01c7677f64a8475ac4255f53ae8c5b53 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 7 Aug 2019 19:27:16 +0200 Subject: [PATCH] display layout optimization --- src/main.cpp | 89 ++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ca9e074..af1a7b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,7 +44,7 @@ static const char* TAG = "MAIN"; WiFiMulti wifiMulti; GxEPD2_BW display(GxEPD2_213_B72(/*CS=SS*/ TFT_CS, /*DC=*/ TFT_DC, /*RST=*/ TFT_RST, /*BUSY=*/ -1)); // GDEH0213B72 -static constexpr uint8_t y_offset = 8; +static constexpr uint8_t y_offset = 6; Adafruit_BME280 bme280; // I2C (also available: hardware SPI Adafruit_BME680 bme680; // I2C (also available: hardware SPI @@ -239,6 +239,8 @@ void receiveMqtt(const char* topic, const char* data) { sensor->pm10 = atof(data); } else if (strcmp("/pm25", topic_last) == 0) { sensor->pm25 = atof(data); + } else if (strcmp("/lux", topic_last) == 0) { + sensor->lux = atof(data); } else if (strcmp("/uvi", topic_last) == 0) { sensor->uvi = atof(data); } else if (strcmp("/uva", topic_last) == 0) { @@ -280,7 +282,7 @@ void displayValues() { display.drawLine(0,y_offset+10,display.width(), y_offset+10, GxEPD_BLACK); // Temp - display.drawRect(0,y_offset+10,66,50,GxEPD_BLACK); + display.drawRect(0,y_offset+10,64,50,GxEPD_BLACK); display.setFont(NULL); display.setCursor(5,y_offset+15); display.printf("max: %.1f", sensor_readings.temperature_max); @@ -293,16 +295,16 @@ void displayValues() { display.printf("min: %.1f", sensor_readings.temperature_min); // Humidity - display.drawRect(65,y_offset+10,66,50,GxEPD_BLACK); + display.drawRect(63,y_offset+10,58,50,GxEPD_BLACK); display.setFont(NULL); - display.setCursor(70,y_offset+15); + display.setCursor(68,y_offset+15); display.print("Humidity"); display.setFont(&FreeSansBold9pt7b); - display.setCursor(70,y_offset+40); + display.setCursor(68,y_offset+40); display.printf("%.1f", sensor_readings.humidity); display.setFont(NULL); display.print(" \%"); - display.setCursor(70,y_offset+45); + display.setCursor(68,y_offset+45); if (sensor_readings.humidity < 30) { display.print("low"); } else if (sensor_readings.humidity < 60) { @@ -313,17 +315,17 @@ void displayValues() { // Pressure - display.drawRect(130,y_offset+10,66,50,GxEPD_BLACK); + display.drawRect(120,y_offset+10,66,50,GxEPD_BLACK); display.setFont(NULL); - display.setCursor(135,y_offset+15); + display.setCursor(125,y_offset+15); display.print("Pressure"); display.setFont(&FreeSansBold9pt7b); - display.setCursor(135,y_offset+40); + display.setCursor(125,y_offset+40); display.printf("%.1f", sensor_readings.pressure); display.setFont(NULL); //display.print(" hPa"); float pressure_diff = history_pressure.getElement(0) - history_pressure.getFirst(); - display.setCursor(135,y_offset+45); + display.setCursor(125,y_offset+45); if (isnan(pressure_diff) || history_pressure.getCount() < history_pressure.getSize()) { } else if (pressure_diff > -20 && pressure_diff < -0.6) { display.print("Trend: \x19\x19"); @@ -341,12 +343,12 @@ void displayValues() { // Other - display.drawRect(195,y_offset+10,56,122-10,GxEPD_BLACK); + display.drawRect(185,y_offset+10,250-186+1,122-10,GxEPD_BLACK); display.setFont(NULL); // VOC - display.setCursor(200,y_offset+15); - display.println("VOC:"); - display.setCursor(200,y_offset+25); + display.setCursor(190,y_offset+15); + display.println("-- VOC --"); + display.setCursor(190,y_offset+25); display.printf("%.1f k\xe9", sensor_readings.voc / 1000.0F); // PM float pm10, pm25; @@ -366,17 +368,29 @@ void displayValues() { pm10 = NAN; pm25 = NAN; } - display.setCursor(200,y_offset+45); - display.println("PM10/2.5:"); - display.setCursor(200,y_offset+55); + display.setCursor(190,y_offset+37); + display.println("-- PM --"); + display.setCursor(190,y_offset+47); display.printf("%.1f", pm10); - display.setCursor(200,y_offset+65); + display.setCursor(220,y_offset+47); display.printf("%.1f", pm25); // Lux - //display.setCursor(200,y_offset+80); - //display.println("Lux:"); - //display.setCursor(200,y_offset+90); - //display.printf("%.1f", sensor_readings.lux); + float lux; + if (light_active) { + lux = sensor_readings.lux; + } else if (!isnan(sensors_a4cf1211c3e4.lux)) { + lux = sensors_a4cf1211c3e4.lux; + } else if (!isnan(sensors_246f28d1fa5c.lux)) { + lux = sensors_246f28d1fa5c.lux; + } else if (!isnan(sensors_246f28d1a080.lux)) { + lux = sensors_246f28d1a080.lux; + } else { + lux = NAN; + } + display.setCursor(190,y_offset+59); + display.println("-- Lux --"); + display.setCursor(190,y_offset+69); + display.printf("%.1f lx", lux); // UV float uvi, uva, uvb; if (uv_active) { @@ -400,36 +414,15 @@ void displayValues() { uva = NAN; uvb = NAN; } - display.setCursor(200,y_offset+80); - display.println("UV I/A/B:"); - display.setCursor(200,y_offset+90); + display.setCursor(190,y_offset+80); + display.println("UV(I/A/B):"); + display.setCursor(190,y_offset+90); display.printf("%.1f", uvi); - display.setCursor(200,y_offset+100); + display.setCursor(190,y_offset+100); display.printf("%.1f", uva); - display.setCursor(200,y_offset+110); + display.setCursor(190,y_offset+110); display.printf("%.1f", uvb); - - float lux; - if (light_active) { - lux = sensor_readings.lux; - } else if (!isnan(sensors_a4cf1211c3e4.lux)) { - lux = sensors_a4cf1211c3e4.lux; - } else if (!isnan(sensors_246f28d1fa5c.lux)) { - lux = sensors_246f28d1fa5c.lux; - } else if (!isnan(sensors_246f28d1a080.lux)) { - lux = sensors_246f28d1a080.lux; - } else { - lux = NAN; - - } - display.setCursor(200,y_offset+120); - display.println("LUX"); - display.setCursor(200,y_offset+130); - display.printf("%.1f", lux); - - - // other nodes display.setFont(NULL); display.setCursor(0, y_offset+70);