mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
Button added and input
This commit is contained in:
22
include/Class/Input.h
Normal file
22
include/Class/Input.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "Class/LineParsing.h"
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
class Input : public LineParsing {
|
||||||
|
public:
|
||||||
|
Input() : LineParsing(){};
|
||||||
|
|
||||||
|
void inputSetDefault() {
|
||||||
|
inputSet(_key, _state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void inputSet(String key, String state) {
|
||||||
|
eventGen(key, "");
|
||||||
|
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||||
|
MqttClient::publishStatus(key, state);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern Input* myInput;
|
||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
class LineParsing {
|
class LineParsing {
|
||||||
protected:
|
protected:
|
||||||
String _type;
|
|
||||||
String _key;
|
String _key;
|
||||||
String _file;
|
String _file;
|
||||||
String _page;
|
String _page;
|
||||||
@@ -23,7 +22,6 @@ class LineParsing {
|
|||||||
public:
|
public:
|
||||||
LineParsing() :
|
LineParsing() :
|
||||||
|
|
||||||
_type{""},
|
|
||||||
_key{""},
|
_key{""},
|
||||||
_file{""},
|
_file{""},
|
||||||
_page{""},
|
_page{""},
|
||||||
@@ -43,12 +41,11 @@ class LineParsing {
|
|||||||
//String order = sCmd.order();
|
//String order = sCmd.order();
|
||||||
//pm.info("create '" + order + "'");
|
//pm.info("create '" + order + "'");
|
||||||
for (int i = 1; i < 12; i++) {
|
for (int i = 1; i < 12; i++) {
|
||||||
if (i == 1) _type = sCmd.next();
|
if (i == 1) _key = sCmd.next();
|
||||||
if (i == 2) _key = sCmd.next();
|
if (i == 2) _file = sCmd.next();
|
||||||
if (i == 3) _file = sCmd.next();
|
if (i == 3) _page = sCmd.next();
|
||||||
if (i == 4) _page = sCmd.next();
|
if (i == 4) _descr = sCmd.next();
|
||||||
if (i == 5) _descr = sCmd.next();
|
if (i == 5) _order = sCmd.next();
|
||||||
if (i == 6) _order = sCmd.next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < 6; i++) {
|
for (int i = 1; i < 6; i++) {
|
||||||
@@ -71,9 +68,6 @@ class LineParsing {
|
|||||||
createWidgetClass(_descr, _page, _order, _file, _key);
|
createWidgetClass(_descr, _page, _order, _file, _key);
|
||||||
}
|
}
|
||||||
|
|
||||||
String gtype() {
|
|
||||||
return _type;
|
|
||||||
}
|
|
||||||
String gkey() {
|
String gkey() {
|
||||||
return _key;
|
return _key;
|
||||||
}
|
}
|
||||||
@@ -100,7 +94,6 @@ class LineParsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_type = "";
|
|
||||||
_key = "";
|
_key = "";
|
||||||
_file = "";
|
_file = "";
|
||||||
_page = "";
|
_page = "";
|
||||||
|
|||||||
@@ -1,39 +1,52 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
class Switch : public LineParsing {
|
class Switch : public LineParsing {
|
||||||
|
protected:
|
||||||
|
int numberEntering = 0;
|
||||||
|
int state = _state.toInt();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Switch() : LineParsing(){};
|
Switch() : LineParsing(){};
|
||||||
|
|
||||||
void switchModeSet() {
|
void init() {
|
||||||
if (_pin != "") {
|
if (_pin != "") {
|
||||||
pinMode(_pin.toInt(), INPUT);
|
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() {
|
void switchStateSetDefault() {
|
||||||
if (_inv == "" && _state != "") {
|
if (_state != "") {
|
||||||
switchChange(_key, _pin, _state, true);
|
switchChangeVirtual(_key, _state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchStateSetInvDefault() {
|
void switchChangeVirtual(String key, String state) {
|
||||||
if (_inv != "" && _state != "") {
|
|
||||||
switchChange(_key, _pin, _state, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void switchChange(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, "");
|
eventGen(key, "");
|
||||||
jsonWriteInt(configLiveJson, key, state.toInt());
|
jsonWriteInt(configLiveJson, key, state.toInt());
|
||||||
MqttClient::publishStatus(key, state);
|
MqttClient::publishStatus(key, state);
|
||||||
|
|||||||
@@ -4,15 +4,20 @@
|
|||||||
|
|
||||||
extern void cmd_init();
|
extern void cmd_init();
|
||||||
extern void itemInit();
|
extern void itemInit();
|
||||||
extern void button();
|
|
||||||
extern void buttonSet();
|
extern void buttonOut();
|
||||||
extern void buttonChange();
|
extern void buttonOutSet();
|
||||||
extern void pinSet();
|
|
||||||
extern void pinChange();
|
extern void pwmOut();
|
||||||
|
extern void pwmOutSet();
|
||||||
|
|
||||||
|
extern void buttonIn();
|
||||||
|
extern void buttonInSet();
|
||||||
|
|
||||||
|
extern void inputDigit();
|
||||||
|
extern void inputDigitSet();
|
||||||
|
|
||||||
extern void handle_time_init();
|
extern void handle_time_init();
|
||||||
extern void pwm();
|
|
||||||
extern void switch_();
|
|
||||||
extern void pwmSet();
|
|
||||||
extern void stepper();
|
extern void stepper();
|
||||||
extern void stepperSet();
|
extern void stepperSet();
|
||||||
extern void servo_();
|
extern void servo_();
|
||||||
@@ -20,8 +25,7 @@ extern void servoSet();
|
|||||||
extern void serialBegin();
|
extern void serialBegin();
|
||||||
extern void serialWrite();
|
extern void serialWrite();
|
||||||
extern void logging();
|
extern void logging();
|
||||||
extern void inputDigit();
|
|
||||||
extern void digitSet();
|
|
||||||
extern void inputTime();
|
extern void inputTime();
|
||||||
extern void button();
|
extern void button();
|
||||||
extern void timeSet();
|
extern void timeSet();
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ extern void do_mqtt_send_settings_to_udp();
|
|||||||
extern void addCommandLoop(const String& cmdStr);
|
extern void addCommandLoop(const String& cmdStr);
|
||||||
extern void loopSerial();
|
extern void loopSerial();
|
||||||
extern void loopCmd();
|
extern void loopCmd();
|
||||||
extern void loopButton();
|
|
||||||
extern void loopScenario();
|
extern void loopScenario();
|
||||||
extern void loopUdp();
|
extern void loopUdp();
|
||||||
|
|
||||||
|
|||||||
2
src/Class/Input.cpp
Normal file
2
src/Class/Input.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "Class/Input.h"
|
||||||
|
Input* myInput;
|
||||||
2
src/Class/Switch.cpp
Normal file
2
src/Class/Switch.cpp
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include "Class/Switch.h"
|
||||||
|
Switch* mySwitch;
|
||||||
130
src/Cmd.cpp
130
src/Cmd.cpp
@@ -1,8 +1,11 @@
|
|||||||
#include "Cmd.h"
|
#include "Cmd.h"
|
||||||
|
|
||||||
#include "Class/Button.h"
|
#include "Class/Button.h"
|
||||||
|
#include "Class/Input.h"
|
||||||
#include "Class/LineParsing.h"
|
#include "Class/LineParsing.h"
|
||||||
#include "Class/Pwm.h"
|
#include "Class/Pwm.h"
|
||||||
|
#include "Class/Switch.h"
|
||||||
|
//-----------------------------
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include "Module/Terminal.h"
|
#include "Module/Terminal.h"
|
||||||
#include "Servo/Servos.h"
|
#include "Servo/Servos.h"
|
||||||
@@ -23,10 +26,19 @@ HardwareSerial *mySerial = nullptr;
|
|||||||
void getData();
|
void getData();
|
||||||
|
|
||||||
void cmd_init() {
|
void cmd_init() {
|
||||||
sCmd.addCommand("button", button);
|
sCmd.addCommand("button-out", buttonOut);
|
||||||
sCmd.addCommand("pwm", pwm);
|
sCmd.addCommand("pwm-out", pwmOut);
|
||||||
|
sCmd.addCommand("button-in", buttonIn);
|
||||||
|
sCmd.addCommand("input-digit", inputDigit);
|
||||||
|
|
||||||
sCmd.addCommand("switch", switch_);
|
sCmd.addCommand("inputTime", inputTime);
|
||||||
|
sCmd.addCommand("timeSet", timeSet);
|
||||||
|
|
||||||
|
sCmd.addCommand("timerStart", timerStart_);
|
||||||
|
sCmd.addCommand("timerStop", timerStop_);
|
||||||
|
|
||||||
|
sCmd.addCommand("text", text);
|
||||||
|
sCmd.addCommand("textSet", textSet);
|
||||||
|
|
||||||
#ifdef ANALOG_ENABLED
|
#ifdef ANALOG_ENABLED
|
||||||
sCmd.addCommand("analog", analog);
|
sCmd.addCommand("analog", analog);
|
||||||
@@ -78,18 +90,6 @@ void cmd_init() {
|
|||||||
sCmd.addCommand("logging", logging);
|
sCmd.addCommand("logging", logging);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sCmd.addCommand("inputDigit", inputDigit);
|
|
||||||
sCmd.addCommand("digitSet", digitSet);
|
|
||||||
|
|
||||||
sCmd.addCommand("inputTime", inputTime);
|
|
||||||
sCmd.addCommand("timeSet", timeSet);
|
|
||||||
|
|
||||||
sCmd.addCommand("timerStart", timerStart_);
|
|
||||||
sCmd.addCommand("timerStop", timerStop_);
|
|
||||||
|
|
||||||
sCmd.addCommand("text", text);
|
|
||||||
sCmd.addCommand("textSet", textSet);
|
|
||||||
|
|
||||||
sCmd.addCommand("mqtt", mqttOrderSend);
|
sCmd.addCommand("mqtt", mqttOrderSend);
|
||||||
sCmd.addCommand("http", httpOrderSend);
|
sCmd.addCommand("http", httpOrderSend);
|
||||||
|
|
||||||
@@ -104,15 +104,15 @@ void cmd_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==========================================Модуль кнопок===================================================
|
//==========================================Модуль кнопок===================================================
|
||||||
//button out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
//button-out light toggle Кнопки Свет 1 pin[12] inv[1] st[1]
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
void button() {
|
void buttonOut() {
|
||||||
myButton = new Button();
|
myButton = new Button();
|
||||||
myButton->update();
|
myButton->update();
|
||||||
String key = myButton->gkey();
|
String key = myButton->gkey();
|
||||||
String pin = myButton->gpin();
|
String pin = myButton->gpin();
|
||||||
String inv = myButton->ginv();
|
String inv = myButton->ginv();
|
||||||
sCmd.addCommand(key.c_str(), buttonSet);
|
sCmd.addCommand(key.c_str(), buttonOutSet);
|
||||||
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||||
jsonWriteStr(configOptionJson, key + "_inv", inv);
|
jsonWriteStr(configOptionJson, key + "_inv", inv);
|
||||||
myButton->pinModeSet();
|
myButton->pinModeSet();
|
||||||
@@ -121,7 +121,7 @@ void button() {
|
|||||||
myButton->clear();
|
myButton->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void buttonSet() {
|
void buttonOutSet() {
|
||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String state = sCmd.next();
|
String state = sCmd.next();
|
||||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||||
@@ -134,22 +134,22 @@ void buttonSet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==========================================Модуль управления ШИМ===================================================
|
//==========================================Модуль управления ШИМ===================================================
|
||||||
//pwm out volume range Кнопки Свет 1 pin[12] st[500]
|
//pwm-out volume range Кнопки Свет 1 pin[12] st[500]
|
||||||
//==================================================================================================================
|
//==================================================================================================================
|
||||||
void pwm() {
|
void pwmOut() {
|
||||||
myPwm = new Pwm();
|
myPwm = new Pwm();
|
||||||
myPwm->update();
|
myPwm->update();
|
||||||
String key = myPwm->gkey();
|
String key = myPwm->gkey();
|
||||||
String pin = myPwm->gpin();
|
String pin = myPwm->gpin();
|
||||||
String inv = myPwm->ginv();
|
String inv = myPwm->ginv();
|
||||||
sCmd.addCommand(key.c_str(), pwmSet);
|
sCmd.addCommand(key.c_str(), pwmOutSet);
|
||||||
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
jsonWriteStr(configOptionJson, key + "_pin", pin);
|
||||||
myPwm->pwmModeSet();
|
myPwm->pwmModeSet();
|
||||||
myPwm->pwmStateSetDefault();
|
myPwm->pwmStateSetDefault();
|
||||||
myPwm->clear();
|
myPwm->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pwmSet() {
|
void pwmOutSet() {
|
||||||
String key = sCmd.order();
|
String key = sCmd.order();
|
||||||
String state = sCmd.next();
|
String state = sCmd.next();
|
||||||
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
||||||
@@ -157,68 +157,40 @@ void pwmSet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//==========================================Модуль физических кнопок========================================
|
//==========================================Модуль физических кнопок========================================
|
||||||
//switch in switch1 toggle Кнопки Свет 1 pin[2] inv[1] db[20]
|
//button-in switch1 toggle Кнопки Свет 1 pin[2] db[20]
|
||||||
//==========================================================================================================
|
//==========================================================================================================
|
||||||
void switch_() {
|
void buttonIn() {
|
||||||
int number = String(sCmd.next()).toInt();
|
mySwitch = new Switch();
|
||||||
int pin = String(sCmd.next()).toInt();
|
mySwitch->update();
|
||||||
int delay = String(sCmd.next()).toInt();
|
String key = mySwitch->gkey();
|
||||||
|
String pin = mySwitch->gpin();
|
||||||
buttons[number].attach(pin);
|
sCmd.addCommand(key.c_str(), buttonInSet);
|
||||||
buttons[number].interval(delay);
|
mySwitch->init();
|
||||||
but[number] = true;
|
mySwitch->switchStateSetDefault();
|
||||||
|
mySwitch->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopSerial() {
|
void buttonInSet() {
|
||||||
if (term) {
|
String key = sCmd.order();
|
||||||
term->loop();
|
String state = sCmd.next();
|
||||||
}
|
mySwitch->switchChangeVirtual(key, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopButton() {
|
//==========================================Модуль ввода цифровых значений==================================
|
||||||
static uint8_t switch_number = 1;
|
//digit-input digit1 inputNum Ввод Введите 1 st[60]
|
||||||
|
//==========================================================================================================
|
||||||
if (but[switch_number]) {
|
|
||||||
buttons[switch_number].update();
|
|
||||||
if (buttons[switch_number].fell()) {
|
|
||||||
eventGen("switch", String(switch_number));
|
|
||||||
|
|
||||||
jsonWriteStr(configLiveJson, "switch" + String(switch_number), "1");
|
|
||||||
}
|
|
||||||
if (buttons[switch_number].rose()) {
|
|
||||||
eventGen("switch", String(switch_number));
|
|
||||||
|
|
||||||
jsonWriteStr(configLiveJson, "switch" + String(switch_number), "0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch_number++;
|
|
||||||
if (switch_number == NUM_BUTTONS) {
|
|
||||||
switch_number = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//=====================================================================================================================================
|
|
||||||
//=========================================Добавление окна ввода цифры=================================================================
|
|
||||||
void inputDigit() {
|
void inputDigit() {
|
||||||
String value_name = sCmd.next();
|
myInput = new Input();
|
||||||
String number = value_name.substring(5);
|
myInput->update();
|
||||||
String widget_name = sCmd.next();
|
String key = myInput->gkey();
|
||||||
widget_name.replace("#", " ");
|
sCmd.addCommand(key.c_str(), inputDigitSet);
|
||||||
String page_name = sCmd.next();
|
myInput->inputSetDefault();
|
||||||
page_name.replace("#", " ");
|
|
||||||
String start_state = sCmd.next();
|
|
||||||
String page_number = sCmd.next();
|
|
||||||
|
|
||||||
jsonWriteStr(configLiveJson, "digit" + number, start_state);
|
|
||||||
createWidget(widget_name, page_name, page_number, "inputNum", "digit" + number);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void digitSet() {
|
void inputDigitSet() {
|
||||||
String number = sCmd.next();
|
|
||||||
String value = sCmd.next();
|
|
||||||
|
|
||||||
jsonWriteStr(configLiveJson, "digit" + number, value);
|
|
||||||
MqttClient::publishStatus("digit" + number, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=====================================================================================================================================
|
//=====================================================================================================================================
|
||||||
@@ -513,3 +485,9 @@ void loopCmd() {
|
|||||||
order_loop = deleteBeforeDelimiter(order_loop, ","); //осекаем
|
order_loop = deleteBeforeDelimiter(order_loop, ","); //осекаем
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loopSerial() {
|
||||||
|
if (term) {
|
||||||
|
term->loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "HttpServer.h"
|
#include "HttpServer.h"
|
||||||
#include "Bus/BusScannerFactory.h"
|
#include "Bus/BusScannerFactory.h"
|
||||||
#include "Utils/Timings.h"
|
#include "Utils/Timings.h"
|
||||||
|
#include "Class/Switch.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -94,7 +95,7 @@ void loop() {
|
|||||||
|
|
||||||
loopCmd();
|
loopCmd();
|
||||||
|
|
||||||
loopButton();
|
mySwitch->loop();
|
||||||
|
|
||||||
loopScenario();
|
loopScenario();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user