Files
IoTManager/src/modules/exec/ButtonOut/ButtonOut.cpp
2022-11-10 18:01:05 +05:00

62 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "Global.h"
#include "classes/IoTItem.h"
extern IoTGpio IoTgpio;
class ButtonOut : public IoTItem {
private:
int _pin, _inv;
public:
ButtonOut(String parameters): IoTItem(parameters) {
jsonRead(parameters, "pin", _pin);
jsonRead(parameters, "inv", _inv);
_round = 0;
IoTgpio.pinMode(_pin, OUTPUT);
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
}
void doByInterval() {
//value.valD = IoTgpio.analogRead(_pin);
//regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
// реакция на вызов команды модуля из сценария
// String command - имя команды после ID. (ID.Команда())
// param - вектор ("массив") значений параметров переданных вместе с командой: ID.Команда("пар1", 22, 33) -> param[0].ValS = "пар1", param[1].ValD = 22
if (command == "change") {
value.valD = 1 - IoTgpio.digitalRead(_pin);
IoTgpio.digitalWrite(_pin, value.valD);
regEvent(value.valD, "ButtonOut");
}
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
}
void setValue(const IoTValue& Value, bool genEvent = true) {
value = Value;
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
regEvent((String)(int)value.valD, "ButtonOut", false, genEvent);
}
String getValue() {
return (String)(int)value.valD;
}
//=======================================================================================================
~ButtonOut() {};
};
void* getAPI_ButtonOut(String subtype, String param) {
if (subtype == F("ButtonOut")) {
return new ButtonOut(param);
} else {
return nullptr;
}
}