progress of sensors

This commit is contained in:
Dmitry Borisenko
2020-08-28 03:25:13 +03:00
parent c473f616b6
commit 0c1a1940d2
5 changed files with 44 additions and 9 deletions

View File

@@ -1 +1 @@
analog-adc;id;anydata;Сенсоры;Аналоговый;order;pin[0];map[1,100,1,100];c[0]
analog-adc;id;anydata;Сенсоры;Аналоговый;order;pin-adc;map[1,100,1,100];c[0]

View File

@@ -3,9 +3,10 @@
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Class/SensorConverting.h"
#include "Global.h"
class SensorAnalog : public LineParsing {
class SensorAnalog : public LineParsing public SensorConverting {
public:
SensorAnalog() : LineParsing(){};
@@ -29,6 +30,8 @@ class SensorAnalog : public LineParsing {
eventGen(key, "");
jsonWriteInt(configLiveJson, key, value);
MqttClient::publishStatus(key, String(value));
Serial.println("[I] sensor '" + key + "' data: " + String(value));
return value;
}
};

View File

@@ -0,0 +1,20 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class SensorConverting : public LineParsing {
public:
SensorConverting() : LineParsing(){};
void SensorConvertingInit() {
}
};
extern SensorConverting* mySensorConverting;

View File

@@ -6,4 +6,5 @@
extern void addItem(String name);
extern void delAllItems();
extern uint8_t getNewElementNumber(String file);
extern uint8_t getFreePin();
extern uint8_t getFreePinAll();
extern uint8_t getFreePinAnalog();

View File

@@ -1,4 +1,5 @@
#include "ItemsList.h"
#include "Utils\StringUtils.h"
static const char* firstLine PROGMEM = "Тип элемента;Id;Виджет;Имя вкладки;Имя виджета;Позиция виджета";
@@ -8,7 +9,11 @@ void addItem(String name) {
name = deleteToMarkerLast(name, "-");
item.replace("id", name + String(getNewElementNumber("id.txt")));
item.replace("order", String(getNewElementNumber("order.txt")));
item.replace("pin", "pin[" + String(getFreePin()) + "]");
if (item.indexOf("pin-adc") != -1) {
item.replace("pin-adc", "pin[" + String(getFreePinAnalog()) + "]");
} else if (item.indexOf("pin") != -1) {
item.replace("pin", "pin[" + String(getFreePinAll()) + "]");
}
item.replace("\r\n", "");
item.replace("\r", "");
item.replace("\n", "");
@@ -31,13 +36,13 @@ uint8_t getNewElementNumber(String file) {
return number;
}
uint8_t getFreePin() {
#ifdef ESP8266
uint8_t getFreePinAll() {
#ifdef ESP8266
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
#endif
#ifdef ESP32
#endif
#ifdef ESP32
uint8_t pins[] = {0, 12, 13, 14, 15, 16, 1, 2, 3, 4, 5};
#endif
#endif
uint8_t array_sz = sizeof(pins) / sizeof(pins[0]);
uint8_t i = getNewElementNumber("pins.txt");
if (i < array_sz) {
@@ -47,6 +52,12 @@ uint8_t getFreePin() {
}
}
uint8_t getFreePinAnalog() {
#ifdef ESP8266
return 0;
#endif
}
//void do_getJsonListFromCsv() {
// if (getJsonListFromCsvFlag) {
// getJsonListFromCsvFlag = false;