From 3a800c09c21629b9e5ac271d6e8586b5d0e20165 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 18 Sep 2022 17:21:22 +0200 Subject: [PATCH 1/2] AXP192 lib updates --- include/payload.h | 2 +- include/power.h | 2 +- src/display.cpp | 6 +++--- src/power.cpp | 27 +++++++++++++++------------ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/payload.h b/include/payload.h index 43bbb1d8a..2add80b7a 100644 --- a/include/payload.h +++ b/include/payload.h @@ -100,6 +100,6 @@ class PayloadConvert { }; extern PayloadConvert payload; -extern uint8_t batt_level; +extern int8_t batt_level; #endif // _PAYLOAD_H_ diff --git a/include/power.h b/include/power.h index 8a69e2693..1f7b73332 100644 --- a/include/power.h +++ b/include/power.h @@ -131,6 +131,6 @@ static inline uint8_t linear(uint16_t voltage, uint16_t minVoltage, (maxVoltage - minVoltage); } -uint8_t read_battlevel(mapFn_t mapFunction = &sigmoidal); +int8_t read_battlevel(mapFn_t mapFunction = &sigmoidal); #endif \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index c9aaad209..2526e514a 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -226,10 +226,10 @@ void dp_refresh(bool nextPage) { // line 4: Battery + GPS status + Wifi channel // B:a.bcV Sats:ab ch:ab #if (defined BAT_MEASURE_ADC || defined HAS_PMU || defined HAS_IP5306) - if (batt_level == 0) - dp->printf("No batt "); - else + if (batt_level > 0) dp->printf("Batt:%3u%% ", batt_level); + else + dp->printf("No batt "); #else dp->printf(" "); #endif diff --git a/src/power.cpp b/src/power.cpp index 729344610..0e346cacd 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -5,7 +5,7 @@ // Local logging tag static const char TAG[] = __FILE__; -uint8_t batt_level = 0; // display value +int8_t batt_level = -1; // percent batt level, global variable, -1 means no batt #ifdef BAT_MEASURE_ADC esp_adc_cal_characteristics_t *adc_characs = @@ -92,11 +92,11 @@ void AXP192_showstatus(void) { if (pmu.isBatteryConnect()) if (pmu.isCharging()) ESP_LOGI(TAG, "Battery charging, %.2fV @ %.0fmAh", - pmu.getBattVoltage() / 1000, pmu.getBatteryChargeCurrent()); + pmu.getBattVoltage() / 1000.0, pmu.getBatteryChargeCurrent()); else ESP_LOGI(TAG, "Battery not charging"); else - ESP_LOGI(TAG, "No Battery"); + ESP_LOGI(TAG, "Battery not present"); if (pmu.isVbusIn()) ESP_LOGI(TAG, "USB powered, %.0fmW", @@ -142,10 +142,14 @@ void AXP192_init(void) { // clear all interrupt flags pmu.clearIrqStatus(); // enable the required interrupt function - pmu.enableIRQ(XPOWERS_AXP192_BAT_INSERT_IRQ | XPOWERS_AXP192_BAT_REMOVE_IRQ | // BATTERY - XPOWERS_AXP192_VBUS_INSERT_IRQ | XPOWERS_AXP192_VBUS_REMOVE_IRQ | // VBUS - XPOWERS_AXP192_PKEY_SHORT_IRQ | XPOWERS_AXP192_PKEY_LONG_IRQ | // POWER KEY - XPOWERS_AXP192_BAT_CHG_DONE_IRQ | XPOWERS_AXP192_BAT_CHG_START_IRQ // CHARGE + pmu.enableIRQ(XPOWERS_AXP192_BAT_INSERT_IRQ | + XPOWERS_AXP192_BAT_REMOVE_IRQ | // BATTERY + XPOWERS_AXP192_VBUS_INSERT_IRQ | + XPOWERS_AXP192_VBUS_REMOVE_IRQ | // VBUS + XPOWERS_AXP192_PKEY_SHORT_IRQ | + XPOWERS_AXP192_PKEY_LONG_IRQ | // POWER KEY + XPOWERS_AXP192_BAT_CHG_DONE_IRQ | + XPOWERS_AXP192_BAT_CHG_START_IRQ // CHARGE ); #endif // PMU_INT @@ -231,14 +235,13 @@ uint16_t read_voltage(void) { return voltage; } -uint8_t read_battlevel(mapFn_t mapFunction) { +int8_t read_battlevel(mapFn_t mapFunction) { // returns the estimated battery level in values 0 ... 100 [percent] uint8_t batt_percent = 0; #ifdef HAS_IP5306 batt_percent = IP5306_GetBatteryLevel(); #elif defined HAS_PMU - int bp = pmu.getBatteryPercent(); - batt_percent = bp < 0 ? 0 : bp; + batt_percent = pmu.getBatteryPercent(); #else const uint16_t batt_voltage = read_voltage(); if (batt_voltage <= BAT_MIN_VOLTAGE) @@ -260,7 +263,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { // we calculate the applicable value from MCMD_DEVS_BATT_MIN to // MCMD_DEVS_BATT_MAX from batt_percent value - if (batt_percent == 0) + if (batt_percent == -1) LMIC_setBatteryLevel(MCMD_DEVS_BATT_NOINFO); else LMIC_setBatteryLevel(batt_percent / 100.0 * @@ -282,7 +285,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { bool batt_sufficient() { #if (defined HAS_PMU || defined BAT_MEASURE_ADC || defined HAS_IP5306) - if (batt_level) // we have a battery voltage + if (batt_level > 0) // we have a battery percent value return (batt_level > OTA_MIN_BATT); else #endif From 6c44865f508bfa38c4a330f38b3154324270f283 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 18 Sep 2022 17:21:40 +0200 Subject: [PATCH 2/2] bump to v3.3.2 --- platformio_orig.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio_orig.ini b/platformio_orig.ini index e53eded31..f1ef25680 100644 --- a/platformio_orig.ini +++ b/platformio_orig.ini @@ -46,7 +46,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I [common] ; for release_version use max. 10 chars total, use any decimal format like "a.b.c" -release_version = 3.3.1 +release_version = 3.3.2 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose debug_level = 3 @@ -71,11 +71,11 @@ lib_deps_rgbled = lib_deps_gps = mikalhart/TinyGPSPlus @ ^1.0.2 lib_deps_sensors = - adafruit/Adafruit Unified Sensor @ ^1.1.4 - adafruit/Adafruit BME280 Library @ ^2.2.1 - adafruit/Adafruit BMP085 Library @ ^1.2.0 + adafruit/Adafruit Unified Sensor @ ^1.1.6 + adafruit/Adafruit BME280 Library @ ^2.2.2 + adafruit/Adafruit BMP085 Library @ ^1.2.1 boschsensortec/BSEC Software Library @ 1.6.1480 - https://github.com/cyberman54/sds-dust-sensors-arduino-library.git + lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1 lib_deps_basic = https://github.com/dbSuS/libpax.git https://github.com/SukkoPera/Arduino-Rokkit-Hash.git @@ -83,7 +83,7 @@ lib_deps_basic = makuna/RTC @ ^2.3.5 spacehuhn/SimpleButton lewisxhe/XPowersLib @ ^0.1.4 - 256dpi/MQTT @ ^2.4.8 + 256dpi/MQTT @ ^2.5.0 lib_deps_all = ${common.lib_deps_basic} ${common.lib_deps_lora}