Fix some runtime issues
This commit is contained in:
parent
bbdcd9b5ec
commit
b1ae5dcd48
@ -34,10 +34,10 @@ struct Context
|
||||
Context& operator=(const Context&) = delete;
|
||||
Context& operator=(Context&&) = delete;
|
||||
|
||||
static Context& getContext()
|
||||
static Context* getContext()
|
||||
{
|
||||
static Context ctx;
|
||||
return ctx;
|
||||
return &ctx;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -48,7 +48,7 @@ void wifiEventHandler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
static int retry_num = 0;
|
||||
auto* ctx = static_cast<Context*>(event_data);
|
||||
auto* ctx = Context::getContext();
|
||||
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
|
||||
{
|
||||
@ -73,14 +73,14 @@ void wifiEventHandler(void* arg, esp_event_base_t event_base,
|
||||
auto* event = static_cast<ip_event_got_ip_t*>(event_data);
|
||||
ESP_LOGI(TAG, "Connected to AP. Got IP: " IPSTR, IP2STR(&event->ip_info.ip));
|
||||
retry_num = 0;
|
||||
|
||||
ESP_LOGI(TAG, "FOLLOW: Events: %p, context: %p", ctx->events, ctx);
|
||||
ctx->events->setEvent(clock_core::EventGroup::WIFI_CONNECTED);
|
||||
}
|
||||
}
|
||||
|
||||
void sntpEventHandler(struct timeval*)
|
||||
{
|
||||
Context::getContext().events->setEvent(clock_core::EventGroup::SNTP_SYNCED);
|
||||
Context::getContext()->events->setEvent(clock_core::EventGroup::SNTP_SYNCED);
|
||||
}
|
||||
|
||||
void timerEventHandler(TimerHandle_t timer)
|
||||
@ -118,12 +118,12 @@ std::expected<void, esp_err_t> wifiInitialize(const char* wifi_ssid, const char*
|
||||
TRY_ESP(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&wifiEventHandler,
|
||||
&(Context::getContext()),
|
||||
Context::getContext(),
|
||||
&instance_any_id));
|
||||
TRY_ESP(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&wifiEventHandler,
|
||||
&(Context::getContext()),
|
||||
Context::getContext(),
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_sta_config_t sta_config;
|
||||
@ -165,12 +165,13 @@ namespace clock_core
|
||||
void run(const char* wifi_ssid, const char* wifi_password)
|
||||
{
|
||||
EventGroup events;
|
||||
Context::getContext().events = &events;
|
||||
Context::getContext()->events = &events;
|
||||
ESP_LOGI(TAG, "INITIAL: Events: %p, context: %p", &events, Context::getContext());
|
||||
|
||||
auto clock_timer = xTimerCreate("clock_core",
|
||||
pdMS_TO_TICKS(60'000),
|
||||
pdTRUE,
|
||||
&Context::getContext(),
|
||||
Context::getContext(),
|
||||
timerEventHandler);
|
||||
|
||||
if (const auto res = wifiInitialize(wifi_ssid, wifi_password);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user