mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
49 lines
1.9 KiB
C++
49 lines
1.9 KiB
C++
#include "ESPConfiguration.h"
|
||
#include "classes/IoTGpio.h"
|
||
|
||
extern IoTGpio IoTgpio;
|
||
|
||
std::list<IoTItem*> IoTItems;
|
||
void* getAPI(String subtype, String params);
|
||
|
||
void configure(String path) {
|
||
File file = seekFile(path);
|
||
file.find("[");
|
||
while (file.available()) {
|
||
String jsonArrayElement = file.readStringUntil('}') + "}";
|
||
if (jsonArrayElement.startsWith(",")) {
|
||
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
||
}
|
||
if (jsonArrayElement == "]}") {
|
||
jsonArrayElement = "";
|
||
}
|
||
if (jsonArrayElement != "") {
|
||
String subtype;
|
||
if (!jsonRead(jsonArrayElement, F("subtype"), subtype)) { //если нет такого ключа в представленном json или он не валидный
|
||
SerialPrint(F("E"), F("Config"), "json error " + subtype);
|
||
continue;
|
||
} else {
|
||
//(IoTItem*) - getAPI вернула ссылку, что бы ее привести к классу IoTItem используем
|
||
myIoTItem = (IoTItem*)getAPI(subtype, jsonArrayElement);
|
||
if (myIoTItem) {
|
||
void* driver;
|
||
// пробуем спросить драйвер GPIO
|
||
if (driver = myIoTItem->getGpioDriver()) IoTgpio.regDriver((IoTGpio*)driver);
|
||
|
||
IoTItems.push_back(myIoTItem);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
file.close();
|
||
SerialPrint("i", "Config", "Configured");
|
||
}
|
||
|
||
void clearConfigure() {
|
||
Serial.printf("Start clearing config\n");
|
||
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
||
Serial.printf("Start delete iotitem %s \n", (*it)->getID().c_str());
|
||
if (*it) delete *it;
|
||
}
|
||
IoTItems.clear();
|
||
} |