// 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 WII5ModeCapture.h * @brief Capture mode: IMU/wave-motion data capture and SD logging. */ #ifndef WII5ModeCapture_h #define WII5ModeCapture_h #include #include #include enum WII5CAPTURE_TYPE { WII5CAPTURETYPE_UNKNOWN, WII5CAPTURETYPE_MANUAL, WII5CAPTURETYPE_TIME, }; enum WII5CAPTURE_STEPS { WII5CAPTURE_START, WII5CAPTURE_OFF, WII5CAPTURE_TIME, WII5CAPTURE_PREPARE, WII5CAPTURE_PREPARE_SD, WII5CAPTURE_PREPARE_COMMS, WII5CAPTURE_PREPARE_ID, WII5CAPTURE_PREPARE_SPARTON, WII5CAPTURE_WAIT, WII5CAPTURE_INPROGRESS, WII5CAPTURE_SHUTDOWN, WII5CAPTURE_PROCESS, WII5CAPTURE_SEND_PREPARE, WII5CAPTURE_SEND_METADATA, WII5CAPTURE_SEND_RAW, WII5CAPTURE_CANCEL_RESTART, WII5CAPTURE_CANCEL_OFF, WII5CAPTURE_MANUAL_OFF, WII5CAPTURE_WAIT5_OFF, WII5CAPTURE_FLIP, WII5CAPTURE_WAIT_COMMS_MATHS, WII5CAPTURE_FINISH }; /** * @brief Capture mode: time-driven IMU data capture and SD logging. * * Drives the WII5CAPTURE_STEPS state machine: prepare SD + comms + IMU, * wait for the start time, run the capture, write metadata and * processed-results blocks, optionally flip SD cards, then idle until * the next capture window. */ class WII5ModeCapture : public WII5Mode { public: WII5ModeCapture() {} /** @brief Reset to WII5CAPTURE_START. */ void reset(); /** @brief One-time bring-up. */ void begin(); /** @brief State-machine tick. */ void loop(); /** @brief Begin a manual capture. */ void start(bool force = false); /** @brief Abort the current capture. */ void stop(bool force = false); bool enableAtFile; bool enableGPS; bool enableMaths; bool enableComms; bool enableLiveSwap; /** @brief Switch the active SD card to the alternate one. */ void flip(); uint32_t startTime; protected: elapsedMillis wait; time_t captureStart; WII5CAPTURE_TYPE captureType; WII5CAPTURE_STEPS step; WII5CAPTURE_STEPS stepLast; uint32_t stepCount; uint32_t stepTotal; uint8_t retry; uint32_t minutes; // since midnight. uint32_t period; uint32_t remaining; bool debug; }; extern WII5ModeCapture wii5ModeCapture; #endif