From 0fb0ede21729852f3f13ed1f994b350d2452b6a0 Mon Sep 17 00:00:00 2001
From: Jan Grewe <jan@faked.org>
Date: Sat, 1 Aug 2020 02:39:44 +0200
Subject: [PATCH] more cleanup

---
 include/power.h |  3 ++-
 src/main.cpp    | 34 +---------------------------------
 src/power.cpp   | 36 +++++++++++++++++++++++++++++++++++-
 3 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/include/power.h b/include/power.h
index e5f434c..bad4546 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 02eb78c..1c67022 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 89e276f..8215256 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;
+    }
+}
-- 
GitLab