feat(travel): Implement settings UI and web server for MTR route configuration
- Added MainUIHandler class to manage the main UI and polling for arrival data. - Introduced SettingsUI class for displaying QR code and configuration options. - Created SettingsUIHandler to manage settings UI lifecycle and web server interactions. - Developed WebHandler to handle HTTP requests for MTR route settings, including adding and removing routes. - Implemented web endpoints for fetching MTR lines, routes, and saving settings. - Enhanced UI with responsive design for e-ink displays and added error handling for web interactions.
This commit is contained in:
58
main/ui/apps/travel/settings/settings_handler.h
Normal file
58
main/ui/apps/travel/settings/settings_handler.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#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<NVSStorageHandler> 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<RoutePair>& 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<RoutePair> routes_;
|
||||
uint32_t polling_interval_sec_ = DEFAULT_POLLING_INTERVAL;
|
||||
std::unique_ptr<NVSStorageHandler> storage_;
|
||||
|
||||
// JSON serialization helpers
|
||||
std::string routes_to_json() const;
|
||||
void routes_from_json(const std::string& json);
|
||||
};
|
||||
|
||||
} // namespace travel
|
||||
Reference in New Issue
Block a user