Migrate Datastore to TaskScheduler
This commit is contained in:
parent
12031ed09e
commit
c045b5df48
@ -1,13 +1,12 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <TimeoutHelper.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
class DatastoreClass {
|
class DatastoreClass {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init(Scheduler* scheduler);
|
||||||
void loop();
|
|
||||||
|
|
||||||
// Sum of yield total of all enabled inverters, a inverter which is just disabled at night is also included
|
// Sum of yield total of all enabled inverters, a inverter which is just disabled at night is also included
|
||||||
float getTotalAcYieldTotalEnabled();
|
float getTotalAcYieldTotalEnabled();
|
||||||
@ -58,7 +57,10 @@ public:
|
|||||||
bool getIsAllEnabledReachable();
|
bool getIsAllEnabledReachable();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimeoutHelper _updateTimeout;
|
void loop();
|
||||||
|
|
||||||
|
Task _loopTask;
|
||||||
|
|
||||||
std::mutex _mutex;
|
std::mutex _mutex;
|
||||||
|
|
||||||
float _totalAcYieldTotalEnabled = 0;
|
float _totalAcYieldTotalEnabled = 0;
|
||||||
|
|||||||
@ -8,14 +8,21 @@
|
|||||||
|
|
||||||
DatastoreClass Datastore;
|
DatastoreClass Datastore;
|
||||||
|
|
||||||
void DatastoreClass::init()
|
void DatastoreClass::init(Scheduler* scheduler)
|
||||||
{
|
{
|
||||||
_updateTimeout.set(1000);
|
scheduler->addTask(_loopTask);
|
||||||
|
_loopTask.setCallback(std::bind(&DatastoreClass::loop, this));
|
||||||
|
_loopTask.setIterations(TASK_FOREVER);
|
||||||
|
_loopTask.setInterval(1 * TASK_SECOND);
|
||||||
|
_loopTask.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatastoreClass::loop()
|
void DatastoreClass::loop()
|
||||||
{
|
{
|
||||||
if (Hoymiles.isAllRadioIdle() && _updateTimeout.occured()) {
|
if (!Hoymiles.isAllRadioIdle()) {
|
||||||
|
_loopTask.forceNextIteration();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t isProducing = 0;
|
uint8_t isProducing = 0;
|
||||||
uint8_t isReachable = 0;
|
uint8_t isReachable = 0;
|
||||||
@ -104,9 +111,6 @@ void DatastoreClass::loop()
|
|||||||
_isAtLeastOnePollEnabled = pollEnabledCount > 0;
|
_isAtLeastOnePollEnabled = pollEnabledCount > 0;
|
||||||
|
|
||||||
_totalDcIrradiation = _totalDcIrradiationInstalled > 0 ? _totalDcPowerIrradiation / _totalDcIrradiationInstalled * 100.0f : 0;
|
_totalDcIrradiation = _totalDcIrradiationInstalled > 0 ? _totalDcPowerIrradiation / _totalDcIrradiationInstalled * 100.0f : 0;
|
||||||
|
|
||||||
_updateTimeout.reset();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float DatastoreClass::getTotalAcYieldTotalEnabled()
|
float DatastoreClass::getTotalAcYieldTotalEnabled()
|
||||||
|
|||||||
@ -146,7 +146,7 @@ void setup()
|
|||||||
|
|
||||||
InverterSettings.init();
|
InverterSettings.init();
|
||||||
|
|
||||||
Datastore.init();
|
Datastore.init(&scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
@ -157,8 +157,6 @@ void loop()
|
|||||||
yield();
|
yield();
|
||||||
InverterSettings.loop();
|
InverterSettings.loop();
|
||||||
yield();
|
yield();
|
||||||
Datastore.loop();
|
|
||||||
yield();
|
|
||||||
MqttHandleDtu.loop();
|
MqttHandleDtu.loop();
|
||||||
yield();
|
yield();
|
||||||
MqttHandleInverter.loop();
|
MqttHandleInverter.loop();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user