mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
not working version
This commit is contained in:
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Input : public LineParsing {
|
||||
public:
|
||||
Input() : LineParsing(){};
|
||||
|
||||
void inputSetDefaultFloat() {
|
||||
inputSetFloat(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetDefaultStr() {
|
||||
inputSetStr(_key, _state);
|
||||
}
|
||||
|
||||
void inputSetFloat(String key, String state) {
|
||||
eventGen(key, "");
|
||||
jsonWriteFloat(configLiveJson, key, state.toFloat());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
|
||||
void inputSetStr(String key, String state) {
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Input* myInput;
|
||||
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class OutputModule : public LineParsing {
|
||||
public:
|
||||
OutputModule() : LineParsing(){};
|
||||
|
||||
void OutputModuleStateSetDefault() {
|
||||
if (_state != "") {
|
||||
OutputModuleChange(_key, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void OutputModuleChange(String key, String state) {
|
||||
state.replace("#", " ");
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, state);
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
extern OutputModule* myText;
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Pwm : public LineParsing {
|
||||
public:
|
||||
Pwm() : LineParsing(){};
|
||||
|
||||
void pwmModeSet() {
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), INPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void pwmStateSetDefault() {
|
||||
if (_state != "") {
|
||||
pwmChange(_key, _pin, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void pwmChange(String key, String pin, String state) {
|
||||
int pinInt = pin.toInt();
|
||||
analogWrite(pinInt, state.toInt());
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Pwm* myPwm;
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Class/SensorConverting.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorAnalog : public SensorConverting {
|
||||
public:
|
||||
SensorAnalog() : SensorConverting(){};
|
||||
|
||||
void SensorAnalogInit(String key) {
|
||||
}
|
||||
|
||||
int SensorAnalogRead(String key, String pin) {
|
||||
int pinInt = pin.toInt();
|
||||
int value;
|
||||
#ifdef ESP32
|
||||
value = analogRead(pinInt);
|
||||
#endif
|
||||
#ifdef ESP8266
|
||||
pinInt = pinInt;
|
||||
value = analogRead(A0);
|
||||
#endif
|
||||
value = this->mapping(key, value);
|
||||
float valueFl = this->correction(key, value);
|
||||
|
||||
eventGen(key, "");
|
||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorAnalog* mySensorAnalog;
|
||||
@@ -1,32 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorConverting : public LineParsing {
|
||||
public:
|
||||
SensorConverting() : LineParsing(){};
|
||||
|
||||
int mapping(String key, int input) {
|
||||
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
||||
if (map_ != "") {
|
||||
input = map(input,
|
||||
selectFromMarkerToMarker(map_, ",", 0).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 1).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 2).toInt(),
|
||||
selectFromMarkerToMarker(map_, ",", 3).toInt());
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
float correction(String key, float input) {
|
||||
String corr = jsonReadStr(configOptionJson, key + "_с");
|
||||
if (corr != "") {
|
||||
float coef = corr.toFloat();
|
||||
input = input * coef;
|
||||
}
|
||||
return input;
|
||||
}
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Switch : public LineParsing {
|
||||
protected:
|
||||
int numberEntering = 0;
|
||||
int state = _state.toInt();
|
||||
|
||||
public:
|
||||
Switch() : LineParsing(){};
|
||||
|
||||
void init() {
|
||||
if (_pin != "") {
|
||||
int number = numberEntering++;
|
||||
buttons[number].attach(_pin.toInt());
|
||||
buttons[number].interval(_db.toInt());
|
||||
but[number] = true;
|
||||
jsonWriteStr(configOptionJson, "switch_num_" + String(number), _key);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
static uint8_t switch_number = 1;
|
||||
if (but[switch_number]) {
|
||||
buttons[switch_number].update();
|
||||
if (buttons[switch_number].fell()) {
|
||||
}
|
||||
if (buttons[switch_number].rose()) {
|
||||
String key = jsonReadStr(configOptionJson, "switch_num_" + String(switch_number));
|
||||
state = !state;
|
||||
switchChangeVirtual(key, String(state));
|
||||
}
|
||||
}
|
||||
switch_number++;
|
||||
if (switch_number == NUM_BUTTONS) {
|
||||
switch_number = 0;
|
||||
}
|
||||
}
|
||||
void switchStateSetDefault() {
|
||||
if (_state != "") {
|
||||
switchChangeVirtual(_key, _state);
|
||||
}
|
||||
}
|
||||
|
||||
void switchChangeVirtual(String key, String state) {
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Switch* mySwitch;
|
||||
@@ -1,43 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class Button1 : public LineParsing {
|
||||
public:
|
||||
Button1() : LineParsing(){};
|
||||
|
||||
void pinModeSet() {
|
||||
if (_pin != "") {
|
||||
pinMode(_pin.toInt(), OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void pinStateSetDefault() {
|
||||
if (_inv == "" && _state != "") {
|
||||
pinChange(_key, _pin, _state, true);
|
||||
}
|
||||
}
|
||||
|
||||
void pinStateSetInvDefault() {
|
||||
if (_inv != "" && _state != "") {
|
||||
pinChange(_key, _pin, _state, false);
|
||||
}
|
||||
}
|
||||
|
||||
void pinChange(String key, String pin, String state, bool rev) {
|
||||
int pinInt = pin.toInt();
|
||||
int stateInt;
|
||||
if (rev) {
|
||||
digitalWrite(pinInt, state.toInt());
|
||||
} else {
|
||||
digitalWrite(pinInt, !state.toInt());
|
||||
}
|
||||
eventGen(key, "");
|
||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||
MqttClient::publishStatus(key, state);
|
||||
}
|
||||
};
|
||||
|
||||
extern Button1* myButton;
|
||||
Reference in New Issue
Block a user