From f91b3fa016d25d1c236b073dca305e5a9a9f9013 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 2 May 2020 17:24:52 +0200 Subject: [PATCH 1/2] battery monitor fixes --- src/display.cpp | 4 +--- src/lorawan.cpp | 17 +++++------------ src/power.cpp | 18 +++++------------- 3 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 3fa7e62a..732b3063 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -283,10 +283,8 @@ void dp_drawPage(time_t t, bool nextpage) { #if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306) if (batt_level == 0) dp_printf("No batt "); - else if (batt_level < 100) - dp_printf("B:%3d%% ", batt_level); else - dp_printf("ext.Pwr "); + dp_printf("B:%3d%% ", batt_level); #else dp_printf(" "); #endif diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 9e5250f8..ac3dd1f2 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -482,29 +482,22 @@ uint8_t myBattLevelCb(void *pUserData) { // we calculate the applicable value from MCMD_DEVS_BATT_MIN to // MCMD_DEVS_BATT_MAX from bat_percent value - uint8_t lmic_batt_level; uint8_t const batt_percent = read_battlevel(); if (batt_percent == 0) - lmic_batt_level = MCMD_DEVS_BATT_NOINFO; + return MCMD_DEVS_BATT_NOINFO; else #ifdef HAS_PMU if (pmu.isVBUSPlug()) - lmic_batt_level = MCMD_DEVS_EXT_POWER; + return MCMD_DEVS_EXT_POWER; #elif defined HAS_IP5306 if (IP5306_GetPowerSource()) - lmic_batt_level = MCMD_DEVS_EXT_POWER; + return MCMD_DEVS_EXT_POWER; #else - if (batt_percent >= 100) - lmic_batt_level = MCMD_DEVS_EXT_POWER; + return (batt_percent / 100.0 * + (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1)); #endif // HAS_PMU - - else - lmic_batt_level = - batt_percent / 100.0 * (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1); - - return lmic_batt_level; } // event EV_RXCOMPLETE message handler diff --git a/src/power.cpp b/src/power.cpp index 062bbcb8..2c6012b5 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -211,26 +211,18 @@ uint16_t read_voltage(void) { } uint8_t read_battlevel(mapFn_t mapFunction) { - // returns the estimated battery level in values 0 ... 100 [percent] - - uint8_t batt_percent; - #ifdef HAS_IP5306 - batt_percent = IP5306_GetBatteryLevel(); + return IP5306_GetBatteryLevel(); #else const uint16_t batt_voltage = read_voltage(); - if (batt_voltage <= BAT_MIN_VOLTAGE) - batt_percent = 0; + return 0; else if (batt_voltage >= BAT_MAX_VOLTAGE) - batt_percent = 100; + return 100; else - batt_percent = - (*mapFunction)(batt_voltage, BAT_MIN_VOLTAGE, BAT_MAX_VOLTAGE); -#endif // HAS_IP5306 - - return batt_percent; + return (*mapFunction)(batt_voltage, BAT_MIN_VOLTAGE, BAT_MAX_VOLTAGE); +#endif } bool batt_sufficient() { From e6d838bc2b369ce5c1c7da748fefd40a54f3c197 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 2 May 2020 17:25:04 +0200 Subject: [PATCH 2/2] RGB LED color fix --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c5ee155e..3d83ebce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -233,7 +233,6 @@ void setup() { #ifdef HAS_RGB_LED switch_LED(LED_ON); strcat_P(features, " RGB"); - rgb_set_color(COLOR_PINK); #endif #endif // HAS_LED