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:
69
main/ui/apps/travel/ui/main_handler.h
Normal file
69
main/ui/apps/travel/ui/main_handler.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include "ui/apps/travel/ui/main.h"
|
||||
#include "ui/apps/travel/settings/settings_handler.h"
|
||||
#include "ui/interaction_handler.h"
|
||||
#include "external/mtr/mtr.h"
|
||||
#include "network/network.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "esp_err.h"
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
namespace travel {
|
||||
|
||||
/**
|
||||
* @brief Main UI Handler for Travel app
|
||||
*
|
||||
* Manages the MainUI instance, polling task, and MTR API interactions.
|
||||
* Runs a background task to periodically fetch arrival data.
|
||||
*/
|
||||
class MainUIHandler {
|
||||
public:
|
||||
// Callback type for settings button
|
||||
using SettingsButtonCallback = void (*)(void* user_data);
|
||||
|
||||
MainUIHandler();
|
||||
~MainUIHandler();
|
||||
|
||||
esp_err_t init(
|
||||
lv_obj_t* parent,
|
||||
InteractionHandler* interaction_handler,
|
||||
SettingHandler* setting_handler,
|
||||
NetworkHandler* network_handler
|
||||
);
|
||||
esp_err_t deinit();
|
||||
|
||||
void register_on_settings_button_clicked(SettingsButtonCallback cb, void* user_data);
|
||||
void force_refresh();
|
||||
|
||||
private:
|
||||
static void polling_task_(void* param);
|
||||
static void on_settings_button_clicked_static_(lv_event_t* e);
|
||||
|
||||
void on_settings_button_clicked_();
|
||||
void fetch_and_update_arrivals_();
|
||||
std::string format_arrival_time_(const std::string& api_time);
|
||||
std::string get_current_time_string_();
|
||||
|
||||
std::unique_ptr<MainUI> main_ui_;
|
||||
SettingHandler* setting_handler_ = nullptr;
|
||||
NetworkHandler* network_handler_ = nullptr;
|
||||
std::unique_ptr<MTRNextTrainHandler> mtr_handler_;
|
||||
|
||||
// Polling task
|
||||
TaskHandle_t polling_task_handle_ = nullptr;
|
||||
std::atomic<bool> polling_running_{false};
|
||||
SemaphoreHandle_t refresh_mutex_ = nullptr;
|
||||
|
||||
// Callback for settings button
|
||||
SettingsButtonCallback on_settings_callback_ = nullptr;
|
||||
void* settings_callback_user_data_ = nullptr;
|
||||
|
||||
static constexpr uint32_t LVGL_LOCK_TIMEOUT_MS = 4000;
|
||||
};
|
||||
|
||||
} // namespace travel
|
||||
Reference in New Issue
Block a user