feat: Implement Discord app UI and settings management
- Added MainUI class for displaying voice state, status icon, and buttons. - Introduced MainUIHandler to manage UI interactions and bridge communication. - Created SettingsUI for displaying QR code and configuration instructions. - Implemented SettingsUIHandler to manage settings and web server interactions. - Developed WebHandler for handling HTTP requests for settings configuration. - Updated AppRegistry to initialize with the new Discord app descriptor. - Enhanced InteractionHandler to support keyboard interactions across app switches. - Updated UIHandler to manage app switching and rendering of app icons. - Enabled QR code support in LVGL configuration.
This commit is contained in:
52
main/ui/apps/iotdis/settings/settings_handler.cpp
Normal file
52
main/ui/apps/iotdis/settings/settings_handler.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "ui/apps/iotdis/settings/settings_handler.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
|
||||
#define TAG "SettingHandler"
|
||||
|
||||
void SettingHandler::load_settings() {
|
||||
remote_ip_ = storage_->get(NVS_KEY_IP);
|
||||
std::string port_str = storage_->get(NVS_KEY_PORT);
|
||||
std::string local_port_str = storage_->get(NVS_KEY_LOCAL_PORT);
|
||||
|
||||
if (!remote_ip_.empty() && !port_str.empty()) {
|
||||
remote_port_ = static_cast<uint16_t>(atoi(port_str.c_str()));
|
||||
|
||||
// Load local port, default to DEFAULT_LOCAL_PORT if not configured
|
||||
if (!local_port_str.empty()) {
|
||||
local_port_ = static_cast<uint16_t>(atoi(local_port_str.c_str()));
|
||||
} else {
|
||||
local_port_ = DEFAULT_LOCAL_PORT;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Loaded settings: %s:%u (local port: %u)", remote_ip_.c_str(), remote_port_, local_port_);
|
||||
} else {
|
||||
local_port_ = DEFAULT_LOCAL_PORT;
|
||||
ESP_LOGI(TAG, "No settings found, user setup required");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SettingHandler::save_settings(const std::string& ip, uint16_t port, uint16_t local_port) {
|
||||
if (ip.empty() || port == 0 || local_port == 0) {
|
||||
ESP_LOGW(TAG, "Cannot save: invalid settings");
|
||||
return;
|
||||
}
|
||||
|
||||
// Save to NVS
|
||||
storage_->put(NVS_KEY_IP, ip);
|
||||
char port_str[8];
|
||||
snprintf(port_str, sizeof(port_str), "%u", port);
|
||||
storage_->put(NVS_KEY_PORT, port_str);
|
||||
char local_port_str[8];
|
||||
snprintf(local_port_str, sizeof(local_port_str), "%u", local_port);
|
||||
storage_->put(NVS_KEY_LOCAL_PORT, local_port_str);
|
||||
|
||||
// Update local config
|
||||
remote_ip_ = ip;
|
||||
remote_port_ = port;
|
||||
local_port_ = local_port;
|
||||
|
||||
ESP_LOGI(TAG, "Settings saved: %s:%u (local port: %u)", remote_ip_.c_str(), remote_port_, local_port_);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user