Merge pull request #17 from Mit4el/ver4dev

обновление с основы
This commit is contained in:
Mit4el
2023-10-03 22:56:25 +03:00
committed by GitHub
37 changed files with 747 additions and 813 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"); //обязательный вызов хотяб один
}
@@ -30,24 +34,40 @@ class ButtonOut : public IoTItem {
// 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);
value.valD = 1 - (int)value.valD;
IoTgpio.digitalWrite(_pin, _inv?!value.valD: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

@@ -10,7 +10,7 @@ public:
void sendHttpPOST(String url, String msg)
{
if (WiFi.status() == WL_CONNECTED)
if (isNetworkActive())
{
WiFiClient client;

View File

@@ -7,7 +7,7 @@
"type": "Writing",
"subtype": "IoTServo",
"id": "servo",
"widget": "range",
"widget": "rangeServo",
"page": "servo",
"descr": "угол",
"int": 1,

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

@@ -13,7 +13,7 @@ class TelegramLT : public IoTItem {
}
void sendTelegramMsg(bool often, String msg) {
if (WiFi.status() == WL_CONNECTED && (often || !often && _prevMsg != msg)) {
if (isNetworkActive() && (often || !often && _prevMsg != msg)) {
WiFiClient client;
HTTPClient http;
http.begin(client, "http://live-control.com/iotm/telegram.php");

View File

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