// SPDX-License-Identifier: Apache-2.0 // Copyright (c) 2012-2024 Scott Penrose and WII5 Buoy contributors // // This file is part of WII5 Buoy firmware. // See LICENSE for full terms. /** * @file WII5ModeSleep.h * @brief Sleep mode: long sleeps between wake-ups; powers down the Maths CPU. */ #ifndef WII5ModeSleep_h #define WII5ModeSleep_h #include #include #include // TODO - Namespace these - e.g enum class ... enum WII5SLEEP_STEPS { WII5SLEEP_START, WII5SLEEP_WAIT, WII5SLEEP_SLEEPING, WII5SLEEP_BUTTONS, WII5SLEEP_UPDATE, WII5SLEEP_TIME, WII5SLEEP_COMMS, WII5SLEEP_FINISH }; /** * @brief Sleep mode: long sleeps between wake-ups. * * Computes how long to sleep until the next configured wake-up * (capture window, position update, etc.), powers down the Maths CPU * and other peripherals, and uses sh3dNodeUtil.sleep() to put the AVR * into deep sleep. */ class WII5ModeSleep : public WII5Mode { public: WII5ModeSleep() {} /** @brief Reset to WII5SLEEP_START. */ void reset(); /** @brief One-time bring-up. */ void begin(); /** @brief State-machine tick. */ void loop(); protected: bool first; WII5SLEEP_STEPS lastStep; elapsedMillis stepWait; elapsedMillis displayWait; WII5SLEEP_STEPS step; uint32_t sleepNextSeconds; // How long we going to sleep (cleared after sleep) }; extern WII5ModeSleep wii5ModeSleep; #endif