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_);
|
||||
}
|
||||
|
||||
45
main/ui/apps/iotdis/settings/settings_handler.h
Normal file
45
main/ui/apps/iotdis/settings/settings_handler.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include "io/nvs_handler.h"
|
||||
|
||||
class SettingHandler {
|
||||
public:
|
||||
SettingHandler(std::unique_ptr<NVSStorageHandler> storage) :
|
||||
remote_ip_(""),
|
||||
remote_port_(0),
|
||||
local_port_(0),
|
||||
storage_(std::move(storage)) { }
|
||||
~SettingHandler() = default;
|
||||
|
||||
esp_err_t init(const EventGroupHandle_t& system_event_group) {
|
||||
storage_->init(system_event_group);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void load_settings();
|
||||
void save_settings(const std::string& ip, uint16_t port) {
|
||||
save_settings(ip, port, local_port_);
|
||||
}
|
||||
void save_settings(const std::string& ip, uint16_t port, uint16_t local_port);
|
||||
|
||||
bool is_configured() const { return !remote_ip_.empty() && remote_port_ != 0 && local_port_ != 0; }
|
||||
|
||||
std::string get_remote_ip() const { return remote_ip_; }
|
||||
uint16_t get_remote_port() const { return remote_port_; }
|
||||
uint16_t get_local_port() const { return local_port_; }
|
||||
|
||||
private:
|
||||
static constexpr uint16_t DEFAULT_LOCAL_PORT = 4212;
|
||||
|
||||
static constexpr const char* NVS_KEY_IP = "bridge_ip";
|
||||
static constexpr const char* NVS_KEY_PORT = "bridge_port";
|
||||
static constexpr const char* NVS_KEY_LOCAL_PORT = "local_port";
|
||||
|
||||
std::string remote_ip_;
|
||||
uint16_t remote_port_;
|
||||
uint16_t local_port_;
|
||||
std::unique_ptr<NVSStorageHandler> storage_;
|
||||
};
|
||||
Reference in New Issue
Block a user