#pragma once #include #include #include #include class PowerController { public: enum class PowerState { ACTIVE, LIGHT_SLEEP, DEEP_SLEEP, SHUTDOWN }; static PowerController& Instance() { static PowerController instance; return instance; } void SetState(PowerState newState) { std::lock_guard lock(mutex_); if (currentState_ != newState) { ESP_LOGI("PowerCtrl", "State change: %d -> %d", static_cast(currentState_), static_cast(newState)); currentState_ = newState; if (stateChangeCallback_) { stateChangeCallback_(newState); } } } PowerState GetState() const { std::lock_guard lock(mutex_); return currentState_; } void OnStateChange(std::function callback) { stateChangeCallback_ = callback; } private: PowerController() = default; ~PowerController() = default; PowerState currentState_ = PowerState::ACTIVE; std::function stateChangeCallback_; mutable std::mutex mutex_; };