#pragma once #include #include #include "protocol.h" #include "animation.h" #include "robotconfig.h" #include "motorcontrol.h" // ============================================================================ // Animation State // ============================================================================ struct AnimationState { Animation animation; Animation* current = nullptr; PlayMode playMode = PLAY_IDLE; uint8_t repeatsRemaining = 0; uint16_t startFrame = 0; // Frame to start playback from uint8_t playGeneration = 0; // Increments each time play() is called void play(PlayMode mode, uint8_t repeats = 0, uint16_t startFrame = 0); void stop(); }; extern AnimationState animState; // ============================================================================ // Motor Position Streaming State // ============================================================================ struct MotorStreamState { bool active = false; unsigned long lastStreamTime = 0; static constexpr unsigned long STREAM_INTERVAL_MS = 50; void start(); void stop(); bool shouldStream(); }; extern MotorStreamState motorStream; // ============================================================================ // Command Dispatcher // ============================================================================ // Process a received packet - call after receivePacket() returns true void dispatchCommand(); // ============================================================================ // Individual Command Handlers // ============================================================================ // Identity & Config void handleIdent(const uint8_t* payload, uint16_t len); void handleConfig(const uint8_t* payload, uint16_t len); // File Operations void handleFileList(const uint8_t* payload, uint16_t len); void handleFileLoad(const uint8_t* payload, uint16_t len); void handleFileSave(const uint8_t* payload, uint16_t len); void handleFileDelete(const uint8_t* payload, uint16_t len); void handleFilePlay(const uint8_t* payload, uint16_t len); void handleFileStop(const uint8_t* payload, uint16_t len); // Motor Control void handleMotorSet(const uint8_t* payload, uint16_t len); void handleMotorScan(const uint8_t* payload, uint16_t len); void handleMotorWrite(const uint8_t* payload, uint16_t len); void handleMotorStream(const uint8_t* payload, uint16_t len); // Behaviors void handleBehavior(const uint8_t* payload, uint16_t len); void handleBehaviorList(const uint8_t* payload, uint16_t len); // Visemes void handleVisemeList(const uint8_t* payload, uint16_t len); void handleVisemeAdd(const uint8_t* payload, uint16_t len); void handleVisemeDelete(const uint8_t* payload, uint16_t len); void handleVisemeSet(const uint8_t* payload, uint16_t len); void handleVisemeTrigger(const uint8_t* payload, uint16_t len); // Settings void handleSettingsSet(const uint8_t* payload, uint16_t len); // System void handleBootloader(const uint8_t* payload, uint16_t len); // ============================================================================ // Helper Functions // ============================================================================ // Send current motor positions void sendMotorPositions(); // Parse animation from payload and save to file bool parseAndSaveAnimation(const uint8_t* payload, uint16_t len, Animation& animation); // Delete a file void deleteFile(fs::FS& fs, const char* path);