mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user