From af02c2c6613bb7d79c0e2c4f84f34361f7857369 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Tue, 14 Apr 2020 00:15:51 +0200 Subject: [PATCH] battery level calculation fixes --- include/power.h | 23 ++++++----------------- src/lorawan.cpp | 2 +- src/power.cpp | 4 ++-- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/include/power.h b/include/power.h index f8604252..c2c91c94 100644 --- a/include/power.h +++ b/include/power.h @@ -7,7 +7,6 @@ #include "i2c.h" #include "reset.h" -#include "lorawan.h" #define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate #define NO_OF_SAMPLES 64 // we do some multisampling to get better values @@ -28,6 +27,7 @@ bool batt_sufficient(void); #ifdef HAS_PMU #include +extern AXP20X_Class pmu; enum pmu_power_t { pmu_power_on, pmu_power_off, pmu_power_sleep }; void AXP192_powerevent_IRQ(void); void AXP192_power(pmu_power_t powerlevel); @@ -37,22 +37,11 @@ void AXP192_showstatus(void); #endif // HAS_PMU // The following map functions were taken from - -/* - Battery.h - Battery library - Copyright (c) 2014 Roberto Lo Giacco. - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation, either version 3 of the - License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - +// +// Battery.h - Battery library +// Copyright (c) 2014 Roberto Lo Giacco +// https://github.com/rlogiacco/BatterySense + /** * Symmetric sigmoidal approximation * https://www.desmos.com/calculator/7m9lu26vpy diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 4e3d7469..e6a35534 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -488,7 +488,7 @@ void lora_setBattLevel(uint8_t batt_percent) { lmic_batt_level = batt_percent / 100.0 * (MCMD_DEVS_BATT_MAX - MCMD_DEVS_BATT_MIN + 1); - LMIC_setBattLevel(lmic_batt_level); + //LMIC_setBattLevel(lmic_batt_level); } // event EV_RXCOMPLETE message handler diff --git a/src/power.cpp b/src/power.cpp index c5da9a13..192c2255 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -212,7 +212,7 @@ uint16_t read_voltage(void) { uint8_t read_battlevel(mapFn_t mapFunction) { - // returns the estimated battery level in values 0 ... 100 [percent], + // returns the estimated battery level in values 0 ... 100 [percent] const uint16_t batt_voltage = read_voltage(); uint8_t batt_percent; @@ -230,7 +230,7 @@ uint8_t read_battlevel(mapFn_t mapFunction) { #if (HAS_LORA) // to come with future LMIC version - // lora_setBattLevel(batt_percent); + lora_setBattLevel(batt_percent); #endif return batt_percent;