From 535c1ef6127747777c61a65092e2aad7e39c10a4 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Tue, 30 Jun 2020 17:06:01 +0200 Subject: [PATCH] display wifi status and battery percent --- src/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4a5be4f..8ea62c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -120,6 +120,14 @@ time_t getTimestamp() { } +float mapf(float x, float in_min, float in_max, float out_min, float out_max) { + float newval = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + if (newval > out_max) newval = out_max; + if (newval < out_min) newval = out_min; + return newval; +} + + void poweroffDevices() { display.powerOff(); @@ -175,13 +183,6 @@ void wifiConnect() { wifiMulti.addAP(WIFI_SSID2, WIFI_PASSWD2); wifiMulti.addAP(WIFI_SSID3, WIFI_PASSWD3); - Serial.println(WIFI_SSID); - Serial.println(WIFI_PASSWD); - Serial.println(WIFI_SSID2); - Serial.println(WIFI_PASSWD2); - Serial.println(WIFI_SSID3); - Serial.println(WIFI_PASSWD3); - IPAddress ip = IPAddress(network.ip); IPAddress dns = IPAddress(network.dns); IPAddress subnet = IPAddress(network.subnet); @@ -487,12 +488,19 @@ void displayValues() { display.drawLine(0,y_offset+10,display.width(), y_offset+10, GxEPD_BLACK); // Status + display.setFont(NULL); display.setCursor(190,y_offset+0); if(WiFi.status() == WL_CONNECTED) { display.print("W"); } else { display.print("_"); } + if (sensor_readings.voltage <= 4.0F) { + display.setCursor(220,y_offset+0); + int battery_percent = mapf(sensor_readings.voltage, 3.3, 4.1, 0, 100); + display.printf("%3d", battery_percent); + display.print(" \%"); + } // Temp display.drawRect(0,y_offset+10,64,50,GxEPD_BLACK);