Files
IoTManager/include/items/SensorAnalogClass.h
Dmitry Borisenko a5171f1178 Optimization
2020-10-20 22:55:45 +03:00

36 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
#include "items/SensorConvertingClass.h"
class SensorAnalogClass : public SensorConvertingClass {
public:
SensorAnalogClass() : SensorConvertingClass(){};
void SensorAnalogInit() {
jsonWriteStr(configOptionJson, _key + "_pin", _pin);
jsonWriteStr(configOptionJson, _key + "_map", _map);
jsonWriteStr(configOptionJson, _key + "_с", _c);
}
int SensorAnalogRead(String key, String pin) {
int value;
#ifdef ESP32
int pinInt = pin.toInt();
value = analogRead(pinInt);
#endif
#ifdef ESP8266
value = analogRead(A0);
#endif
value = this->mapping(key, value);
float valueFl = this->correction(key, value);
eventGen(key, "");
jsonWriteStr(configLiveJson, key, String(valueFl));
publishStatus(key, String(valueFl));
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
return value;
}
};
extern SensorAnalogClass mySensorAnalog;