Migrate NetworkSettings to TaskScheduler
This commit is contained in:
parent
7881d955bd
commit
1501411037
@ -2,6 +2,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <DNSServer.h>
|
||||
#include <TaskSchedulerDeclarations.h>
|
||||
#include <WiFi.h>
|
||||
#include <vector>
|
||||
|
||||
@ -38,8 +39,7 @@ typedef struct NetworkEventCbList {
|
||||
class NetworkSettingsClass {
|
||||
public:
|
||||
NetworkSettingsClass();
|
||||
void init();
|
||||
void loop();
|
||||
void init(Scheduler* scheduler);
|
||||
void applyConfig();
|
||||
void enableAdminMode();
|
||||
String getApName();
|
||||
@ -57,11 +57,15 @@ public:
|
||||
void raiseEvent(network_event event);
|
||||
|
||||
private:
|
||||
void loop();
|
||||
void setHostname();
|
||||
void setStaticIp();
|
||||
void handleMDNS();
|
||||
void setupMode();
|
||||
void NetworkEvent(WiFiEvent_t event);
|
||||
|
||||
Task _loopTask;
|
||||
|
||||
bool adminEnabled = true;
|
||||
bool forceDisconnection = false;
|
||||
uint32_t adminTimeoutCounter = 0;
|
||||
|
||||
@ -18,7 +18,7 @@ NetworkSettingsClass::NetworkSettingsClass()
|
||||
dnsServer.reset(new DNSServer());
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::init()
|
||||
void NetworkSettingsClass::init(Scheduler* scheduler)
|
||||
{
|
||||
using std::placeholders::_1;
|
||||
|
||||
@ -27,6 +27,11 @@ void NetworkSettingsClass::init()
|
||||
|
||||
WiFi.onEvent(std::bind(&NetworkSettingsClass::NetworkEvent, this, _1));
|
||||
setupMode();
|
||||
|
||||
scheduler->addTask(_loopTask);
|
||||
_loopTask.setCallback(std::bind(&NetworkSettingsClass::loop, this));
|
||||
_loopTask.setIterations(TASK_FOREVER);
|
||||
_loopTask.enable();
|
||||
}
|
||||
|
||||
void NetworkSettingsClass::NetworkEvent(WiFiEvent_t event)
|
||||
|
||||
@ -82,7 +82,7 @@ void setup()
|
||||
|
||||
// Initialize WiFi
|
||||
MessageOutput.print("Initialize Network... ");
|
||||
NetworkSettings.init();
|
||||
NetworkSettings.init(&scheduler);
|
||||
MessageOutput.println("done");
|
||||
NetworkSettings.applyConfig();
|
||||
|
||||
@ -153,8 +153,6 @@ void loop()
|
||||
{
|
||||
scheduler.execute();
|
||||
|
||||
NetworkSettings.loop();
|
||||
yield();
|
||||
InverterSettings.loop();
|
||||
yield();
|
||||
WebApi.loop();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user