#pragma once #include #include #include class PowerSaveTimer { public: PowerSaveTimer(int cpu_max_freq, int seconds_to_sleep = 20, int seconds_to_shutdown = -1); ~PowerSaveTimer(); void SetEnabled(bool enabled); void OnEnterSleepMode(std::function callback); void OnExitSleepMode(std::function callback); void OnShutdownRequest(std::function callback); void WakeUp(); private: void PowerSaveCheck(); esp_timer_handle_t power_save_timer_ = nullptr; bool enabled_ = false; bool in_sleep_mode_ = false; int ticks_ = 0; int cpu_max_freq_; int seconds_to_sleep_; int seconds_to_shutdown_; std::function on_enter_sleep_mode_; std::function on_exit_sleep_mode_; std::function on_shutdown_request_; };