#ifndef STATE_TRACKING_H #define STATE_TRACKING_H #include #include "esp_vfs_fat.h" /// @brief An event that represents the physical bomb state moving. struct EventCB { // The name of the event. // This should not contain whitespace or the characters ':', ',' const char* name; // An optional callback function for recreating the state. // Arguments are "ticks" and the serialized argument void (*replay_callback)(uint32_t, const char*); }; /// @brief Registers a callback for a certain event to be called on replay. /// @param name The name of the event to respond to. /// @param replay_callback A function to call to playback this state transition. void register_event_cb(const char* name, void (*replay_callback)(uint32_t, const char*)); // TODO: add one for generically responding to all events. /// @brief Call this to indicate that the bomb state has transitioned. /// @param name The name of the event that has occured. /// @param arg The serialized data associated with the event. /// This must not contain newline characters such as '\n' or '\r' void event_occured(const char* name, const char* arg); /// @brief Sets the recording source. /// @param stream The stream to record to. /// @param should_close whether or not the stream should be closed when finished. /// @return true if the source was updated. bool set_recording_source(FILE* stream, bool should_close); /// @brief Sets the playback source. /// @param stream The stream to playback from. /// @param should_close whether or not the stream should be closed when finished. /// @return true if the source was updated. bool set_playback_source(FILE* stream, bool should_close); /// @brief Starts recording to the stream specified by `set_recording_source()`. /// @return true if starting recording is successful. bool start_recording(); /// @brief Stops recording the state. /// @return true if stopping the recording is successful. bool stop_recording(); /// @brief Starts playing back the recording specified by `set_playback_source()`. /// @return true if starting playback is successful. bool start_playback(); /// @brief Stops playing back the recording. /// @return true if stopping the playback is successful. bool stop_playback(); /// @brief Gets weather or not we are tracking the state /// This can be helpful to conditionally do extra computation only /// when we are tracking the state. /// @return bool is_state_tracking(); #endif /* STATE_TRACKING_H */