2020-09-02 22:34:49 +03:00
|
|
|
#pragma once
|
|
|
|
|
#include <Arduino.h>
|
2020-09-03 23:29:34 +03:00
|
|
|
|
2020-09-02 22:34:49 +03:00
|
|
|
#include "Class/LineParsing.h"
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
|
2020-09-03 01:12:43 +03:00
|
|
|
class ButtonOutClass : public LineParsing {
|
2020-11-02 04:09:15 +03:00
|
|
|
public:
|
|
|
|
|
ButtonOutClass() : LineParsing() {};
|
2020-09-02 22:34:49 +03:00
|
|
|
|
2020-09-03 23:29:34 +03:00
|
|
|
void init() {
|
2020-09-02 22:34:49 +03:00
|
|
|
if (_pin != "") {
|
|
|
|
|
pinMode(_pin.toInt(), OUTPUT);
|
|
|
|
|
}
|
2020-09-03 23:29:34 +03:00
|
|
|
jsonWriteStr(configOptionJson, _key + "_pin", _pin);
|
|
|
|
|
jsonWriteStr(configOptionJson, _key + "_inv", _inv);
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void pinStateSetDefault() {
|
2020-09-03 23:29:34 +03:00
|
|
|
pinChange(_key, _state);
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-09-03 23:29:34 +03:00
|
|
|
void pinChange(String key, String state) {
|
|
|
|
|
String pin = jsonReadStr(configOptionJson, key + "_pin");
|
|
|
|
|
String inv = jsonReadStr(configOptionJson, key + "_inv");
|
2020-09-02 22:34:49 +03:00
|
|
|
int pinInt = pin.toInt();
|
2020-09-03 23:29:34 +03:00
|
|
|
|
|
|
|
|
if (inv == "") {
|
2020-09-02 22:34:49 +03:00
|
|
|
digitalWrite(pinInt, state.toInt());
|
2020-11-02 04:09:15 +03:00
|
|
|
}
|
|
|
|
|
else {
|
2020-09-02 22:34:49 +03:00
|
|
|
digitalWrite(pinInt, !state.toInt());
|
|
|
|
|
}
|
2020-11-07 01:11:32 +03:00
|
|
|
eventGen2(key, state);
|
2020-09-02 22:34:49 +03:00
|
|
|
jsonWriteInt(configLiveJson, key, state.toInt());
|
2020-11-02 04:09:15 +03:00
|
|
|
publishStatus(key, state);
|
2020-09-02 22:34:49 +03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-09-03 02:07:12 +03:00
|
|
|
extern ButtonOutClass myButtonOut;
|