mirror of
https://github.com/Laxilef/OTGateway.git
synced 2026-12-03 03:33:03 +05:00
refactor: simplify task configuration and registration
This commit is contained in:
1 parent
d19f6aaa52
commit
4004927ecd
9 files changed
+38
-55
No files matched your search
+13
-11
@@ -963,16 +963,18 @@ void initSensors() {
|
||||
|
||||
pollDhtSensorsTask.setInterval(1000)
|
||||
.setEnabledWhen([] {
|
||||
return canRunSensors() &&
|
||||
(Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
|
||||
Sensors::getAmountByType(Sensors::Type::DHT22, true));
|
||||
return canRunSensors() && (
|
||||
Sensors::getAmountByType(Sensors::Type::DHT11, true) ||
|
||||
Sensors::getAmountByType(Sensors::Type::DHT22, true)
|
||||
);
|
||||
});
|
||||
sensorsTaskManager.addTask(pollDhtSensorsTask);
|
||||
|
||||
maintainDallasSensorsTask.setEnabledWhen([] {
|
||||
return canRunSensors() &&
|
||||
(!dallasInstances.empty() ||
|
||||
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true));
|
||||
return canRunSensors() && (
|
||||
!dallasInstances.empty() ||
|
||||
Sensors::getAmountByType(Sensors::Type::DALLAS_TEMP, true)
|
||||
);
|
||||
})
|
||||
.resume(15000);
|
||||
sensorsTaskManager.addTask(maintainDallasSensorsTask);
|
||||
@@ -985,9 +987,10 @@ void initSensors() {
|
||||
|
||||
#if USE_BLE
|
||||
scanBleSensorsTask.setEnabledWhen([] {
|
||||
return canRunSensors() &&
|
||||
(NimBLEDevice::isInitialized() ||
|
||||
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true));
|
||||
return canRunSensors() && (
|
||||
NimBLEDevice::isInitialized() ||
|
||||
Sensors::getAmountByType(Sensors::Type::BLUETOOTH, true)
|
||||
);
|
||||
})
|
||||
.onDone([](const Task&, uint32_t) {
|
||||
if (scanBleSensorsTask.interval() != 1000) {
|
||||
@@ -998,8 +1001,7 @@ void initSensors() {
|
||||
sensorsTaskManager.addTask(scanBleSensorsTask);
|
||||
#endif
|
||||
|
||||
updateSensorsTask.setInterval(1000)
|
||||
.setEnabledWhen(canRunSensors);
|
||||
updateSensorsTask.setInterval(1000).setEnabledWhen(canRunSensors);
|
||||
sensorsTaskManager.addTask(updateSensorsTask);
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user