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