2024-10-29 00:22:29 +08:00
|
|
|
#ifndef WIFI_BOARD_H
|
|
|
|
|
#define WIFI_BOARD_H
|
|
|
|
|
|
2024-11-05 20:15:00 +08:00
|
|
|
#include "board.h"
|
2025-12-09 09:24:56 +08:00
|
|
|
#include <freertos/FreeRTOS.h>
|
|
|
|
|
#include <freertos/event_groups.h>
|
|
|
|
|
#include <esp_timer.h>
|
2024-10-29 00:22:29 +08:00
|
|
|
|
|
|
|
|
class WifiBoard : public Board {
|
|
|
|
|
protected:
|
2025-12-09 09:24:56 +08:00
|
|
|
esp_timer_handle_t connect_timer_ = nullptr;
|
|
|
|
|
bool in_config_mode_ = false;
|
|
|
|
|
NetworkEventCallback network_event_callback_ = nullptr;
|
|
|
|
|
|
2024-11-03 05:54:15 +08:00
|
|
|
virtual std::string GetBoardJson() override;
|
|
|
|
|
|
2025-12-09 09:24:56 +08:00
|
|
|
/**
|
|
|
|
|
* Handle network event (called from WiFi manager callbacks)
|
|
|
|
|
* @param event The network event type
|
|
|
|
|
* @param data Additional data (e.g., SSID for Connecting/Connected events)
|
|
|
|
|
*/
|
|
|
|
|
void OnNetworkEvent(NetworkEvent event, const std::string& data = "");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start WiFi connection attempt
|
|
|
|
|
*/
|
|
|
|
|
void TryWifiConnect();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enter WiFi configuration mode
|
|
|
|
|
*/
|
|
|
|
|
void StartWifiConfigMode();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* WiFi connection timeout callback
|
|
|
|
|
*/
|
|
|
|
|
static void OnWifiConnectTimeout(void* arg);
|
|
|
|
|
|
2024-10-29 00:22:29 +08:00
|
|
|
public:
|
2025-05-07 02:33:38 +08:00
|
|
|
WifiBoard();
|
2025-12-09 09:24:56 +08:00
|
|
|
virtual ~WifiBoard();
|
|
|
|
|
|
2025-02-04 14:24:51 +08:00
|
|
|
virtual std::string GetBoardType() override;
|
2025-12-09 09:24:56 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Start network connection asynchronously
|
|
|
|
|
* This function returns immediately. Network events are notified through the callback set by SetNetworkEventCallback().
|
|
|
|
|
*/
|
2024-11-01 14:26:02 +08:00
|
|
|
virtual void StartNetwork() override;
|
2025-12-09 09:24:56 +08:00
|
|
|
|
2025-07-17 20:18:21 +08:00
|
|
|
virtual NetworkInterface* GetNetwork() override;
|
2025-12-09 09:24:56 +08:00
|
|
|
virtual void SetNetworkEventCallback(NetworkEventCallback callback) override;
|
2024-11-18 06:17:39 +08:00
|
|
|
virtual const char* GetNetworkStateIcon() override;
|
2025-12-09 09:24:56 +08:00
|
|
|
virtual void SetPowerSaveLevel(PowerSaveLevel level) override;
|
2025-05-07 02:33:38 +08:00
|
|
|
virtual AudioCodec* GetAudioCodec() override { return nullptr; }
|
2025-05-22 19:19:36 +08:00
|
|
|
virtual std::string GetDeviceStatusJson() override;
|
2025-12-09 09:24:56 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Enter WiFi configuration mode (thread-safe, can be called from any task)
|
|
|
|
|
*/
|
|
|
|
|
void EnterWifiConfigMode();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if in WiFi config mode
|
|
|
|
|
*/
|
|
|
|
|
bool IsInWifiConfigMode() const;
|
2024-10-29 00:22:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // WIFI_BOARD_H
|