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