Skip to content

Commit

Permalink
show reason for last reset
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed Mar 8, 2020
1 parent a4ebf83 commit f87cb00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion release/latest/curfirmwareversion.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ release. It is used by the android app for forcing software updates. Do not ed
Generated by bin/buildall.sh -->

<resources>
<string name="cur_firmware_version">0.1.0</string>
<string name="cur_firmware_version">0.1.3</string>
</resources>
30 changes: 20 additions & 10 deletions src/sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#ifdef T_BEAM_V10
#include "axp20x.h"
extern AXP20X_Class axp;
#endif
#endif

// deep sleep support
RTC_DATA_ATTR int bootCount = 0;
Expand All @@ -28,8 +28,6 @@ esp_sleep_source_t wakeCause; // the reason we booted this time
#define xstr(s) str(s)
#define str(s) #s



// -----------------------------------------------------------------------------
// Application
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -63,7 +61,7 @@ void setLed(bool ledOn)

void setGPSPower(bool on)
{
DEBUG_MSG("Setting GPS power=%d\n", on);
DEBUG_MSG("Setting GPS power=%d\n", on);

#ifdef T_BEAM_V10
if (axp192_found)
Expand All @@ -84,9 +82,24 @@ void initDeepSleep()
wakeButtons = ((uint64_t)1) << buttons.gpios[0];
*/

DEBUG_MSG("booted, wake cause %d (boot count %d)\n", wakeCause, bootCount);
}
// If we booted because our timer ran out or the user pressed reset, send those as fake events
const char *reason = "reset"; // our best guess
RESET_REASON hwReason = rtc_get_reset_reason(0);

if (hwReason == RTCWDT_BROWN_OUT_RESET)
reason = "brownout";

if (hwReason == TG0WDT_SYS_RESET)
reason = "taskWatchdog";

if (hwReason == TG1WDT_SYS_RESET)
reason = "intWatchdog";

if (wakeCause == ESP_SLEEP_WAKEUP_TIMER)
reason = "timeout";

DEBUG_MSG("booted, wake cause %d (boot count %d), reset_reason=%s\n", wakeCause, bootCount, reason);
}

void doDeepSleep(uint64_t msecToWake)
{
Expand Down Expand Up @@ -175,9 +188,6 @@ void doDeepSleep(uint64_t msecToWake)
esp_deep_sleep_start(); // TBD mA sleep current (battery)
}




/**
* enter light sleep (preserves ram but stops everything about CPU).
*
Expand All @@ -188,7 +198,7 @@ esp_sleep_wakeup_cause_t doLightSleep(uint64_t sleepMsec) // FIXME, use a more r
//DEBUG_MSG("Enter light sleep\n");
uint64_t sleepUsec = sleepMsec * 1000LL;

Serial.flush(); // send all our characters before we stop cpu clock
Serial.flush(); // send all our characters before we stop cpu clock
setBluetoothEnable(false); // has to be off before calling light sleep

// NOTE! ESP docs say we must disable bluetooth and wifi before light sleep
Expand Down

0 comments on commit f87cb00

Please sign in to comment.