Refactor NVS and WiFi handlers for improved memory management and logging
- Updated KVStorageHandler interface to use std::string instead of char* for key-value operations. - Enhanced NVSStorageHandler to utilize ESP_LOG for error and info messages instead of printf. - Refactored WifiHandler to manage WiFi credentials using JSON format for better structure and storage. - Replaced raw pointers with std::unique_ptr in WifiHandler and NetworkHandler for automatic memory management. - Removed unused TouchHandler and EInkTouchHandler classes to clean up the codebase. - Adjusted CMakeLists.txt to remove unnecessary include directories. - Updated lv_conf.h to enable FreeRTOS and gesture recognition features.
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
#include "esp_wifi.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
#define WIFI_CONNECTED_BIT (1 << 0)
|
||||
#define WIFI_STARTED_BIT (1 << 0)
|
||||
#define WIFI_CONNECTED_BIT (1 << 1)
|
||||
|
||||
|
||||
class WifiHandler {
|
||||
public:
|
||||
@@ -11,16 +13,13 @@ public:
|
||||
// this handler is used to store/retrieve WiFi credentials
|
||||
// should have a unique namespace for WiFi credentials
|
||||
// it will be owned by WifiHandler and deleted in its destructor
|
||||
KVStorageHandler* kvs
|
||||
std::unique_ptr<KVStorageHandler> kvs
|
||||
);
|
||||
~WifiHandler();
|
||||
|
||||
// move semantics
|
||||
WifiHandler(WifiHandler&& other) noexcept;
|
||||
|
||||
void init();
|
||||
esp_err_t connect(const char* ssid, const char* password);
|
||||
esp_err_t connect(const char* ssid); // connect using stored password
|
||||
esp_err_t init();
|
||||
esp_err_t connect(const std::string& ssid, const std::string& password);
|
||||
esp_err_t connect(const std::string& ssid); // connect using stored password
|
||||
esp_err_t reconnect(); // reconnect to current SSID
|
||||
void disconnect();
|
||||
EventBits_t wait_for_connection(TickType_t ticks_to_wait);
|
||||
@@ -37,17 +36,21 @@ private:
|
||||
// prevent copying
|
||||
WifiHandler(const WifiHandler&) = delete;
|
||||
WifiHandler& operator=(const WifiHandler&) = delete;
|
||||
// prevent moving
|
||||
WifiHandler(WifiHandler&& other) = delete;
|
||||
WifiHandler& operator=(WifiHandler&& other) = delete;
|
||||
|
||||
char* build_password_key(const char* ssid);
|
||||
void get_wifi_credentials(char*& ssid, char*& password);
|
||||
void store_wifi_credentials(const std::string& ssid, const std::string& password);
|
||||
void get_wifi_credentials(std::string& out_ssid, std::string& out_password);
|
||||
|
||||
bool initialized = false;
|
||||
KVStorageHandler* kvs = nullptr;
|
||||
std::unique_ptr<KVStorageHandler> kvs = nullptr;
|
||||
EventGroupHandle_t s_wifi_event_group = 0;
|
||||
SemaphoreHandle_t scan_mutex = nullptr;
|
||||
SemaphoreHandle_t connection_mutex = nullptr;
|
||||
SemaphoreHandle_t credential_mutex = nullptr;
|
||||
// current connected / preferred SSID
|
||||
char* current_ssid = nullptr;
|
||||
std::string current_ssid;
|
||||
// prevent auto-reconnect on expected disconnection, e.g. when user calls disconnect()
|
||||
// should be reset to false after connect()
|
||||
bool expect_disconnected = false;
|
||||
|
||||
Reference in New Issue
Block a user