battery status

This commit is contained in:
2021-05-10 19:36:14 +02:00
parent ef9d84b09d
commit d3992277df
2 changed files with 11 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
#define BOARDH #define BOARDH
#define IDLESHUTDOWN 900000 // 15min* 60 sec * 1000ms #define IDLESHUTDOWN 900000 // 15min* 60 sec * 1000ms
#define VBATTMIN 3200 #define VBATTMIN 3000
#define VBATTMAX 4180 #define VBATTMAX 4180
#define VBATTREF 3300 #define VBATTREF 3300

View File

@@ -18,6 +18,8 @@ void initBattery(void)
#ifdef VBATTPIN #ifdef VBATTPIN
#ifdef MEAS_EN #ifdef MEAS_EN
battery.onDemand(MEAS_EN, LOW); battery.onDemand(MEAS_EN, LOW);
//pinMode(MEAS_EN, OUTPUT);
//digitalWrite(MEAS_EN, HIGH);
battery.begin(VBATTREF, (R12 + R13) / R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2 battery.begin(VBATTREF, (R12 + R13) / R13); //R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
#else #else
@@ -63,15 +65,11 @@ bool handleBattery(void)
uint64_t currentmillis = millis(); uint64_t currentmillis = millis();
if (currentmillis - delay_timer > BATTERYMEASUREDELAY) if (currentmillis - delay_timer > BATTERYMEASUREDELAY)
{ {
uint16_t vbatt = battery.voltage(); uint32_t vbatt = battery.voltage();
if (vbatt < VBATTMIN) if (vbatt < VBATTMIN)
{ {
//turnOnAllLed(); return true;
} }
delay_timer = currentmillis;
// delay(5000);
// shutdown();
} }
#endif #endif
@@ -150,6 +148,10 @@ void handlePowerState(void)
powerstate = on; powerstate = on;
powerOn(); powerOn();
turnOffAllLed(); turnOffAllLed();
delay(500);
batterydisplay();
delay(1000);
turnOffAllLed();
} }
} }
break; break;
@@ -160,11 +162,11 @@ void handlePowerState(void)
powerstate = poweringOff; powerstate = poweringOff;
turnOnAllLed(); turnOnAllLed();
} }
if (HandleTimeOut()) else if (HandleTimeOut())
{ {
powerstate = timeOut; powerstate = timeOut;
} }
if (handleBattery()) else if (handleBattery())
{ {
powerstate = lowBatt; powerstate = lowBatt;
} }