Skip to content

Commit

Permalink
Merge pull request #894 from cyberman54/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
cyberman54 authored Sep 18, 2022
2 parents 26b0a55 + 6c44865 commit c87113f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/payload.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ class PayloadConvert {
};

extern PayloadConvert payload;
extern uint8_t batt_level;
extern int8_t batt_level;

#endif // _PAYLOAD_H_
2 changes: 1 addition & 1 deletion include/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions platformio_orig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,19 +71,19 @@ 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
bblanchon/ArduinoJson @ ^6
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}
Expand Down
6 changes: 3 additions & 3 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions src/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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 *
Expand All @@ -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
Expand Down

0 comments on commit c87113f

Please sign in to comment.