pulse() в ButtonOut, +прочие корректировки

This commit is contained in:
DmitriyTychina
2023-09-05 00:20:03 +03:00
parent 93dfa8ee83
commit fbe7b1cf02
16 changed files with 157 additions and 120 deletions

View File

@@ -3,24 +3,28 @@
extern IoTGpio IoTgpio;
class ButtonOut : public IoTItem {
private:
int _pin, _inv;
int _pin;
bool _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);
enableDoByInt = false;
}
void doByInterval() {
//value.valD = IoTgpio.analogRead(_pin);
int val = _inv?1:0;
IoTgpio.digitalWrite(_pin, val);
// SerialPrint("I", "ButtonOut","single pulse end");
value.valD = 0;
regEvent(0, "ButtonOut");
enableDoByInt = false;
//regEvent(value.valD, "ButtonOut"); //обязательный вызов хотяб один
}
@@ -34,20 +38,36 @@ class ButtonOut : public IoTItem {
IoTgpio.digitalWrite(_pin, value.valD);
regEvent(value.valD, "ButtonOut");
}
else if (command == "pulse") {
if (param[0].isDecimal && (param[0].valD != 0)) {
value.valD = !_inv?1:0;
enableDoByInt = true;
// SerialPrint("I", "ButtonOut","single pulse start");
regEvent((String)(int)!_inv?1:0, "ButtonOut");
suspendNextDoByInt(param[0].valD);
IoTgpio.digitalWrite(_pin, !_inv?1:0);
}
}
return {}; // команда поддерживает возвращаемое значения. Т.е. по итогу выполнения команды или общения с внешней системой, можно вернуть значение в сценарий для дальнейшей обработки
}
void setValue(const IoTValue& Value, bool genEvent = true) {
value = Value;
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
if ((value.valD == !_inv?1:0) && (_interval != 0)) {
value.valD = !_inv?1:0;
enableDoByInt = true;
// SerialPrint("I", "ButtonOut","single pulse start");
suspendNextDoByInt(_interval);
} else {
enableDoByInt = false;
}
regEvent((String)(int)value.valD, "ButtonOut", false, genEvent);
IoTgpio.digitalWrite(_pin, _inv?!value.valD:value.valD);
}
String getValue() {
return (String)(int)value.valD;
}
//=======================================================================================================
~ButtonOut() {};
};

View File

@@ -39,6 +39,11 @@
"name": "change",
"descr": "Инвертирует значение переключателя",
"params": []
},
{
"name": "pulse",
"descr": "Генерирует одиночный импульс",
"params": ["Длительность (ms)"]
}
]
},

View File

@@ -79,16 +79,7 @@ public:
case 1:
// for doByIntervals
if (enableDoByInt)
{
currentMillis = millis();
difference = currentMillis - prevMillis;
if (difference >= _interval)
{
prevMillis = millis();
this->doByInterval();
}
}
IoTItem::loop();
break;
case 2:

View File

@@ -3,6 +3,11 @@
#include "Arduino.h"
#include "MySensorsGate.h"
// временное решение
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long difference;
#ifdef MYSENSORS
// callback библиотеки mysensors
void receive(const MyMessage& message) {

View File

@@ -246,6 +246,11 @@ protected:
pv_last = pv;
}
// временное решение
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long difference;
void loop()
{
if (enableDoByInt)