117 lines
3.4 KiB
C++
117 lines
3.4 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
#include <vector>
|
|
|
|
// Forward declarations
|
|
class BehaviorManager;
|
|
class VisemeBehavior;
|
|
class FocusBehavior;
|
|
|
|
// ============================================================================
|
|
// Config Key-Value System
|
|
// ============================================================================
|
|
|
|
enum ConfigKey : uint16_t {
|
|
// Basic settings
|
|
KEY_DEVICE_NAME = 0x0001,
|
|
KEY_FIRMWARE_MAJOR = 0x0002,
|
|
KEY_FIRMWARE_MINOR = 0x0003,
|
|
|
|
// Motor array (single entry containing all motors)
|
|
KEY_MOTOR_ARRAY = 0x0100,
|
|
|
|
// Behavior states (array of behaviorID + enabled pairs)
|
|
KEY_BEHAVIOR_STATES = 0x0200,
|
|
|
|
// Viseme array (single entry containing all visemes)
|
|
KEY_VISEME_ARRAY = 0x0300,
|
|
|
|
// Focus behavior settings
|
|
KEY_FOCUS_SETTINGS = 0x0500,
|
|
|
|
// WiFi / WebSocket settings
|
|
KEY_WIFI_SETTINGS = 0x0600,
|
|
|
|
// Future extensible settings
|
|
KEY_SERIAL_BAUD = 0x0400,
|
|
KEY_MOTOR_UPDATE_INTERVAL = 0x0401,
|
|
// ... add more as needed
|
|
};
|
|
|
|
enum ConfigType : uint8_t {
|
|
TYPE_UINT8 = 0x01,
|
|
TYPE_UINT16 = 0x02,
|
|
TYPE_UINT32 = 0x03,
|
|
TYPE_BOOL = 0x04,
|
|
TYPE_INT8 = 0x05,
|
|
TYPE_INT16 = 0x06,
|
|
TYPE_INT32 = 0x07,
|
|
TYPE_FLOAT = 0x08,
|
|
TYPE_STRING = 0x09,
|
|
TYPE_MOTOR_ARRAY = 0x0A, // Special type for motor array
|
|
TYPE_BEHAVIOR_STATES = 0x0B, // Special type for behavior state array
|
|
TYPE_VISEME_ARRAY = 0x0C, // Special type for viseme array
|
|
TYPE_FOCUS_SETTINGS = 0x0D, // Focus behavior settings blob
|
|
TYPE_WIFI_SETTINGS = 0x0E, // WiFi/WebSocket settings blob
|
|
};
|
|
|
|
struct FirmwareVersion {
|
|
uint8_t major;
|
|
uint8_t minor;
|
|
};
|
|
|
|
struct ServoModel {
|
|
uint8_t major;
|
|
uint8_t minor;
|
|
};
|
|
|
|
struct Motor {
|
|
String name;
|
|
uint8_t motorID;
|
|
ServoModel servoModel;
|
|
uint16_t position;
|
|
uint16_t current = 0;
|
|
bool isEnabled = true;
|
|
};
|
|
|
|
struct RobotConfig {
|
|
String deviceName;
|
|
FirmwareVersion firmwareVersion;
|
|
std::vector<Motor> motors;
|
|
|
|
uint16_t getMotorPosition(uint8_t motorID) const;
|
|
uint16_t getMotorCurrent(uint8_t motorID) const;
|
|
uint8_t getMotorModel(uint8_t motorID);
|
|
bool setMotorPosition(uint8_t motorID, uint16_t newPosition);
|
|
bool setMotorCurrent(uint8_t motorID, uint16_t newCurrent);
|
|
bool setMotorEnabled(uint8_t motorID, bool enable);
|
|
bool isMotorEnabled(uint8_t motorID);
|
|
void enableAllMotors();
|
|
String serializeJSON() const;
|
|
std::vector<uint8_t> serializeToBytes() const;
|
|
|
|
// Legacy format (v1)
|
|
bool saveToFFat(const char* path = "/robot_config.bin") const;
|
|
bool loadFromFFat(const char* path = "/robot_config.bin");
|
|
|
|
// New key-value format (v2)
|
|
bool saveToFFatV2(const char* path = "/robot_config.bin",
|
|
BehaviorManager* behaviorManager = nullptr,
|
|
VisemeBehavior* visemeBehavior = nullptr,
|
|
FocusBehavior* focusBehavior = nullptr) const;
|
|
bool loadFromFFatV2(const char* path = "/robot_config.bin",
|
|
BehaviorManager* behaviorManager = nullptr,
|
|
VisemeBehavior* visemeBehavior = nullptr,
|
|
FocusBehavior* focusBehavior = nullptr);
|
|
|
|
// New version with behavior/viseme support
|
|
bool loadOrCreateDefault(const char* path = "/robot_config.bin",
|
|
BehaviorManager* behaviorManager = nullptr,
|
|
VisemeBehavior* visemeBehavior = nullptr,
|
|
FocusBehavior* focusBehavior = nullptr);
|
|
|
|
// Legacy version (for backward compatibility)
|
|
bool loadOrCreateDefault(const char* path);
|
|
|
|
};
|