Skip to content

Commit

Permalink
Fix #133 - force deep sleep if battery reaches 10%
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed May 17, 2020
1 parent ef1463a commit efc2395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/PowerFSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ void PowerFSM_setup()
powerFSM.add_transition(&stateDARK, &stateON, EVENT_PRESS, NULL, "Press");
powerFSM.add_transition(&stateON, &stateON, EVENT_PRESS, screenPress, "Press"); // reenter On to restart our timers

// Handle critically low power battery by forcing deep sleep
powerFSM.add_transition(&stateBOOT, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
powerFSM.add_transition(&stateLS, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
powerFSM.add_transition(&stateNB, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
powerFSM.add_transition(&stateDARK, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");
powerFSM.add_transition(&stateON, &stateSDS, EVENT_LOW_BATTERY, NULL, "LowBat");

powerFSM.add_transition(&stateDARK, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");
powerFSM.add_transition(&stateON, &stateON, EVENT_BLUETOOTH_PAIR, NULL, "Bluetooth pairing");

Expand Down
1 change: 1 addition & 0 deletions src/PowerFSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define EVENT_BLUETOOTH_PAIR 7
#define EVENT_NODEDB_UPDATED 8 // NodeDB has a big enough change that we think you should turn on the screen
#define EVENT_CONTACT_FROM_PHONE 9 // the phone just talked to us over bluetooth
#define EVENT_LOW_BATTERY 10 // Battery is critically low, go to sleep

extern Fsm powerFSM;

Expand Down
9 changes: 4 additions & 5 deletions src/esp32/main-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ uint32_t axpDebugRead()
Periodic axpDebugOutput(axpDebugRead);
#endif

#define MIN_BAT_MILLIVOLTS 3690 // millivolts. 10% per https://blog.ampow.com/lipo-voltage-chart/
#define MIN_BAT_MILLIVOLTS 5000 // 3690 // millivolts. 10% per https://blog.ampow.com/lipo-voltage-chart/

/// loop code specific to ESP32 targets
void esp32Loop()
Expand Down Expand Up @@ -226,10 +226,9 @@ void esp32Loop()
axp.clearIRQ();
}

float v = axp.getBattVoltage();
DEBUG_MSG("Bat volt %f\n", v);
//if(v >= MIN_BAT_MILLIVOLTS / 2 && v < MIN_BAT_MILLIVOLTS) // If we have a battery at all and it is less than 10% full, force deep sleep
// powerFSM.trigger(EVENT_LOW_BATTERY);
if (powerStatus.haveBattery && !powerStatus.usb &&
axp.getBattVoltage() < MIN_BAT_MILLIVOLTS) // If we have a battery at all and it is less than 10% full, force deep sleep
powerFSM.trigger(EVENT_LOW_BATTERY);

#endif // T_BEAM_V10
}

2 comments on commit efc2395

@spattinson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MIN_BAT_MILLIVOLTS seems high. Typical 18650 are different chemistry to LiPo, even for LiPos that chart seems a bit off, other charts put 3690mV at about 30% for a lipo, for 18650 i think 10% remaining iis in the region of 3.2-3.3V. Reference 1st graph in this test report looking at the red line - discharge at 0.2A - he gets a capacity of 2900mah, 90% of 2900 = 2610, that point in the graph looks to be a shade above 3.2V

@geeksville
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super great - thanks I'll make that change. also - if you find any radioish problems PRs / issues apprecaited.

Please sign in to comment.