#pragma once #include "freertos/FreeRTOS.h" #include #include #include #include "io/nvs_handler.h" #include "ui/apps/travel/types.h" namespace travel { /** * @brief Settings handler for Travel app * * Manages NVS persistence of route pairs and polling interval. */ class SettingHandler { public: explicit SettingHandler(std::unique_ptr storage); ~SettingHandler() = default; esp_err_t init(const EventGroupHandle_t& system_event_group); void load_settings(); void save_settings(); bool is_configured() const { return !routes_.empty(); } // Route management void add_route(const RoutePair& route); void remove_route(size_t index); void clear_routes(); const std::vector& get_routes() const { return routes_; } size_t get_route_count() const { return routes_.size(); } // Polling interval (seconds) uint32_t get_polling_interval() const { return polling_interval_sec_; } void set_polling_interval(uint32_t seconds); static constexpr size_t MAX_ROUTES = 5; static constexpr uint32_t DEFAULT_POLLING_INTERVAL = 30; static constexpr uint32_t MIN_POLLING_INTERVAL = 10; static constexpr uint32_t MAX_POLLING_INTERVAL = 120; private: static constexpr const char* NVS_KEY_ROUTES = "routes"; static constexpr const char* NVS_KEY_POLLING = "poll_interval"; std::vector routes_; uint32_t polling_interval_sec_ = DEFAULT_POLLING_INTERVAL; std::unique_ptr storage_; // JSON serialization helpers std::string routes_to_json() const; void routes_from_json(const std::string& json); }; } // namespace travel