diff --git a/include/power.h b/include/power.h index e5f434c31c1820a59017078faabb4284ef7d7def..bad45463911eefd7ee7accb33fbaec5f1d37a2c0 100644 --- a/include/power.h +++ b/include/power.h @@ -5,4 +5,5 @@ float powerGetBattVoltage(); void powerSetOutput(uint8_t channel, bool enabled); void powerStatus(); void powerSetup(); -void powerSleep(); \ No newline at end of file +void powerSleep(); +void powerBootInfo(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 02eb78c408d65f1543763a146ab3542035cee71c..1c67022aeb76893c5720e033b2604db8d2ce2171 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,7 +7,6 @@ #include <CayenneLPP.h> int state; -RTC_DATA_ATTR int bootCount = 0; CayenneLPP payload(55); void createPayload() @@ -27,42 +26,11 @@ void printPayload() { Serial.println("\n#########################\n"); } -static void bootInfo() -{ - ++bootCount; - Serial.printf("Boot number: %d\n", bootCount); - - esp_sleep_wakeup_cause_t wakeup_reason; - wakeup_reason = esp_sleep_get_wakeup_cause(); - - switch (wakeup_reason) - { - case ESP_SLEEP_WAKEUP_EXT0: - Serial.println("Wakeup caused by external signal using RTC_IO"); - break; - case ESP_SLEEP_WAKEUP_EXT1: - Serial.println("Wakeup caused by external signal using RTC_CNTL"); - break; - case ESP_SLEEP_WAKEUP_TIMER: - Serial.println("Wakeup caused by timer"); - break; - case ESP_SLEEP_WAKEUP_TOUCHPAD: - Serial.println("Wakeup caused by touchpad"); - break; - case ESP_SLEEP_WAKEUP_ULP: - Serial.println("Wakeup caused by ULP program"); - break; - default: - Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); - break; - } -} - void setup() { Serial.begin(115200); Wire.begin(21, 22); - bootInfo(); + powerBootInfo(); powerSetup(); gpsSetup(); loraSetup(); diff --git a/src/power.cpp b/src/power.cpp index 89e276fafa0d4cf4928cf2dc3fef67a50653a35a..821525630d9cd3318c8dda91409fc2570097d425 100644 --- a/src/power.cpp +++ b/src/power.cpp @@ -1,6 +1,8 @@ #include "config.h" #include <axp20x.h> +RTC_DATA_ATTR int bootCount = 0; + AXP20X_Class axp; void powerLed(axp_chgled_mode_t mode) @@ -83,4 +85,36 @@ void powerSleep() esp_sleep_enable_timer_wakeup(1000000 * SLEEP_SECONDS); Serial.println("\n### END ###"); esp_deep_sleep_start(); -} \ No newline at end of file +} + + +void powerBootInfo() +{ + ++bootCount; + Serial.printf("Boot number: %d\n", bootCount); + + esp_sleep_wakeup_cause_t wakeup_reason; + wakeup_reason = esp_sleep_get_wakeup_cause(); + + switch (wakeup_reason) + { + case ESP_SLEEP_WAKEUP_EXT0: + Serial.println("Wakeup caused by external signal using RTC_IO"); + break; + case ESP_SLEEP_WAKEUP_EXT1: + Serial.println("Wakeup caused by external signal using RTC_CNTL"); + break; + case ESP_SLEEP_WAKEUP_TIMER: + Serial.println("Wakeup caused by timer"); + break; + case ESP_SLEEP_WAKEUP_TOUCHPAD: + Serial.println("Wakeup caused by touchpad"); + break; + case ESP_SLEEP_WAKEUP_ULP: + Serial.println("Wakeup caused by ULP program"); + break; + default: + Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); + break; + } +}