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:
54
include/items/ButtonInClass.h
Normal file
54
include/items/ButtonInClass.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class ButtonInClass : public LineParsing {
|
||||
protected:
|
||||
int numberEntering = 0;
|
||||
int state = _state.toInt();
|
||||
|
||||
public:
|
||||
ButtonInClass() : 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 ButtonInClass* myButtonIn;
|
||||
42
include/items/ButtonOutClass.h
Normal file
42
include/items/ButtonOutClass.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class ButtonOutClass : public LineParsing {
|
||||
public:
|
||||
ButtonOutClass() : 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 ButtonOutClass* myButtonOut;
|
||||
31
include/items/InputClass.h
Normal file
31
include/items/InputClass.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class InputClass : public LineParsing {
|
||||
public:
|
||||
InputClass() : 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 InputClass* myInput;
|
||||
23
include/items/OutputTextClass.h
Normal file
23
include/items/OutputTextClass.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class OutputTextClass : public LineParsing {
|
||||
public:
|
||||
OutputTextClass() : 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 OutputTextClass* myOutputText;
|
||||
31
include/items/PwmOutClass.h
Normal file
31
include/items/PwmOutClass.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class PwmOutClass : public LineParsing {
|
||||
public:
|
||||
PwmOutClass() : 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 PwmOutClass* myPwmOut;
|
||||
32
include/items/SensorAnalogClass.h
Normal file
32
include/items/SensorAnalogClass.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include "Class/LineParsing.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorAnalogClass : public SensorConvertingClass {
|
||||
public:
|
||||
SensorAnalogClass() : SensorConvertingClass(){};
|
||||
|
||||
int SensorAnalogRead(String key, String pin) {
|
||||
|
||||
int pinInt = pin.toInt();
|
||||
int value;
|
||||
|
||||
#ifdef ESP32
|
||||
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));
|
||||
MqttClient::publishStatus(key, String(valueFl));
|
||||
Serial.println("[I] sensor '" + key + "' data: " + String(valueFl));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
extern SensorAnalogClass* mySensorAnalog;
|
||||
32
include/items/SensorConvertingClass.h
Normal file
32
include/items/SensorConvertingClass.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorConvertingClass : public LineParsing {
|
||||
public:
|
||||
SensorConvertingClass() : 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;
|
||||
}
|
||||
};
|
||||
34
include/items/SensorUltrasonicClass.h
Normal file
34
include/items/SensorUltrasonicClass.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "Class/LineParsing.h"
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "Global.h"
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
public:
|
||||
SensorUltrasonic() : SensorConvertingClass(){};
|
||||
|
||||
int SensorUltrasonicRead(String key, String pin) {
|
||||
int trig = selectFromMarkerToMarker(pin, ",", 0).toInt();
|
||||
int echo = selectFromMarkerToMarker(pin, ",", 1).toInt();
|
||||
int value;
|
||||
|
||||
digitalWrite(trig, LOW);
|
||||
delayMicroseconds(2);
|
||||
digitalWrite(trig, HIGH);
|
||||
delayMicroseconds(10);
|
||||
digitalWrite(trig, LOW);
|
||||
long duration_ = pulseIn(echo, HIGH, 30000); // 3000 µs = 50cm // 30000 µs = 5 m
|
||||
value = duration_ / 29 / 2;
|
||||
|
||||
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 SensorUltrasonic* mySensorUltrasonic;
|
||||
Reference in New Issue
Block a user