Button added and input

This commit is contained in:
Dmitry Borisenko
2020-08-02 01:54:26 +02:00
parent b2496bbc9f
commit 8df3ab8946
9 changed files with 133 additions and 119 deletions

22
include/Class/Input.h Normal file
View 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;

View File

@@ -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 = "";

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();