diff --git a/include/Datastore.h b/include/Datastore.h index 351a822..b4610bf 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -6,6 +6,7 @@ class DatastoreClass { public: + DatastoreClass(); void init(Scheduler& scheduler); // Sum of yield total of all enabled inverters, a inverter which is just disabled at night is also included @@ -81,4 +82,4 @@ private: bool _isAtLeastOnePollEnabled = false; }; -extern DatastoreClass Datastore; \ No newline at end of file +extern DatastoreClass Datastore; diff --git a/include/InverterSettings.h b/include/InverterSettings.h index aad05ed..6a36a70 100644 --- a/include/InverterSettings.h +++ b/include/InverterSettings.h @@ -8,6 +8,7 @@ class InverterSettingsClass { public: + InverterSettingsClass(); void init(Scheduler& scheduler); private: diff --git a/include/MessageOutput.h b/include/MessageOutput.h index 94f915a..4048975 100644 --- a/include/MessageOutput.h +++ b/include/MessageOutput.h @@ -1,33 +1,34 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -#pragma once - -#include -#include -#include -#include -#include - -#define BUFFER_SIZE 500 - -class MessageOutputClass : public Print { -public: - void init(Scheduler& scheduler); - size_t write(uint8_t c) override; - size_t write(const uint8_t* buffer, size_t size) override; - void register_ws_output(AsyncWebSocket* output); - -private: - void loop(); - - Task _loopTask; - - AsyncWebSocket* _ws = nullptr; - char _buffer[BUFFER_SIZE]; - uint16_t _buff_pos = 0; - uint32_t _lastSend = 0; - bool _forceSend = false; - - std::mutex _msgLock; -}; - -extern MessageOutputClass MessageOutput; \ No newline at end of file +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#include +#include +#include +#include +#include + +#define BUFFER_SIZE 500 + +class MessageOutputClass : public Print { +public: + MessageOutputClass(); + void init(Scheduler& scheduler); + size_t write(uint8_t c) override; + size_t write(const uint8_t* buffer, size_t size) override; + void register_ws_output(AsyncWebSocket* output); + +private: + void loop(); + + Task _loopTask; + + AsyncWebSocket* _ws = nullptr; + char _buffer[BUFFER_SIZE]; + uint16_t _buff_pos = 0; + uint32_t _lastSend = 0; + bool _forceSend = false; + + std::mutex _msgLock; +}; + +extern MessageOutputClass MessageOutput; diff --git a/include/MqttHandleDtu.h b/include/MqttHandleDtu.h index 01e1798..5afc877 100644 --- a/include/MqttHandleDtu.h +++ b/include/MqttHandleDtu.h @@ -6,6 +6,7 @@ class MqttHandleDtuClass { public: + MqttHandleDtuClass(); void init(Scheduler& scheduler); private: @@ -14,4 +15,4 @@ private: Task _loopTask; }; -extern MqttHandleDtuClass MqttHandleDtu; \ No newline at end of file +extern MqttHandleDtuClass MqttHandleDtu; diff --git a/include/MqttHandleHass.h b/include/MqttHandleHass.h index 41f7bf8..feb8674 100644 --- a/include/MqttHandleHass.h +++ b/include/MqttHandleHass.h @@ -51,6 +51,7 @@ const byteAssign_fieldDeviceClass_t deviceFieldAssignment[] = { class MqttHandleHassClass { public: + MqttHandleHassClass(); void init(Scheduler& scheduler); void publishConfig(); void forceUpdate(); @@ -79,4 +80,4 @@ private: bool _updateForced = false; }; -extern MqttHandleHassClass MqttHandleHass; \ No newline at end of file +extern MqttHandleHassClass MqttHandleHass; diff --git a/include/MqttHandleInverter.h b/include/MqttHandleInverter.h index 3925935..446f30a 100644 --- a/include/MqttHandleInverter.h +++ b/include/MqttHandleInverter.h @@ -8,6 +8,7 @@ class MqttHandleInverterClass { public: + MqttHandleInverterClass(); void init(Scheduler& scheduler); static String getTopic(std::shared_ptr inv, const ChannelType_t type, const ChannelNum_t channel, const FieldId_t fieldId); @@ -39,4 +40,4 @@ private: }; }; -extern MqttHandleInverterClass MqttHandleInverter; \ No newline at end of file +extern MqttHandleInverterClass MqttHandleInverter; diff --git a/include/MqttHandleInverterTotal.h b/include/MqttHandleInverterTotal.h index 1931781..ae4d66c 100644 --- a/include/MqttHandleInverterTotal.h +++ b/include/MqttHandleInverterTotal.h @@ -5,6 +5,7 @@ class MqttHandleInverterTotalClass { public: + MqttHandleInverterTotalClass(); void init(Scheduler& scheduler); private: @@ -13,4 +14,4 @@ private: Task _loopTask; }; -extern MqttHandleInverterTotalClass MqttHandleInverterTotal; \ No newline at end of file +extern MqttHandleInverterTotalClass MqttHandleInverterTotal; diff --git a/include/WebApi_dtu.h b/include/WebApi_dtu.h index 5514e75..3acf449 100644 --- a/include/WebApi_dtu.h +++ b/include/WebApi_dtu.h @@ -6,6 +6,7 @@ class WebApiDtuClass { public: + WebApiDtuClass(); void init(AsyncWebServer& server, Scheduler& scheduler); private: diff --git a/src/Datastore.cpp b/src/Datastore.cpp index 1d4c2eb..5bfbb98 100644 --- a/src/Datastore.cpp +++ b/src/Datastore.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2023 Thomas Basler and others + * Copyright (C) 2023-2024 Thomas Basler and others */ #include "Datastore.h" #include "Configuration.h" @@ -8,12 +8,14 @@ DatastoreClass Datastore; +DatastoreClass::DatastoreClass() + : _loopTask(1 * TASK_SECOND, TASK_FOREVER, std::bind(&DatastoreClass::loop, this)) +{ +} + void DatastoreClass::init(Scheduler& scheduler) { scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&DatastoreClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); - _loopTask.setInterval(1 * TASK_SECOND); _loopTask.enable(); } diff --git a/src/Display_Graphic.cpp b/src/Display_Graphic.cpp index 04195fd..7f5d94c 100644 --- a/src/Display_Graphic.cpp +++ b/src/Display_Graphic.cpp @@ -35,6 +35,7 @@ static const char* const i18n_yield_total_kwh[] = { "total: %.1f kWh", "Ges.: %. static const char* const i18n_date_format[] = { "%m/%d/%Y %H:%M", "%d.%m.%Y %H:%M", "%d/%m/%Y %H:%M" }; DisplayGraphicClass::DisplayGraphicClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&DisplayGraphicClass::loop, this)) { } @@ -55,8 +56,6 @@ void DisplayGraphicClass::init(Scheduler& scheduler, const DisplayType_t type, c _diagram.init(scheduler, _display); scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&DisplayGraphicClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.setInterval(_period); _loopTask.enable(); } diff --git a/src/Display_Graphic_Diagram.cpp b/src/Display_Graphic_Diagram.cpp index 498123b..b529688 100644 --- a/src/Display_Graphic_Diagram.cpp +++ b/src/Display_Graphic_Diagram.cpp @@ -8,6 +8,8 @@ #include DisplayGraphicDiagramClass::DisplayGraphicDiagramClass() + : _averageTask(1 * TASK_SECOND, TASK_FOREVER, std::bind(&DisplayGraphicDiagramClass::averageLoop, this)) + , _dataPointTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&DisplayGraphicDiagramClass::dataPointLoop, this)) { } @@ -16,14 +18,9 @@ void DisplayGraphicDiagramClass::init(Scheduler& scheduler, U8G2* display) _display = display; scheduler.addTask(_averageTask); - _averageTask.setCallback(std::bind(&DisplayGraphicDiagramClass::averageLoop, this)); - _averageTask.setIterations(TASK_FOREVER); - _averageTask.setInterval(1 * TASK_SECOND); _averageTask.enable(); scheduler.addTask(_dataPointTask); - _dataPointTask.setCallback(std::bind(&DisplayGraphicDiagramClass::dataPointLoop, this)); - _dataPointTask.setIterations(TASK_FOREVER); updatePeriod(); _dataPointTask.enable(); } @@ -58,7 +55,7 @@ uint32_t DisplayGraphicDiagramClass::getSecondsPerDot() void DisplayGraphicDiagramClass::updatePeriod() { // Calculate seconds per datapoint - _dataPointTask.setInterval(Configuration.get().Display.Diagram.Duration * TASK_SECOND / MAX_DATAPOINTS ); + _dataPointTask.setInterval(Configuration.get().Display.Diagram.Duration * TASK_SECOND / MAX_DATAPOINTS); } void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX, uint8_t xPos, uint8_t yPos, uint8_t width, uint8_t height, bool isFullscreen) @@ -110,7 +107,9 @@ void DisplayGraphicDiagramClass::redraw(uint8_t screenSaverOffsetX, uint8_t xPos if (maxWatts > 0 && isFullscreen) { // draw y axis ticks - const uint16_t yAxisWattPerTick = maxWatts <= 100 ? 10 : maxWatts <= 1000 ? 100 : maxWatts < 5000 ? 500 : 1000; + const uint16_t yAxisWattPerTick = maxWatts <= 100 ? 10 : maxWatts <= 1000 ? 100 + : maxWatts < 5000 ? 500 + : 1000; const uint8_t yAxisTickSizePixel = height / (maxWatts / yAxisWattPerTick); for (int16_t tickYPos = graphPosY + height; tickYPos > graphPosY - arrow_size; tickYPos -= yAxisTickSizePixel) { diff --git a/src/InverterSettings.cpp b/src/InverterSettings.cpp index 21bf2d9..a52cdc0 100644 --- a/src/InverterSettings.cpp +++ b/src/InverterSettings.cpp @@ -25,6 +25,12 @@ InverterSettingsClass InverterSettings; +InverterSettingsClass::InverterSettingsClass() + : _settingsTask(INVERTER_UPDATE_SETTINGS_INTERVAL, TASK_FOREVER, std::bind(&InverterSettingsClass::settingsLoop, this)) + , _hoyTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&InverterSettingsClass::hoyLoop, this)) +{ +} + void InverterSettingsClass::init(Scheduler& scheduler) { const CONFIG_T& config = Configuration.get(); @@ -91,14 +97,9 @@ void InverterSettingsClass::init(Scheduler& scheduler) } scheduler.addTask(_hoyTask); - _hoyTask.setCallback(std::bind(&InverterSettingsClass::hoyLoop, this)); - _hoyTask.setIterations(TASK_FOREVER); _hoyTask.enable(); scheduler.addTask(_settingsTask); - _settingsTask.setCallback(std::bind(&InverterSettingsClass::settingsLoop, this)); - _settingsTask.setIterations(TASK_FOREVER); - _settingsTask.setInterval(INVERTER_UPDATE_SETTINGS_INTERVAL); _settingsTask.enable(); } @@ -119,7 +120,7 @@ void InverterSettingsClass::settingsLoop() inv->setEnablePolling(inv_cfg.Poll_Enable && (SunPosition.isDayPeriod() || inv_cfg.Poll_Enable_Night)); inv->setEnableCommands(inv_cfg.Command_Enable && (SunPosition.isDayPeriod() || inv_cfg.Command_Enable_Night)); } - } +} void InverterSettingsClass::hoyLoop() { diff --git a/src/Led_Single.cpp b/src/Led_Single.cpp index 744c7b7..40320b1 100644 --- a/src/Led_Single.cpp +++ b/src/Led_Single.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2023 Thomas Basler and others + * Copyright (C) 2023-2024 Thomas Basler and others */ #include "Led_Single.h" #include "Configuration.h" @@ -38,6 +38,8 @@ const uint8_t pwmTable[] = { #define LED_OFF 0 LedSingleClass::LedSingleClass() + : _setTask(LEDSINGLE_UPDATE_INTERVAL * TASK_MILLISECOND, TASK_FOREVER, std::bind(&LedSingleClass::setLoop, this)) + , _outputTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&LedSingleClass::outputLoop, this)) { } @@ -62,14 +64,9 @@ void LedSingleClass::init(Scheduler& scheduler) if (ledActive) { scheduler.addTask(_outputTask); - _outputTask.setCallback(std::bind(&LedSingleClass::outputLoop, this)); - _outputTask.setIterations(TASK_FOREVER); _outputTask.enable(); scheduler.addTask(_setTask); - _setTask.setCallback(std::bind(&LedSingleClass::setLoop, this)); - _setTask.setInterval(LEDSINGLE_UPDATE_INTERVAL * TASK_MILLISECOND); - _setTask.setIterations(TASK_FOREVER); _setTask.enable(); } } diff --git a/src/MessageOutput.cpp b/src/MessageOutput.cpp index f602bee..4ed1377 100644 --- a/src/MessageOutput.cpp +++ b/src/MessageOutput.cpp @@ -1,63 +1,66 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* - * Copyright (C) 2022-2023 Thomas Basler and others - */ -#include "MessageOutput.h" - -#include - -MessageOutputClass MessageOutput; - -void MessageOutputClass::init(Scheduler& scheduler) -{ - scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&MessageOutputClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); - _loopTask.enable(); -} - -void MessageOutputClass::register_ws_output(AsyncWebSocket* output) -{ - _ws = output; -} - -size_t MessageOutputClass::write(uint8_t c) -{ - if (_buff_pos < BUFFER_SIZE) { - std::lock_guard lock(_msgLock); - _buffer[_buff_pos] = c; - _buff_pos++; - } else { - _forceSend = true; - } - - return Serial.write(c); -} - -size_t MessageOutputClass::write(const uint8_t* buffer, size_t size) -{ - std::lock_guard lock(_msgLock); - if (_buff_pos + size < BUFFER_SIZE) { - memcpy(&_buffer[_buff_pos], buffer, size); - _buff_pos += size; - } - _forceSend = true; - - return Serial.write(buffer, size); -} - -void MessageOutputClass::loop() -{ - // Send data via websocket if either time is over or buffer is full - if (_forceSend || (millis() - _lastSend > 1000)) { - std::lock_guard lock(_msgLock); - if (_ws && _buff_pos > 0) { - _ws->textAll(_buffer, _buff_pos); - _buff_pos = 0; - } - if (_forceSend) { - _buff_pos = 0; - } - _forceSend = false; - } -} \ No newline at end of file +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2022-2024 Thomas Basler and others + */ +#include "MessageOutput.h" + +#include + +MessageOutputClass MessageOutput; + +MessageOutputClass::MessageOutputClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&MessageOutputClass::loop, this)) +{ +} + +void MessageOutputClass::init(Scheduler& scheduler) +{ + scheduler.addTask(_loopTask); + _loopTask.enable(); +} + +void MessageOutputClass::register_ws_output(AsyncWebSocket* output) +{ + _ws = output; +} + +size_t MessageOutputClass::write(uint8_t c) +{ + if (_buff_pos < BUFFER_SIZE) { + std::lock_guard lock(_msgLock); + _buffer[_buff_pos] = c; + _buff_pos++; + } else { + _forceSend = true; + } + + return Serial.write(c); +} + +size_t MessageOutputClass::write(const uint8_t* buffer, size_t size) +{ + std::lock_guard lock(_msgLock); + if (_buff_pos + size < BUFFER_SIZE) { + memcpy(&_buffer[_buff_pos], buffer, size); + _buff_pos += size; + } + _forceSend = true; + + return Serial.write(buffer, size); +} + +void MessageOutputClass::loop() +{ + // Send data via websocket if either time is over or buffer is full + if (_forceSend || (millis() - _lastSend > 1000)) { + std::lock_guard lock(_msgLock); + if (_ws && _buff_pos > 0) { + _ws->textAll(_buffer, _buff_pos); + _buff_pos = 0; + } + if (_forceSend) { + _buff_pos = 0; + } + _forceSend = false; + } +} diff --git a/src/MqttHandleDtu.cpp b/src/MqttHandleDtu.cpp index c20ddb1..e8192b2 100644 --- a/src/MqttHandleDtu.cpp +++ b/src/MqttHandleDtu.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ #include "MqttHandleDtu.h" #include "Configuration.h" @@ -10,11 +10,14 @@ MqttHandleDtuClass MqttHandleDtu; +MqttHandleDtuClass::MqttHandleDtuClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&MqttHandleDtuClass::loop, this)) +{ +} + void MqttHandleDtuClass::init(Scheduler& scheduler) { scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&MqttHandleDtuClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.setInterval(Configuration.get().Mqtt.PublishInterval * TASK_SECOND); _loopTask.enable(); } @@ -35,4 +38,4 @@ void MqttHandleDtuClass::loop() MqttSettings.publish("dtu/rssi", String(WiFi.RSSI())); MqttSettings.publish("dtu/bssid", WiFi.BSSIDstr()); } -} \ No newline at end of file +} diff --git a/src/MqttHandleHass.cpp b/src/MqttHandleHass.cpp index 4f1e08a..1df7237 100644 --- a/src/MqttHandleHass.cpp +++ b/src/MqttHandleHass.cpp @@ -11,11 +11,14 @@ MqttHandleHassClass MqttHandleHass; +MqttHandleHassClass::MqttHandleHassClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&MqttHandleHassClass::loop, this)) +{ +} + void MqttHandleHassClass::init(Scheduler& scheduler) { scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&MqttHandleHassClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.enable(); } @@ -53,7 +56,7 @@ void MqttHandleHassClass::publishConfig() const CONFIG_T& config = Configuration.get(); - // publish DTU sensors + // publish DTU sensors publishDtuSensor("IP", "", "diagnostic", "mdi:network-outline", "", ""); publishDtuSensor("WiFi Signal", "signal_strength", "diagnostic", "", "dBm", "rssi"); publishDtuSensor("Uptime", "duration", "diagnostic", "", "s", ""); diff --git a/src/MqttHandleInverter.cpp b/src/MqttHandleInverter.cpp index 0c1676e..53cf490 100644 --- a/src/MqttHandleInverter.cpp +++ b/src/MqttHandleInverter.cpp @@ -18,6 +18,11 @@ MqttHandleInverterClass MqttHandleInverter; +MqttHandleInverterClass::MqttHandleInverterClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&MqttHandleInverterClass::loop, this)) +{ +} + void MqttHandleInverterClass::init(Scheduler& scheduler) { using std::placeholders::_1; @@ -36,8 +41,6 @@ void MqttHandleInverterClass::init(Scheduler& scheduler) MqttSettings.subscribe(String(topic + "+/cmd/" + TOPIC_SUB_RESTART), 0, std::bind(&MqttHandleInverterClass::onMqttMessage, this, _1, _2, _3, _4, _5, _6)); scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&MqttHandleInverterClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.setInterval(Configuration.get().Mqtt.PublishInterval * TASK_SECOND); _loopTask.enable(); } diff --git a/src/MqttHandleInverterTotal.cpp b/src/MqttHandleInverterTotal.cpp index db584b2..5f5be6a 100644 --- a/src/MqttHandleInverterTotal.cpp +++ b/src/MqttHandleInverterTotal.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2023 Thomas Basler and others + * Copyright (C) 2023-2024 Thomas Basler and others */ #include "MqttHandleInverterTotal.h" #include "Configuration.h" @@ -10,11 +10,14 @@ MqttHandleInverterTotalClass MqttHandleInverterTotal; +MqttHandleInverterTotalClass::MqttHandleInverterTotalClass() + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&MqttHandleInverterTotalClass::loop, this)) +{ +} + void MqttHandleInverterTotalClass::init(Scheduler& scheduler) { scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&MqttHandleInverterTotalClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.setInterval(Configuration.get().Mqtt.PublishInterval * TASK_SECOND); _loopTask.enable(); } diff --git a/src/NetworkSettings.cpp b/src/NetworkSettings.cpp index c8004f1..59ce8f7 100644 --- a/src/NetworkSettings.cpp +++ b/src/NetworkSettings.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2022-2023 Thomas Basler and others + * Copyright (C) 2022-2024 Thomas Basler and others */ #include "NetworkSettings.h" #include "Configuration.h" @@ -12,7 +12,8 @@ #include NetworkSettingsClass::NetworkSettingsClass() - : _apIp(192, 168, 4, 1) + : _loopTask(TASK_IMMEDIATE, TASK_FOREVER, std::bind(&NetworkSettingsClass::loop, this)) + , _apIp(192, 168, 4, 1) , _apNetmask(255, 255, 255, 0) { _dnsServer.reset(new DNSServer()); @@ -29,8 +30,6 @@ void NetworkSettingsClass::init(Scheduler& scheduler) setupMode(); scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&NetworkSettingsClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); _loopTask.enable(); } diff --git a/src/SunPosition.cpp b/src/SunPosition.cpp index a3a9f47..f1e1bee 100644 --- a/src/SunPosition.cpp +++ b/src/SunPosition.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2023 Thomas Basler and others + * Copyright (C) 2023-2024 Thomas Basler and others */ #include "SunPosition.h" #include "Configuration.h" @@ -10,15 +10,13 @@ SunPositionClass SunPosition; SunPositionClass::SunPositionClass() + : _loopTask(5 * TASK_SECOND, TASK_FOREVER, std::bind(&SunPositionClass::loop, this)) { } void SunPositionClass::init(Scheduler& scheduler) { scheduler.addTask(_loopTask); - _loopTask.setCallback(std::bind(&SunPositionClass::loop, this)); - _loopTask.setIterations(TASK_FOREVER); - _loopTask.setInterval(5 * TASK_SECOND); _loopTask.enable(); } diff --git a/src/WebApi_dtu.cpp b/src/WebApi_dtu.cpp index d2100ad..7886afc 100644 --- a/src/WebApi_dtu.cpp +++ b/src/WebApi_dtu.cpp @@ -9,6 +9,11 @@ #include #include +WebApiDtuClass::WebApiDtuClass() + : _applyDataTask(TASK_IMMEDIATE, TASK_ONCE, std::bind(&WebApiDtuClass::applyDataTaskCb, this)) +{ +} + void WebApiDtuClass::init(AsyncWebServer& server, Scheduler& scheduler) { using std::placeholders::_1; @@ -19,8 +24,6 @@ void WebApiDtuClass::init(AsyncWebServer& server, Scheduler& scheduler) _server->on("/api/dtu/config", HTTP_POST, std::bind(&WebApiDtuClass::onDtuAdminPost, this, _1)); scheduler.addTask(_applyDataTask); - _applyDataTask.setCallback(std::bind(&WebApiDtuClass::applyDataTaskCb, this)); - _applyDataTask.setIterations(TASK_ONCE); } void WebApiDtuClass::applyDataTaskCb() diff --git a/src/WebApi_ws_console.cpp b/src/WebApi_ws_console.cpp index 4a9d87e..aaca6d8 100644 --- a/src/WebApi_ws_console.cpp +++ b/src/WebApi_ws_console.cpp @@ -10,6 +10,7 @@ WebApiWsConsoleClass::WebApiWsConsoleClass() : _ws("/console") + , _wsCleanupTask(1 * TASK_SECOND, TASK_FOREVER, std::bind(&WebApiWsConsoleClass::wsCleanupTaskCb, this)) { } @@ -20,9 +21,6 @@ void WebApiWsConsoleClass::init(AsyncWebServer& server, Scheduler& scheduler) MessageOutput.register_ws_output(&_ws); scheduler.addTask(_wsCleanupTask); - _wsCleanupTask.setCallback(std::bind(&WebApiWsConsoleClass::wsCleanupTaskCb, this)); - _wsCleanupTask.setIterations(TASK_FOREVER); - _wsCleanupTask.setInterval(1 * TASK_SECOND); _wsCleanupTask.enable(); } diff --git a/src/WebApi_ws_live.cpp b/src/WebApi_ws_live.cpp index 708a9a6..26a2965 100644 --- a/src/WebApi_ws_live.cpp +++ b/src/WebApi_ws_live.cpp @@ -13,6 +13,8 @@ WebApiWsLiveClass::WebApiWsLiveClass() : _ws("/livedata") + , _wsCleanupTask(1 * TASK_SECOND, TASK_FOREVER, std::bind(&WebApiWsLiveClass::wsCleanupTaskCb, this)) + , _sendDataTask(1 * TASK_SECOND, TASK_FOREVER, std::bind(&WebApiWsLiveClass::sendDataTaskCb, this)) { } @@ -32,15 +34,9 @@ void WebApiWsLiveClass::init(AsyncWebServer& server, Scheduler& scheduler) _ws.onEvent(std::bind(&WebApiWsLiveClass::onWebsocketEvent, this, _1, _2, _3, _4, _5, _6)); scheduler.addTask(_wsCleanupTask); - _wsCleanupTask.setCallback(std::bind(&WebApiWsLiveClass::wsCleanupTaskCb, this)); - _wsCleanupTask.setIterations(TASK_FOREVER); - _wsCleanupTask.setInterval(1 * TASK_SECOND); _wsCleanupTask.enable(); scheduler.addTask(_sendDataTask); - _sendDataTask.setCallback(std::bind(&WebApiWsLiveClass::sendDataTaskCb, this)); - _sendDataTask.setIterations(TASK_FOREVER); - _sendDataTask.setInterval(1 * TASK_SECOND); _sendDataTask.enable(); }