57 lines
2.1 KiB
C
57 lines
2.1 KiB
C
#ifndef STATE_TRACKING_H
|
|
#define STATE_TRACKING_H
|
|
|
|
#include <stdint.h>
|
|
#include "esp_vfs_fat.h"
|
|
|
|
/// @brief An event that represents the physical bomb state moving.
|
|
struct Event {
|
|
// 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 an event to be tracked.
|
|
/// @param name The name of the event that has occured.
|
|
/// @param replay_callback A function to call to recreate this state transition.
|
|
void register_event(const char* name, void (*replay_callback)(uint32_t, const char*));
|
|
|
|
/// @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();
|
|
|
|
#endif /* STATE_TRACKING_H */
|