/** * @file Config.h * @brief Configuration management for the Locomotive Test Bench * * This module handles persistent storage of system settings * using ESP32's Preferences library (NVS - Non-Volatile Storage). * * @author Locomotive Test Bench Project * @date 2025 */ #ifndef CONFIG_H #define CONFIG_H #include #include /** * @struct SystemConfig * @brief System operation configuration * * Stores current control mode and locomotive parameters. */ struct SystemConfig { bool isDCCMode; ///< True = DCC digital, False = DC analog bool is3Rail; ///< True = 3-rail mode, False = 2-rail mode bool powerOn; ///< True = power enabled, False = power off uint16_t dccAddress; ///< DCC locomotive address (1-10239) uint8_t speed; ///< Speed setting (0-100%) uint8_t direction; ///< Direction: 0 = reverse, 1 = forward uint32_t dccFunctions; ///< Bit field for DCC functions F0-F28 }; /** * @class Config * @brief Configuration manager with persistent storage * * Manages all configuration parameters and provides persistent * storage using ESP32's NVS (Non-Volatile Storage) via Preferences. * * @note All settings are automatically saved to flash memory * and persist across reboots. */ class Config { public: /** * @brief Constructor - initializes with default values */ Config(); /** * @brief Initialize preferences and load saved settings * * Must be called during setup() before using configuration. * Loads previously saved settings from NVS. */ void begin(); /** * @brief Save current configuration to NVS * * Writes all system settings to persistent storage. * Should be called after any configuration changes. */ void save(); /** * @brief Load configuration from NVS * * Reads previously saved settings. Called automatically * by begin(), but can be called manually to reload. */ void load(); /** * @brief Reset all settings to defaults * * Clears all stored preferences and resets to factory defaults. * Use with caution - all saved settings will be lost. */ void reset(); SystemConfig system; ///< System operation settings private: Preferences preferences; ///< ESP32 NVS preferences object }; #endif // CONFIG_H #endif