From fd29b2b3d8f45ded63dc95c14f6af8534bb91ac4 Mon Sep 17 00:00:00 2001 From: Matti Airas Date: Wed, 2 Oct 2024 22:43:53 +0300 Subject: [PATCH] Fix event loop calls --- README.md | 2 +- examples/analog_input.cpp | 5 +--- examples/async_repeat_sensor.cpp | 7 ++--- examples/chain_counter.cpp | 5 +--- examples/constant_sensor.cpp | 5 +--- .../max6675_signalk.cpp | 5 +--- .../max6675_signalk_n2k.cpp | 5 +--- examples/freertos_tasks.cpp | 9 ++----- .../fuel_level_sensor_example.cpp | 7 +---- examples/hysteresis.cpp | 7 +---- examples/join_and_zip.cpp | 11 ++------ examples/lambda_transform.cpp | 7 +---- examples/manual_networking.cpp | 15 +++++------ .../milone_level_sensor.cpp | 9 ++----- examples/minimal_app.cpp | 15 ++++------- examples/raw_json.cpp | 10 ++----- examples/relay_control.cpp | 9 ++----- examples/repeat_sensor_analog_input.cpp | 7 +---- examples/repeat_transform.cpp | 13 +++------- examples/rpm_counter.cpp | 9 ++----- .../smart_switch/remote_switch_example.cpp | 7 +---- .../smart_switch/smart_switch_example.cpp | 9 ++----- examples/temperature_sender.cpp | 7 +---- examples/time_counter.cpp | 26 +++++++------------ .../controllers/smart_switch_controller.cpp | 2 +- src/sensesp/net/discovery.cpp | 2 +- src/sensesp/net/http_server.h | 2 +- src/sensesp/net/networking.cpp | 4 +-- src/sensesp/net/networking.h | 4 +-- src/sensesp/net/ota.h | 4 +-- src/sensesp/net/web/base_command_handler.cpp | 4 +-- src/sensesp/sensors/analog_input.cpp | 2 +- src/sensesp/sensors/constant_sensor.h | 7 ++--- src/sensesp/sensors/digital_input.h | 10 +++---- src/sensesp/sensors/system_info.h | 12 ++++----- src/sensesp/signalk/signalk_delta_queue.cpp | 2 +- src/sensesp/signalk/signalk_put_request.cpp | 4 +-- src/sensesp/signalk/signalk_ws_client.cpp | 4 +-- src/sensesp/signalk/signalk_ws_client.h | 4 +-- src/sensesp/system/async_response_handler.h | 6 ++--- src/sensesp/system/base_button.h | 2 +- src/sensesp/system/led_blinker.cpp | 16 ++++++------ src/sensesp/system/stream_producer.h | 4 +-- src/sensesp/system/task_queue_producer.h | 4 +-- src/sensesp/transforms/click_type.cpp | 6 ++--- src/sensesp/transforms/debounce.h | 6 ++--- src/sensesp/transforms/press_repeater.cpp | 2 +- src/sensesp/transforms/repeat.h | 18 ++++++------- src/sensesp_app_builder.h | 2 +- 49 files changed, 120 insertions(+), 224 deletions(-) diff --git a/README.md b/README.md index 852fb1dc3..77913217c 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ `sensesp_app->get_event_loop()`. For example: ```cpp - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( 1000, []() { Serial.println("Hello, world!"); } ); diff --git a/examples/analog_input.cpp b/examples/analog_input.cpp index ee8720d4d..980f3294d 100644 --- a/examples/analog_input.cpp +++ b/examples/analog_input.cpp @@ -88,8 +88,5 @@ void setup() { } void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/async_repeat_sensor.cpp b/examples/async_repeat_sensor.cpp index 070ad07f2..ae450fdc2 100644 --- a/examples/async_repeat_sensor.cpp +++ b/examples/async_repeat_sensor.cpp @@ -33,7 +33,7 @@ void setup() { auto digital_read_callback = [](RepeatSensor* sensor) { ESP_LOGI("Example", "Pretend to trigger an asynchronous measurement operation here."); - SensESPBaseApp::get_event_loop()->onDelay(1000, + event_loop()->onDelay(1000, [sensor]() { sensor->emit(digitalRead(kDigitalInputPin)); }); }; @@ -55,8 +55,5 @@ void setup() { } void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/chain_counter.cpp b/examples/chain_counter.cpp index f84b02839..d7e006069 100644 --- a/examples/chain_counter.cpp +++ b/examples/chain_counter.cpp @@ -147,8 +147,5 @@ void setup() { // The loop function is called in an endless loop during program execution. // It simply calls `app.tick()` which will then execute all events needed. void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/constant_sensor.cpp b/examples/constant_sensor.cpp index 336c3d3f7..2ad71f11d 100644 --- a/examples/constant_sensor.cpp +++ b/examples/constant_sensor.cpp @@ -36,8 +36,5 @@ void setup() { } void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/dual_thermocouple_sensors/max6675_signalk.cpp b/examples/dual_thermocouple_sensors/max6675_signalk.cpp index 4a8ab8f27..b1ff0570c 100644 --- a/examples/dual_thermocouple_sensors/max6675_signalk.cpp +++ b/examples/dual_thermocouple_sensors/max6675_signalk.cpp @@ -56,8 +56,5 @@ void setup() { } void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/dual_thermocouple_sensors/max6675_signalk_n2k.cpp b/examples/dual_thermocouple_sensors/max6675_signalk_n2k.cpp index 79959c0d9..2ea47d4cf 100644 --- a/examples/dual_thermocouple_sensors/max6675_signalk_n2k.cpp +++ b/examples/dual_thermocouple_sensors/max6675_signalk_n2k.cpp @@ -144,8 +144,5 @@ void setup() { // main program loop void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); + event_loop()->tick(); } diff --git a/examples/freertos_tasks.cpp b/examples/freertos_tasks.cpp index e94d84b54..eb95d5dc8 100644 --- a/examples/freertos_tasks.cpp +++ b/examples/freertos_tasks.cpp @@ -88,13 +88,8 @@ void setup() { [](float input) { ESP_LOGD("Example", "Heading: %f", input); })); // print out free heap - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( 2000, []() { ESP_LOGD("Example", "Free heap: %d", ESP.getFreeHeap()); }); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/fuel_level_sensor/fuel_level_sensor_example.cpp b/examples/fuel_level_sensor/fuel_level_sensor_example.cpp index beabd17cf..ae618bba6 100644 --- a/examples/fuel_level_sensor/fuel_level_sensor_example.cpp +++ b/examples/fuel_level_sensor/fuel_level_sensor_example.cpp @@ -35,9 +35,4 @@ void setup() { new SKOutputFloat("tanks.fuel.0.currentLevel")); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/hysteresis.cpp b/examples/hysteresis.cpp index 7f6040e30..32e267444 100644 --- a/examples/hysteresis.cpp +++ b/examples/hysteresis.cpp @@ -45,9 +45,4 @@ void setup() { ->connect_to(new SKOutputBool(sk_path)); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/join_and_zip.cpp b/examples/join_and_zip.cpp index 640cde834..29a1ada64 100644 --- a/examples/join_and_zip.cpp +++ b/examples/join_and_zip.cpp @@ -142,14 +142,7 @@ void setup() { // merged values to the console. merged_string->connect_to(new LambdaConsumer( - [](String value) { - ESP_LOGD("App", "Merged: %s", value.c_str()); - })); + [](String value) { ESP_LOGD("App", "Merged: %s", value.c_str()); })); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/lambda_transform.cpp b/examples/lambda_transform.cpp index 023c5de92..a03779da7 100644 --- a/examples/lambda_transform.cpp +++ b/examples/lambda_transform.cpp @@ -90,9 +90,4 @@ void setup() { ->connect_to(new SKOutputFloat(sk_path)); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/manual_networking.cpp b/examples/manual_networking.cpp index 081217e68..5c295e891 100644 --- a/examples/manual_networking.cpp +++ b/examples/manual_networking.cpp @@ -3,11 +3,11 @@ #include "sensesp/net/http_server.h" #include "sensesp/net/networking.h" #include "sensesp/sensors/digital_input.h" +#include "sensesp/signalk/signalk_output.h" #include "sensesp/system/lambda_consumer.h" #include "sensesp/transforms/linear.h" #include "sensesp/transforms/typecast.h" #include "sensesp_minimal_app_builder.h" -#include "sensesp/signalk/signalk_output.h" using namespace sensesp; @@ -43,7 +43,8 @@ void setup() { Serial.println(""); - ESP_LOGD("Example", "Connected to WiFi. IP address: %s", WiFi.localIP().toString().c_str()); + ESP_LOGD("Example", "Connected to WiFi. IP address: %s", + WiFi.localIP().toString().c_str()); WiFi.setHostname(SensESPBaseApp::get_hostname().c_str()); @@ -56,12 +57,8 @@ void setup() { Serial.printf("Digin: %d\n", input); })); - digin->connect_to(new SKOutputBool("electrical.switches.0.state", "/digin/state")); + digin->connect_to( + new SKOutputBool("electrical.switches.0.state", "/digin/state")); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/milone_level_sensor/milone_level_sensor.cpp b/examples/milone_level_sensor/milone_level_sensor.cpp index 0dcee91cd..27b126510 100644 --- a/examples/milone_level_sensor/milone_level_sensor.cpp +++ b/examples/milone_level_sensor/milone_level_sensor.cpp @@ -42,7 +42,7 @@ class ETapeInterpreter : public CurveInterpolator { }; void setup() { -// Some initialization boilerplate when in debug mode... + // Some initialization boilerplate when in debug mode... SetupLogging(); // Create a builder object @@ -129,9 +129,4 @@ void setup() { new SKOutputFloat("tanks.freshwater.starboard.currentLevel")); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/minimal_app.cpp b/examples/minimal_app.cpp index 54893adef..8aeb7a699 100644 --- a/examples/minimal_app.cpp +++ b/examples/minimal_app.cpp @@ -58,17 +58,12 @@ void setup() { })); pinMode(output_pin1, OUTPUT); - SensESPBaseApp::get_event_loop()->onRepeat(5, - []() { digitalWrite(output_pin1, !digitalRead(output_pin1)); }); + event_loop()->onRepeat( + 5, []() { digitalWrite(output_pin1, !digitalRead(output_pin1)); }); pinMode(output_pin2, OUTPUT); - SensESPBaseApp::get_event_loop()->onRepeat(100, - []() { digitalWrite(output_pin2, !digitalRead(output_pin2)); }); + event_loop()->onRepeat( + 100, []() { digitalWrite(output_pin2, !digitalRead(output_pin2)); }); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/raw_json.cpp b/examples/raw_json.cpp index cf23e36bf..6d05d333d 100644 --- a/examples/raw_json.cpp +++ b/examples/raw_json.cpp @@ -19,8 +19,7 @@ void setup() { ->set_wifi("Hat Labs Sensors", "kanneluuri2406") ->get_app(); - SensESPBaseApp::get_event_loop()->onRepeat(1000, - []() { toggler.set(!toggler.get()); }); + event_loop()->onRepeat(1000, []() { toggler.set(!toggler.get()); }); // take some boolean input and convert it into a simple serialized JSON // document @@ -45,9 +44,4 @@ void setup() { jsonify->connect_to(new SKOutputRawJson(sk_path, "")); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/relay_control.cpp b/examples/relay_control.cpp index 45ec47a19..126d28c7e 100644 --- a/examples/relay_control.cpp +++ b/examples/relay_control.cpp @@ -18,7 +18,7 @@ using namespace sensesp; // light when it gets dark outside. void setup() { -// Some initialization boilerplate when in debug mode... + // Some initialization boilerplate when in debug mode... SetupLogging(); // Create a builder object @@ -54,9 +54,4 @@ void setup() { ->connect_to(new DigitalOutput(5)); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/repeat_sensor_analog_input.cpp b/examples/repeat_sensor_analog_input.cpp index 52bff0b96..7fcf5198a 100644 --- a/examples/repeat_sensor_analog_input.cpp +++ b/examples/repeat_sensor_analog_input.cpp @@ -63,9 +63,4 @@ void setup() { new SKOutputFloat(sk_path, "", new SKMetadata("ratio", "Indoor light"))); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/repeat_transform.cpp b/examples/repeat_transform.cpp index 859086336..f4081fcc6 100644 --- a/examples/repeat_transform.cpp +++ b/examples/repeat_transform.cpp @@ -77,9 +77,9 @@ void setup() { // Repeat the values every 2 seconds - auto repeat_A = new Repeat(2000); - auto repeat_a = new Repeat(2000); - auto repeat_int = new Repeat(2000); + auto repeat_A = new Repeat(2000); + auto repeat_a = new Repeat(2000); + auto repeat_int = new Repeat(2000); // Pay attention to the individual columns of the program console output. // Capital letters are produced every second. Repeat gets always triggered as @@ -138,9 +138,4 @@ void setup() { [](int value) { ESP_LOGD("App", "Repeat: %d", value); })); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/rpm_counter.cpp b/examples/rpm_counter.cpp index a8ba03ace..2fc1b15f8 100644 --- a/examples/rpm_counter.cpp +++ b/examples/rpm_counter.cpp @@ -1,6 +1,6 @@ #include -//#define SERIAL_DEBUG_DISABLED +// #define SERIAL_DEBUG_DISABLED #include "sensesp/sensors/digital_input.h" #include "sensesp/signalk/signalk_output.h" @@ -75,9 +75,4 @@ void setup() { // to a Signal K Output as a number } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/smart_switch/remote_switch_example.cpp b/examples/smart_switch/remote_switch_example.cpp index 6c25c9704..22a8b1520 100644 --- a/examples/smart_switch/remote_switch_example.cpp +++ b/examples/smart_switch/remote_switch_example.cpp @@ -101,9 +101,4 @@ void setup() { sk_listener->connect_to(controller); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/smart_switch/smart_switch_example.cpp b/examples/smart_switch/smart_switch_example.cpp index 23806b8fb..af786c14b 100644 --- a/examples/smart_switch/smart_switch_example.cpp +++ b/examples/smart_switch/smart_switch_example.cpp @@ -107,13 +107,8 @@ void setup() { // to be reported to the server every 10 seconds, regardless of whether // or not it has changed. That keeps the value on the server fresh and // lets the server know the switch is still alive. - load_switch->connect_to(new Repeat(10000)) + load_switch->connect_to(new Repeat(10000)) ->connect_to(new SKOutputBool(sk_path, config_path_sk_output)); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/temperature_sender.cpp b/examples/temperature_sender.cpp index 23bf596ba..24368eccf 100644 --- a/examples/temperature_sender.cpp +++ b/examples/temperature_sender.cpp @@ -162,9 +162,4 @@ void setup() { new SKOutputFloat(sk_path, "/12V_alternator/temp/sk", metadata)); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/examples/time_counter.cpp b/examples/time_counter.cpp index b91116642..943a8341d 100644 --- a/examples/time_counter.cpp +++ b/examples/time_counter.cpp @@ -15,11 +15,12 @@ * */ -#include "sensesp_app.h" -#include "sensesp/sensors/digital_input.h" -#include "sensesp/transforms/lambda_transform.h" #include "sensesp/transforms/time_counter.h" + +#include "sensesp/sensors/digital_input.h" #include "sensesp/transforms/frequency.h" +#include "sensesp/transforms/lambda_transform.h" +#include "sensesp_app.h" #include "sensesp_app_builder.h" using namespace sensesp; @@ -37,7 +38,7 @@ void setup() { // set GPIO 18 to output mode pinMode(18, OUTPUT); - SensESPBaseApp::get_event_loop()->onRepeat(10, []() { + event_loop()->onRepeat(10, []() { if (freq == 0) { if (millis() - freq_start_time >= 10000) { freq = 10; @@ -86,20 +87,18 @@ void setup() { frequency->connect_to(propulsion_state); // create engine hours counter using PersistentDuration - auto* engine_hours = - new TimeCounter("/Transforms/Engine Hours"); + auto* engine_hours = new TimeCounter("/Transforms/Engine Hours"); frequency->connect_to(engine_hours); // create and connect the frequency output object frequency->connect_to( new SKOutput("propulsion.main.revolutions", "", - new SKMetadata("Hz", "Main Engine Revolutions"))); + new SKMetadata("Hz", "Main Engine Revolutions"))); // create and connect the propulsion state output object - propulsion_state->connect_to( - new SKOutput("propulsion.main.state", "", - new SKMetadata("", "Main Engine State"))); + propulsion_state->connect_to(new SKOutput( + "propulsion.main.state", "", new SKMetadata("", "Main Engine State"))); // create and connect the engine hours output object engine_hours->connect_to( @@ -107,9 +106,4 @@ void setup() { new SKMetadata("s", "Main Engine running time"))); } -void loop() { - // We're storing the event loop in a static variable so that it's only - // acquired once. Saves a few function calls per loop iteration. - static auto event_loop = SensESPBaseApp::get_event_loop(); - event_loop->tick(); -} +void loop() { event_loop()->tick(); } diff --git a/src/sensesp/controllers/smart_switch_controller.cpp b/src/sensesp/controllers/smart_switch_controller.cpp index 4817a39c8..37081adb1 100644 --- a/src/sensesp/controllers/smart_switch_controller.cpp +++ b/src/sensesp/controllers/smart_switch_controller.cpp @@ -23,7 +23,7 @@ SmartSwitchController::SmartSwitchController(bool auto_initialize, // Emit the initial state once the event loop starts if (auto_initialize_) { - SensESPBaseApp::get_event_loop()->onDelay(0, + event_loop()->onDelay(0, [this]() { this->emit(is_on); }); } } diff --git a/src/sensesp/net/discovery.cpp b/src/sensesp/net/discovery.cpp index 404720742..aeee82426 100644 --- a/src/sensesp/net/discovery.cpp +++ b/src/sensesp/net/discovery.cpp @@ -5,7 +5,7 @@ namespace sensesp { MDNSDiscovery::MDNSDiscovery() { - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { + event_loop()->onDelay(0, [this]() { String hostname = SensESPBaseApp::get_hostname(); // MDNS.begin(hostname) will crash if hostname is blank diff --git a/src/sensesp/net/http_server.h b/src/sensesp/net/http_server.h index 8ce0d5cc8..5002be11c 100644 --- a/src/sensesp/net/http_server.h +++ b/src/sensesp/net/http_server.h @@ -79,7 +79,7 @@ class HTTPServer : public Configurable { ESP_LOGE(__FILENAME__, "Only one HTTPServer instance is allowed"); return; } - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { + event_loop()->onDelay(0, [this]() { esp_err_t error = httpd_start(&server_, &config_); if (error != ESP_OK) { ESP_LOGE(__FILENAME__, "Error starting HTTP server: %s", diff --git a/src/sensesp/net/networking.cpp b/src/sensesp/net/networking.cpp index 34ae4b08f..292cbb147 100644 --- a/src/sensesp/net/networking.cpp +++ b/src/sensesp/net/networking.cpp @@ -92,7 +92,7 @@ Networking::Networking(String config_path, String client_ssid, dns_server_->setErrorReplyCode(DNSReplyCode::NoError); dns_server_->start(53, "*", WiFi.softAPIP()); - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( 1, [this]() { dns_server_->processNextRequest(); }); } } @@ -193,7 +193,7 @@ void Networking::start_client_autoconnect() { // Launch a separate onRepeat event to (re-)establish WiFi connection. // Connecting is attempted only every 20 s to allow the previous connection // attempt to complete even if the network is slow. - SensESPBaseApp::get_event_loop()->onRepeat(20000, reconnect_cb); + event_loop()->onRepeat(20000, reconnect_cb); } /** diff --git a/src/sensesp/net/networking.h b/src/sensesp/net/networking.h index 750b3e71b..a6acd0bf2 100644 --- a/src/sensesp/net/networking.h +++ b/src/sensesp/net/networking.h @@ -49,7 +49,7 @@ class WiFiStateProducer : public ValueProducer { setup_wifi_callbacks(); // Emit the current state as soon as the event loop starts - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { this->emit(this->output); }); + event_loop()->onDelay(0, [this]() { this->emit(this->output); }); } void setup_wifi_callbacks() { @@ -89,7 +89,7 @@ class WiFiStateProducer : public ValueProducer { // Setting the AP mode happens immediately, // so this callback is likely called already before all startables have been // initiated. Delay the WiFi state update until the start of the event loop. - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( 0, [this]() { this->emit(WiFiState::kWifiAPModeActivated); }); } diff --git a/src/sensesp/net/ota.h b/src/sensesp/net/ota.h index 8e2161bfa..41e3a7742 100644 --- a/src/sensesp/net/ota.h +++ b/src/sensesp/net/ota.h @@ -18,7 +18,7 @@ class OTA { * @param password A password to be used for the OTA update. */ OTA(const char* password) : password_{password} { - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { + event_loop()->onDelay(0, [this]() { ArduinoOTA.setPassword(password_); ArduinoOTA.onStart([]() { ESP_LOGW(__FILENAME__, "Starting OTA"); }); ArduinoOTA.onEnd([]() { ESP_LOGW(__FILENAME__, "OTA End"); }); @@ -41,7 +41,7 @@ class OTA { } }); ArduinoOTA.begin(); - SensESPBaseApp::get_event_loop()->onRepeat(20, OTA::handle_ota); + event_loop()->onRepeat(20, OTA::handle_ota); }); } diff --git a/src/sensesp/net/web/base_command_handler.cpp b/src/sensesp/net/web/base_command_handler.cpp index 71c6a614d..42d08b06d 100644 --- a/src/sensesp/net/web/base_command_handler.cpp +++ b/src/sensesp/net/web/base_command_handler.cpp @@ -9,7 +9,7 @@ void add_http_reset_handler(HTTPServer* server) { "Resetting device back to factory defaults. " "You may have to reconfigure the WiFi settings.", 0); - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( 500, []() { SensESPBaseApp::get()->reset(); }); return ESP_OK; }); @@ -20,7 +20,7 @@ void add_http_restart_handler(HTTPServer* server) { HTTPRequestHandler* restart_handler = new HTTPRequestHandler( 1 << HTTP_POST, "/api/device/restart", [](httpd_req_t* req) { httpd_resp_send(req, "Restarting device", 0); - SensESPBaseApp::get_event_loop()->onDelay(500, []() { ESP.restart(); }); + event_loop()->onDelay(500, []() { ESP.restart(); }); return ESP_OK; }); server->add_handler(restart_handler); diff --git a/src/sensesp/sensors/analog_input.cpp b/src/sensesp/sensors/analog_input.cpp index 780f8b976..2574a07f8 100644 --- a/src/sensesp/sensors/analog_input.cpp +++ b/src/sensesp/sensors/analog_input.cpp @@ -18,7 +18,7 @@ AnalogInput::AnalogInput(uint8_t pin, unsigned int read_delay, load_configuration(); if (this->analog_reader->configure()) { - SensESPBaseApp::get_event_loop()->onRepeat(read_delay, [this]() { this->update(); }); + event_loop()->onRepeat(read_delay, [this]() { this->update(); }); } } diff --git a/src/sensesp/sensors/constant_sensor.h b/src/sensesp/sensors/constant_sensor.h index 8940d9a96..78cf091c0 100644 --- a/src/sensesp/sensors/constant_sensor.h +++ b/src/sensesp/sensors/constant_sensor.h @@ -59,10 +59,11 @@ class ConstantSensor : public Sensor { this->load_configuration(); // Emit the initial value once to set the output - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { this->emit(value_); }); + event_loop()->onDelay(0, + [this]() { this->emit(value_); }); // Then, emit the value at the specified interval - SensESPBaseApp::get_event_loop()->onRepeat(send_interval_ * 1000, - [this]() { this->emit(value_); }); + event_loop()->onRepeat( + send_interval_ * 1000, [this]() { this->emit(value_); }); } void set(T value) { value_ = value; } diff --git a/src/sensesp/sensors/digital_input.h b/src/sensesp/sensors/digital_input.h index e940c8e6a..d5560a0de 100644 --- a/src/sensesp/sensors/digital_input.h +++ b/src/sensesp/sensors/digital_input.h @@ -57,7 +57,7 @@ class DigitalInputState : public DigitalInput, public Sensor { set_requires_restart(true); load_configuration(); - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( read_delay_, [this]() { emit(digitalRead(pin_)); }); } @@ -93,10 +93,10 @@ class DigitalInputCounter : public DigitalInput, public Sensor { unsigned int read_delay, String config_path = "") : DigitalInputCounter(pin, pin_mode, interrupt_type, read_delay, config_path, [this]() { this->counter_++; }) { - SensESPBaseApp::get_event_loop()->onInterrupt(pin_, interrupt_type_, + event_loop()->onInterrupt(pin_, interrupt_type_, interrupt_handler_); - SensESPBaseApp::get_event_loop()->onRepeat(read_delay_, [this]() { + event_loop()->onRepeat(read_delay_, [this]() { noInterrupts(); output = counter_; counter_ = 0; @@ -201,13 +201,13 @@ class DigitalInputChange : public DigitalInput, public Sensor { output = (bool)digitalRead(pin_); last_output_ = !output; // ensure that we always send the first output - SensESPBaseApp::get_event_loop()->onInterrupt( + event_loop()->onInterrupt( pin_, interrupt_type_, [this]() { output = (bool)digitalRead(pin_); triggered_ = true; }); - SensESPBaseApp::get_event_loop()->onTick([this]() { + event_loop()->onTick([this]() { if (triggered_ && (output != last_output_)) { noInterrupts(); triggered_ = false; diff --git a/src/sensesp/sensors/system_info.h b/src/sensesp/sensors/system_info.h index 4d709c31c..4963bad25 100644 --- a/src/sensesp/sensors/system_info.h +++ b/src/sensesp/sensors/system_info.h @@ -47,8 +47,8 @@ class SystemHz : public FloatSensor { SystemHz() { elapsed_millis_ = 0; - SensESPBaseApp::get_event_loop()->onTick([this]() { this->tick(); }); - SensESPBaseApp::get_event_loop()->onRepeat(1000, + event_loop()->onTick([this]() { this->tick(); }); + event_loop()->onRepeat(1000, [this]() { this->update(); }); } String get_value_name() { return "systemhz"; } @@ -71,7 +71,7 @@ class SystemHz : public FloatSensor { class FreeMem : public IntSensor { public: FreeMem() { - SensESPBaseApp::get_event_loop()->onRepeat(1000, + event_loop()->onRepeat(1000, [this]() { this->update(); }); } String get_value_name() { return "freemem"; } @@ -91,7 +91,7 @@ class FreeMem : public IntSensor { class Uptime : public FloatSensor { public: Uptime() { - SensESPBaseApp::get_event_loop()->onRepeat(1000, + event_loop()->onRepeat(1000, [this]() { this->update(); }); } String get_value_name() { return "uptime"; } @@ -111,7 +111,7 @@ class Uptime : public FloatSensor { class IPAddrDev : public StringSensor { public: IPAddrDev() { - SensESPBaseApp::get_event_loop()->onRepeat(10000, + event_loop()->onRepeat(10000, [this]() { this->update(); }); } String get_value_name() { return "ipaddr"; } @@ -131,7 +131,7 @@ class IPAddrDev : public StringSensor { class WiFiSignal : public FloatSensor { public: WiFiSignal() { - SensESPBaseApp::get_event_loop()->onRepeat(3000, + event_loop()->onRepeat(3000, [this]() { this->update(); }); } String get_value_name() { return "wifisignal"; } diff --git a/src/sensesp/signalk/signalk_delta_queue.cpp b/src/sensesp/signalk/signalk_delta_queue.cpp index b8a850265..7774f9390 100644 --- a/src/sensesp/signalk/signalk_delta_queue.cpp +++ b/src/sensesp/signalk/signalk_delta_queue.cpp @@ -13,7 +13,7 @@ SKDeltaQueue::SKDeltaQueue(unsigned int max_buffer_size) : max_buffer_size{max_buffer_size}, meta_sent_{false} { semaphore_ = xSemaphoreCreateRecursiveMutex(); - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( 0, [this]() { this->connect_emitters(); }); } diff --git a/src/sensesp/signalk/signalk_put_request.cpp b/src/sensesp/signalk/signalk_put_request.cpp index cb227878e..16304fc65 100644 --- a/src/sensesp/signalk/signalk_put_request.cpp +++ b/src/sensesp/signalk/signalk_put_request.cpp @@ -22,7 +22,7 @@ String SKRequest::send_request(JsonDocument& request, // After 10 seconds, if we haven't already handled a response, // assume its not coming. pending_request->timeout_cleanup = - SensESPBaseApp::get_event_loop()->onDelay(timeout, [pending_request]() { + event_loop()->onDelay(timeout, [pending_request]() { // Mark the delay eventll as it will be cleaned up by the ReactESP // framework if this executes... ESP_LOGW(__FILENAME__, "No response from server for request Id %s", @@ -80,7 +80,7 @@ void SKRequest::remove_request(String request_id) { // The timeout code was not called, so just // remove it from the ReactESP execution queue... pending_request->timeout_cleanup->remove( - SensESPBaseApp::get_event_loop()); + event_loop()); } // Now, remove the request from the map... diff --git a/src/sensesp/signalk/signalk_ws_client.cpp b/src/sensesp/signalk/signalk_ws_client.cpp index bf1e4566c..70b802269 100644 --- a/src/sensesp/signalk/signalk_ws_client.cpp +++ b/src/sensesp/signalk/signalk_ws_client.cpp @@ -90,7 +90,7 @@ SKWSClient::SKWSClient(const String& config_path, SKDeltaQueue* sk_delta_queue, [this]() { this->emit(this->connection_state_.get()); }); // process any received updates in the main task - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( 1, [this]() { this->process_received_updates(); }); // set the singleton object pointer @@ -101,7 +101,7 @@ SKWSClient::SKWSClient(const String& config_path, SKDeltaQueue* sk_delta_queue, // Connect the counters delta_tx_tick_producer_.connect_to(&delta_tx_count_producer_); - SensESPBaseApp::get_event_loop()->onDelay(0, [this]() { + event_loop()->onDelay(0, [this]() { ESP_LOGD(__FILENAME__, "Starting SKWSClient"); xTaskCreate(ExecuteWebSocketTask, "SKWSClient", kWsClientTaskStackSize, this, 1, NULL); diff --git a/src/sensesp/signalk/signalk_ws_client.h b/src/sensesp/signalk/signalk_ws_client.h index cdaaf22c2..ca12e0476 100644 --- a/src/sensesp/signalk/signalk_ws_client.h +++ b/src/sensesp/signalk/signalk_ws_client.h @@ -106,7 +106,7 @@ class SKWSClient : public Configurable, TaskQueueProducer connection_state_ = TaskQueueProducer( SKWSConnectionState::kSKWSDisconnected, - SensESPBaseApp::get_event_loop()); + event_loop()); /// task_connection_state is used to track the internal task state which might /// be out of sync with the published connection state. @@ -118,7 +118,7 @@ class SKWSClient : public Configurable, SKDeltaQueue* sk_delta_queue_; /// @brief Emits the number of deltas sent since last report TaskQueueProducer delta_tx_tick_producer_ = - TaskQueueProducer(0, SensESPBaseApp::get_event_loop(), 5, 990); + TaskQueueProducer(0, event_loop(), 5, 990); Integrator delta_tx_count_producer_{1, 0, ""}; Integrator delta_rx_count_producer_{1, 0, ""}; diff --git a/src/sensesp/system/async_response_handler.h b/src/sensesp/system/async_response_handler.h index bffb59976..637facccc 100644 --- a/src/sensesp/system/async_response_handler.h +++ b/src/sensesp/system/async_response_handler.h @@ -50,11 +50,11 @@ class AsyncResponseHandler : public ValueConsumer, this->emit(status_); if (timeout_event_ != nullptr) { - SensESPBaseApp::get_event_loop()->remove(timeout_event_); + event_loop()->remove(timeout_event_); timeout_event_ = nullptr; } timeout_event_ = - SensESPBaseApp::get_event_loop()->onDelay(timeout_, [this]() { + event_loop()->onDelay(timeout_, [this]() { if (status_ == AsyncResponseStatus::kPending) { ESP_LOGV("AsyncResponseHandler", "Timeout"); status_ = AsyncResponseStatus::kTimeout; @@ -74,7 +74,7 @@ class AsyncResponseHandler : public ValueConsumer, // Clear the timeout event if (timeout_event_ != nullptr) { - SensESPBaseApp::get_event_loop()->remove(timeout_event_); + event_loop()->remove(timeout_event_); timeout_event_ = nullptr; } diff --git a/src/sensesp/system/base_button.h b/src/sensesp/system/base_button.h index 14e72c9e4..c313292e3 100644 --- a/src/sensesp/system/base_button.h +++ b/src/sensesp/system/base_button.h @@ -32,7 +32,7 @@ class BaseButtonHandler : public Configurable, public IEventHandler { ESP_LOGD(__FILENAME__, "Button handler started"); - SensESPBaseApp::get_event_loop()->onRepeat( + event_loop()->onRepeat( 4, [this]() { this->button_->check(); }); } diff --git a/src/sensesp/system/led_blinker.cpp b/src/sensesp/system/led_blinker.cpp index 1267467a2..173f64a56 100644 --- a/src/sensesp/system/led_blinker.cpp +++ b/src/sensesp/system/led_blinker.cpp @@ -11,7 +11,7 @@ namespace sensesp { BaseBlinker::BaseBlinker(int pin) : pin_{pin} { pinMode(pin, OUTPUT); - SensESPBaseApp::get_event_loop()->onDelay(1, [this]() { this->tick(); }); + event_loop()->onDelay(1, [this]() { this->tick(); }); } /** @@ -44,13 +44,13 @@ void BaseBlinker::blip(int duration) { bool const orig_state = this->state_; this->set_state(false); int const current_counter = this->update_counter_; - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( duration, [this, duration, orig_state, current_counter]() { // only update if no-one has touched the LED in the meanwhile if (this->update_counter_ == current_counter) { this->set_state(true); int const new_counter = this->update_counter_; - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( duration, [this, orig_state, new_counter]() { // again, only update if no-one has touched the LED if (this->update_counter_ == new_counter) { @@ -75,7 +75,7 @@ void BaseBlinker::set_enabled(bool state) { } else { this->set_state(false); if (was_enabled) { - event_->remove(SensESPBaseApp::get_event_loop()); + event_->remove(event_loop()); } } } @@ -91,7 +91,7 @@ void EvenBlinker::tick() { return; } this->flip_state(); - event_ = SensESPBaseApp::get_event_loop()->onDelay( + event_ = event_loop()->onDelay( period_, [this]() { this->tick(); }); } @@ -107,7 +107,7 @@ void RatioBlinker::tick() { int const off_duration = max(0, period_ - on_duration); unsigned int const ref_duration = state_ == false ? off_duration : on_duration; - event_ = SensESPBaseApp::get_event_loop()->onDelay( + event_ = event_loop()->onDelay( ref_duration, [this]() { this->tick(); }); } @@ -137,7 +137,7 @@ void PatternBlinker::tick() { // odd indices indicate times when LED should be OFF, even when ON bool const new_state = (pattern_ptr_ % 2) == 0; this->set_state(new_state); - event_ = SensESPBaseApp::get_event_loop()->onDelay( + event_ = event_loop()->onDelay( pattern_[pattern_ptr_++], [this]() { this->tick(); }); } @@ -145,7 +145,7 @@ void PatternBlinker::restart() { state_ = false; pattern_ptr_ = 0; if (event_ != NULL) { - event_->remove(SensESPBaseApp::get_event_loop()); + event_->remove(event_loop()); event_ = NULL; this->tick(); } diff --git a/src/sensesp/system/stream_producer.h b/src/sensesp/system/stream_producer.h index f600a9a01..10ae1960d 100644 --- a/src/sensesp/system/stream_producer.h +++ b/src/sensesp/system/stream_producer.h @@ -16,7 +16,7 @@ class StreamCharProducer : public ValueProducer { public: StreamCharProducer(Stream* stream) : stream_{stream} { read_event_ = - SensESPBaseApp::get_event_loop()->onAvailable(*stream_, [this]() { + event_loop()->onAvailable(*stream_, [this]() { while (stream_->available()) { char c = stream_->read(); this->emit(c); @@ -39,7 +39,7 @@ class StreamLineProducer : public ValueProducer { static int buf_pos = 0; buf_ = new char[max_line_length_ + 1]; read_event_ = - SensESPBaseApp::get_event_loop()->onAvailable(*stream_, [this]() { + event_loop()->onAvailable(*stream_, [this]() { while (stream_->available()) { char c = stream_->read(); if (c == '\n') { diff --git a/src/sensesp/system/task_queue_producer.h b/src/sensesp/system/task_queue_producer.h index 169bd4257..038d1c207 100644 --- a/src/sensesp/system/task_queue_producer.h +++ b/src/sensesp/system/task_queue_producer.h @@ -24,7 +24,7 @@ template class TaskQueueProducer : public ObservableValue { public: TaskQueueProducer(const T& value, - reactesp::EventLoop* consumer_app = SensESPBaseApp::get_event_loop(), + reactesp::EventLoop* consumer_app = event_loop(), int queue_size = 1, unsigned int poll_rate = 990) : ObservableValue(value), queue_size_{queue_size} { queue_ = xQueueCreate(queue_size, sizeof(T)); @@ -43,7 +43,7 @@ class TaskQueueProducer : public ObservableValue { TaskQueueProducer(const T& value, int queue_size = 1, unsigned int poll_rate = 990) - : TaskQueueProducer(value, SensESPBaseApp::get_event_loop(), queue_size, + : TaskQueueProducer(value, event_loop(), queue_size, poll_rate) {} virtual void set(const T& value) override { diff --git a/src/sensesp/transforms/click_type.cpp b/src/sensesp/transforms/click_type.cpp index 21a12ad5b..21e34f438 100644 --- a/src/sensesp/transforms/click_type.cpp +++ b/src/sensesp/transforms/click_type.cpp @@ -54,7 +54,7 @@ void ClickType::on_button_press() { // of the double_click_interval. Remove any "SingleClick" report that may // have been queued up.... if (delayed_click_report_ != NULL) { - delayed_click_report_->remove(SensESPBaseApp::get_event_loop()); + delayed_click_report_->remove(event_loop()); delayed_click_report_ = NULL; ESP_LOGD(__FILENAME__, "ClickType press is double click. Removed queued SingleClick " @@ -101,7 +101,7 @@ void ClickType::on_button_release() { // DoubleClick uint64_t const time_of_event = millis(); int64_t const pd = (long)press_duration_; - delayed_click_report_ = SensESPBaseApp::get_event_loop()->onDelay( + delayed_click_report_ = event_loop()->onDelay( double_click_interval_ + 20, [this, pd, time_of_event]() { ESP_LOGD( __FILENAME__, @@ -129,7 +129,7 @@ void ClickType::on_button_release() { } void ClickType::emitDelayed(ClickTypes value) { - SensESPBaseApp::get_event_loop()->onDelay( + event_loop()->onDelay( 5, [this, value]() { this->emit(value); }); } diff --git a/src/sensesp/transforms/debounce.h b/src/sensesp/transforms/debounce.h index 4da87a67f..ff5f2d450 100644 --- a/src/sensesp/transforms/debounce.h +++ b/src/sensesp/transforms/debounce.h @@ -50,11 +50,11 @@ class Debounce : public SymmetricTransform { debounced_value_ = input; if (event_) { - event_->remove(SensESPBaseApp::get_event_loop()); + event_->remove(event_loop()); event_ = nullptr; } - event_ = - SensESPBaseApp::get_event_loop()->onDelay(ms_min_delay_, [this, input]() { + event_ = event_loop()->onDelay( + ms_min_delay_, [this, input]() { this->event_ = nullptr; this->debounced_value_ = input; this->emit(input); diff --git a/src/sensesp/transforms/press_repeater.cpp b/src/sensesp/transforms/press_repeater.cpp index 5763a984e..d63bb3c48 100644 --- a/src/sensesp/transforms/press_repeater.cpp +++ b/src/sensesp/transforms/press_repeater.cpp @@ -12,7 +12,7 @@ PressRepeater::PressRepeater(const String& config_path, int integer_false, repeating_{false} { load_configuration(); - SensESPBaseApp::get_event_loop()->onRepeat(10, [this]() { + event_loop()->onRepeat(10, [this]() { if (pushed_) { // A press is currently in progress if (repeating_) { diff --git a/src/sensesp/transforms/repeat.h b/src/sensesp/transforms/repeat.h index 2da2c0e18..6a25ed4d1 100644 --- a/src/sensesp/transforms/repeat.h +++ b/src/sensesp/transforms/repeat.h @@ -33,9 +33,9 @@ class Repeat : public Transform { this->emit(input); if (repeat_event_ != nullptr) { // Delete the old repeat event - repeat_event_->remove(SensESPBaseApp::get_event_loop()); + repeat_event_->remove(event_loop()); } - repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + repeat_event_ = event_loop()->onRepeat( interval_, [this]() { this->notify(); }); } @@ -65,7 +65,7 @@ class RepeatStopping : public Repeat { // Delete the old repeat event this->repeat_event_->remove(); } - this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + this->repeat_event_ = event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); } @@ -76,7 +76,7 @@ class RepeatStopping : public Repeat { // Delete the old repeat event this->repeat_event_->remove(); } - this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + this->repeat_event_ = event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); } @@ -113,9 +113,9 @@ class RepeatExpiring : public Repeat> { if (this->repeat_event_ != nullptr) { // Delete the old repeat event - this->repeat_event_->remove(SensESPBaseApp::get_event_loop()); + this->repeat_event_->remove(event_loop()); } - this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + this->repeat_event_ = event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); } @@ -124,9 +124,9 @@ class RepeatExpiring : public Repeat> { age_ = 0; if (this->repeat_event_ != nullptr) { // Delete the old repeat event - this->repeat_event_->remove(SensESPBaseApp::get_event_loop()); + this->repeat_event_->remove(event_loop()); } - this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + this->repeat_event_ = event_loop()->onRepeat( this->interval_, [this]() { this->repeat_function(); }); } @@ -167,7 +167,7 @@ class RepeatConstantRate : public RepeatExpiring { this->repeat_event_->remove(); } - this->repeat_event_ = SensESPBaseApp::get_event_loop()->onRepeat( + this->repeat_event_ = event_loop()->onRepeat( interval, [this]() { this->repeat_function(); }); } diff --git a/src/sensesp_app_builder.h b/src/sensesp_app_builder.h index bb8549614..f05753538 100644 --- a/src/sensesp_app_builder.h +++ b/src/sensesp_app_builder.h @@ -220,7 +220,7 @@ class SensESPAppBuilder : public SensESPBaseAppBuilder { input == SystemStatus::kWifiNoAP) { ESP_LOGW(__FILENAME__, "Unable to connect to wifi for too long; restarting."); - SensESPBaseApp::get_event_loop()->onDelay(1000, []() { ESP.restart(); }); + event_loop()->onDelay(1000, []() { ESP.restart(); }); } }));