From b1ae5dcd489e2d58005cce85504f8f80f6f6b93c Mon Sep 17 00:00:00 2001 From: Erki Date: Fri, 16 Feb 2024 17:14:21 +0200 Subject: [PATCH] Fix some runtime issues --- firmware/main/clock_core.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/firmware/main/clock_core.cpp b/firmware/main/clock_core.cpp index ec888f5..570283a 100644 --- a/firmware/main/clock_core.cpp +++ b/firmware/main/clock_core.cpp @@ -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(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(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 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);