From 9f3c929fcd48fa26db1a1311e3f4864dde0faa09 Mon Sep 17 00:00:00 2001 From: Thomas Schmid Date: Sun, 26 Jun 2022 00:24:44 +0200 Subject: [PATCH] update main app handling to include an off state Signed-off-by: Thomas Schmid --- firmware/src/main.cpp | 57 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index 683f862..8463305 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -22,25 +22,72 @@ std::vector> apps = { std::ref(fackel_app) }; +<<<<<<< HEAD unsigned int current_app = 1; unsigned int next_app; +======= +static unsigned int current_app = 0; +static unsigned int next_app; +static bool init_successfull = false; +static bool sleep_active=false; + +void switch_app() { + if (!sleep_active) { + next_app = current_app + 1; + } else { + sleep_active = false; + next_app = 0; + } + + if (next_app >= apps.size()) { + next_app = 0; + // Turn off leds before going to sleep + fadeToBlackBy(leds, NUM_LEDS, 0xFF); + FastLED.show(); + + //configure wakeup source + esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, 1); + + //bedtime + sleep_active = true; + esp_deep_sleep_start(); + } + + next_app = next_app % apps.size(); +} +>>>>>>> update main app handling to include an off state void setup() { next_app = current_app; +<<<<<<< HEAD zauberstab_init(); //Serial.begin(115200); +======= + if (zauberstab_init() != 0) { + return; + } + Serial.begin(115200); +>>>>>>> update main app handling to include an off state + init_successfull = true; apps[current_app].get().init(); } void loop() { -/* EVERY_N_SECONDS(30) - { - next_app++; - next_app = next_app % apps.size(); - } */ + if (!init_successfull) { + return; + } + + if (acc_has_event()) { + String axes = myAcc.getActTapStatusAsString(); + byte intSource = myAcc.readAndClearInterrupts(); + + if (myAcc.checkInterrupt(intSource, ADXL345_DOUBLE_TAP)) { + switch_app(); + } + } if (next_app != current_app) {