Files
ink-board/main/ui/apps/iotdis/bridge/bridge.h
GW_MC e467951b8c 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.
2026-02-02 20:47:27 +08:00

68 lines
1.6 KiB
C++

#pragma once
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "ui/apps/iotdis/settings/settings_handler.h"
#include <string>
#include <cstdint>
#include <memory>
#include "esp_err.h"
#include "network/udp_client.h"
struct StatusUpdateEventData {
enum class VoiceState {
UNKNOWN,
MUTED,
UNMUTED,
ERROR
} state;
};
using StatusEventCallback = void(*)(StatusUpdateEventData, void*);
class IotDisBridge {
public:
IotDisBridge(
SettingHandler* setting_handler
) : setting_handler_(setting_handler) { }
~IotDisBridge();
void start_polling_task();
void stop_polling_task();
esp_err_t send_mute_command();
bool test_connection(const std::string& ip, uint16_t port) {
return test_connection(ip, port, setting_handler_->get_local_port());
}
bool test_connection(const std::string& ip, uint16_t port, uint16_t local_port);
void register_on_status_update_callback(
StatusEventCallback callback,
void* status_event_user_data
) {
on_status_update_callback_ = callback;
status_event_user_data_ = status_event_user_data;
}
private:
static constexpr int POLL_INTERVAL_MS = 2000;
static constexpr int ERROR_POLL_INTERVAL_MS = 5000;
static constexpr int RESPONSE_TIMEOUT_MS = 1000;
static constexpr int MAX_FAILURES_BEFORE_ERROR = 3;
void poll_status_();
// Polling task
static void poll_task_(void* param);
TaskHandle_t poll_task_handle_ = nullptr;
bool stop_polling_ = false;
int consecutive_failures_ = 0;
SettingHandler* setting_handler_ = nullptr;
UDPClient udp_client_;
StatusEventCallback on_status_update_callback_ = nullptr;
void* status_event_user_data_ = nullptr;
};