Skip to content

Commit

Permalink
Migrate InverterSettings to TaskScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
tbnobody committed Nov 23, 2023
1 parent 1501411 commit 77779a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions include/InverterSettings.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <TaskSchedulerDeclarations.h>
#include <cstdint>

#define INVERTER_UPDATE_SETTINGS_INTERVAL 60000l

class InverterSettingsClass {
public:
void init();
void loop();
void init(Scheduler* scheduler);

private:
void loop();

Task _loopTask;

uint32_t _lastUpdate = 0;
};

Expand Down
7 changes: 6 additions & 1 deletion src/InverterSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

InverterSettingsClass InverterSettings;

void InverterSettingsClass::init()
void InverterSettingsClass::init(Scheduler* scheduler)
{
const CONFIG_T& config = Configuration.get();
const PinMapping_t& pin = PinMapping.get();
Expand Down Expand Up @@ -87,6 +87,11 @@ void InverterSettingsClass::init()
} else {
MessageOutput.println("Invalid pin config");
}

scheduler->addTask(_loopTask);
_loopTask.setCallback(std::bind(&InverterSettingsClass::loop, this));
_loopTask.setIterations(TASK_FOREVER);
_loopTask.enable();
}

void InverterSettingsClass::loop()
Expand Down
4 changes: 1 addition & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void setup()
}
MessageOutput.println("done");

InverterSettings.init();
InverterSettings.init(&scheduler);

Datastore.init(&scheduler);
}
Expand All @@ -153,8 +153,6 @@ void loop()
{
scheduler.execute();

InverterSettings.loop();
yield();
WebApi.loop();
yield();
Display.loop();
Expand Down

0 comments on commit 77779a1

Please sign in to comment.