mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
progress
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/JsonUtils.h"
|
||||
|
||||
class LineParsing {
|
||||
protected:
|
||||
@@ -49,7 +50,7 @@ class LineParsing {
|
||||
if (i == 5) _order = sCmd.next();
|
||||
}
|
||||
|
||||
for (int i = 1; i < 6; i++) {
|
||||
for (int i = 1; i < 10; i++) {
|
||||
String arg = sCmd.next();
|
||||
if (arg != "") {
|
||||
if (arg.indexOf("pin[") != -1) {
|
||||
@@ -64,16 +65,24 @@ class LineParsing {
|
||||
if (arg.indexOf("db[") != -1) {
|
||||
_db = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("map[") != -1) {
|
||||
_map = extractInner(arg);
|
||||
}
|
||||
if (arg.indexOf("c[") != -1) {
|
||||
_c = extractInner(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_page.replace("#", " ");
|
||||
|
||||
_descr.replace("#", " ");
|
||||
_descr.replace("#", " ");
|
||||
|
||||
createWidgetClass(_descr, _page, _order, _file, _key);
|
||||
}
|
||||
|
||||
//jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
||||
|
||||
String gkey() {
|
||||
return _key;
|
||||
}
|
||||
@@ -90,14 +99,20 @@ class LineParsing {
|
||||
return _order;
|
||||
}
|
||||
String gpin() {
|
||||
return _pin;
|
||||
return _pin; //
|
||||
}
|
||||
String ginv() {
|
||||
return _inv;
|
||||
return _inv; //
|
||||
}
|
||||
String gstate() {
|
||||
return _state;
|
||||
}
|
||||
String gmap() {
|
||||
return _map;
|
||||
}
|
||||
String gc() {
|
||||
return _c;
|
||||
}
|
||||
|
||||
void clear() {
|
||||
_key = "";
|
||||
@@ -150,4 +165,13 @@ class LineParsing {
|
||||
const String getWidgetFileClass(const String& name) {
|
||||
return "/widgets/" + name + ".json";
|
||||
}
|
||||
|
||||
//String jsonWriteStr1(String& json, String name, String value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
};
|
||||
|
||||
@@ -6,16 +6,11 @@
|
||||
#include "Class/SensorConverting.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorAnalog : public LineParsing,
|
||||
public SensorConverting {
|
||||
class SensorAnalog : public SensorConverting {
|
||||
public:
|
||||
SensorAnalog() : LineParsing(),
|
||||
SensorConverting(){};
|
||||
SensorAnalog() : SensorConverting(){};
|
||||
|
||||
void SensorAnalogInit() {
|
||||
//if (_pin != "") {
|
||||
// pinMode(_pin.toInt(), INPUT);
|
||||
//}
|
||||
void SensorAnalogInit(String key) {
|
||||
}
|
||||
|
||||
int SensorAnalogRead(String key, String pin) {
|
||||
@@ -28,15 +23,16 @@ class SensorAnalog : public LineParsing,
|
||||
pinInt = pinInt;
|
||||
value = analogRead(A0);
|
||||
#endif
|
||||
float valueFl;
|
||||
//float valueFl = this->mapping(value);
|
||||
// valueFl = this->correction(valueFl);
|
||||
|
||||
eventGen(key, "");
|
||||
jsonWriteFloat(configLiveJson, key, valueFl);
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
value = this->mapping(key, value);
|
||||
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
eventGen(key, "");
|
||||
jsonWriteFloat(configLiveJson, key, value);
|
||||
MqttClient::publishStatus(key, String(value));
|
||||
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(value));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,20 +9,21 @@ class SensorConverting : public LineParsing {
|
||||
public:
|
||||
SensorConverting() : LineParsing(){};
|
||||
|
||||
int mapping(int input) {
|
||||
if (_map != "") {
|
||||
_map.replace("map[", "");
|
||||
_map.replace("]", "");
|
||||
int mapping(String key, int input) {
|
||||
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
||||
if (map_ != "") {
|
||||
map_.replace("map[", "");
|
||||
map_.replace("]", "");
|
||||
input = map(input,
|
||||
selectFromMarkerToMarker(_map, ",", 0).toInt(),
|
||||
selectFromMarkerToMarker(_map, ",", 1).toInt(),
|
||||
selectFromMarkerToMarker(_map, ",", 2).toInt(),
|
||||
selectFromMarkerToMarker(_map, ",", 3).toInt());
|
||||
selectFromMarkerToMarker(map_, ",", 0).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 1).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 2).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 3).toInt());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
float correction(float input) {
|
||||
float correction(String key, float input) {
|
||||
_c.replace("c[", "");
|
||||
_c.replace("]", "");
|
||||
float coef = _c.toFloat();
|
||||
|
||||
Reference in New Issue
Block a user