Files
IoTManager/include/Class/button.h
Dmitry Borisenko 217cdfc080 Buttons done
2020-07-31 00:56:10 +02:00

44 lines
1.0 KiB
C++

#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
class Button : public LineParsing {
public:
Button() : LineParsing(){};
void pinModeSet() {
if (_pin != "") {
Serial.println(_pin);
pinMode(_pin.toInt(), OUTPUT);
}
}
void pinStateSetDefault() {
if (_inv == "" && _state != "") {
pinChange(_key, _pin, _state, true);
}
}
void pinStateSetInvDefault() {
if (_inv != "" && _state != "") {
pinChange(_key, _pin, _state, false);
}
}
void pinChange(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, "");
jsonWriteInt(configLiveJson, key, state.toInt());
MqttClient::publishStatus(key, state);
}
};
extern Button* myButton;