Files
IoTManager/include/items/ButtonOutClass.h

42 lines
1023 B
C
Raw Normal View History

2020-09-02 22:34:49 +03:00
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "Global.h"
2020-09-03 01:12:43 +03:00
class ButtonOutClass : public LineParsing {
2020-09-02 22:34:49 +03:00
public:
2020-09-03 01:12:43 +03:00
ButtonOutClass() : LineParsing(){};
2020-09-02 22:34:49 +03:00
void pinModeSet() {
if (_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);
}
};
2020-09-03 01:12:43 +03:00
extern ButtonOutClass* myButtonOut;