Added api endpoints, IO view and minor other things

This commit is contained in:
anschrammh 2019-04-23 08:04:18 +02:00
parent ff6f083865
commit c20e89f1e9

View File

@ -5,6 +5,7 @@
#include "webApi.h" #include "webApi.h"
#include "CFGDictionary.h" #include "CFGDictionary.h"
#include "CFGParameterValue.h" #include "CFGParameterValue.h"
#define DEBUG
SAB sab; SAB sab;
@ -12,13 +13,12 @@ unsigned long currentMs = 0, batteryMs = 0, buttonMs = 0;
View1Packet v1p = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().getSize(GBYTE), sab.getPowerInfo(),0}; View1Packet v1p = {sab.getRtcManager().getDateTime(), sab.getSdCardManager().getSize(GBYTE), sab.getPowerInfo(),0};
ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum()}; ViewAPPacket vap = {sab.getConnectivityManager().softAPmacAddress(), sab.getConnectivityManager().softAPSSID(), sab.getConnectivityManager().softAPIP(), sab.getConnectivityManager().softAPgetStationNum()};
ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI()}; ViewSTAPacket vstap = {sab.getConnectivityManager().macAddress(), sab.getConnectivityManager().localIP(), sab.getConnectivityManager().RSSI()};
ViewIoInfoPacket vio = {{0}};
SdCardApiPacket sdCardApiPacket = {NULL, NULL}; SdCardApiPacket sdCardApiPacket = {NULL, NULL};
void setup() void setup()
{ {
// put your setup code here, to run once: // put your setup code here, to run once:
pinMode(GPIO_0, INPUT);
Serial.println("Starting setup"); Serial.println("Starting setup");
CFGFileParser cfgFileParser(sab.getSdCardManager(), AP_CFG_FILE); CFGFileParser cfgFileParser(sab.getSdCardManager(), AP_CFG_FILE);
CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile(); CFGDictionary<CFGParameterValue> *cfgDictionary = (CFGDictionary<CFGParameterValue> *) cfgFileParser.parseFile();
@ -40,8 +40,9 @@ void setup()
sab.getScreenManager().addView(&(view_2), &vap, 1); sab.getScreenManager().addView(&(view_2), &vap, 1);
sab.getScreenManager().addView(&(view_3), &vstap, 2); sab.getScreenManager().addView(&(view_3), &vstap, 2);
sab.getScreenManager().addView(&(memInfo), NULL, 3); sab.getScreenManager().addView(&(memInfo), NULL, 3);
sab.getScreenManager().addView(NULL, NULL, 4); //for testin purposes sab.getScreenManager().addView(&(ioInfo), &vio, 4);
sab.getScreenManager().addView(&(dummy), NULL, 5); //for testin purposes sab.getScreenManager().addView(NULL, NULL, 5); //for testing purposes
sab.getScreenManager().addView(&(dummy), NULL, 6); //for testing purposes
sab.getScreenManager().displayView(0); sab.getScreenManager().displayView(0);
if(sab.getRtcManager().hasLostPower()) if(sab.getRtcManager().hasLostPower())
@ -64,13 +65,18 @@ void setup()
sab.getWebServerManager().addApiRoutine("/esp/reset", &(espResetApi), NULL, WEBServerManager::GET); sab.getWebServerManager().addApiRoutine("/esp/reset", &(espResetApi), NULL, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/wifi/stainfo", &(staWifiInfoApi), &sab, WEBServerManager::GET); sab.getWebServerManager().addApiRoutine("/sab/wifi/stainfo", &(staWifiInfoApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/systeminfo", &(systemInfoApi), &sab, WEBServerManager::GET); sab.getWebServerManager().addApiRoutine("/sab/systeminfo", &(systemInfoApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/io/get/level", &(ioGetLevelApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/io/set/level", &(ioSetLevelApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/io/get/mode", &(ioGetModeApi), &sab, WEBServerManager::GET);
sab.getWebServerManager().addApiRoutine("/sab/io/set/mode", &(ioSetModeApi), &sab, WEBServerManager::GET);
Serial.println("End setup"); Serial.println("End setup");
} }
void loop() void loop()
{ {
if(millis() - currentMs > 1000) if(millis() - currentMs > 100)
{ {
currentMs = millis(); currentMs = millis();
v1p.dateTime = sab.getRtcManager().getDateTime(); v1p.dateTime = sab.getRtcManager().getDateTime();
@ -82,6 +88,8 @@ void loop()
vstap.ipAddr = sab.getConnectivityManager().localIP(); vstap.ipAddr = sab.getConnectivityManager().localIP();
vstap.sigStrength = sab.getConnectivityManager().RSSI(); vstap.sigStrength = sab.getConnectivityManager().RSSI();
sab.getIoManager().getPcf().digitalReadAll(vio.ioState);
sab.getScreenManager().displayView(); sab.getScreenManager().displayView();
} }
@ -95,10 +103,11 @@ void loop()
if(digitalRead(GPIO_0) == 0 && millis() - buttonMs > 500) if(digitalRead(GPIO_0) == 0 && millis() - buttonMs > 500)
{ {
buttonMs = millis(); buttonMs = millis();
sab.getScreenManager().displayNextView();
#ifdef DEBUG
Serial.println("Changing view"); Serial.println("Changing view");
Serial.print("Selected view is : ");Serial.println(sab.getScreenManager().getCurrentViewUID()); Serial.print("Selected view is : ");Serial.println(sab.getScreenManager().getCurrentViewUID());
#endif
sab.getScreenManager().displayNextView();
} }
//Run the webServer //Run the webServer