diff --git a/include/classes/IoTItem.h b/include/classes/IoTItem.h index cfdb33e2..5ff1e0fe 100644 --- a/include/classes/IoTItem.h +++ b/include/classes/IoTItem.h @@ -1,4 +1,5 @@ #pragma once +#include #include "classes/IoTGpio.h" //#include "classes/IoTBench.h" diff --git a/src/modules/virtual/Math/Math.cpp b/src/modules/virtual/Math/Math.cpp index d726d2dc..979031f6 100644 --- a/src/modules/virtual/Math/Math.cpp +++ b/src/modules/virtual/Math/Math.cpp @@ -37,9 +37,16 @@ private: int h2 = selectToMarker(endTime, ":").toInt(); int min2 = selectToMarkerLast(endTime, ":").toInt(); + int sumMin1 = h1 * 60 + min1; + int sumMin2 = h2 * 60 + min2; + int nowMinutes = _time_local.hour * 60 + _time_local.minute; - return nowMinutes >= h1 * 60 + min1 && nowMinutes <= h2 * 60 + min2; + if (sumMin1 <= sumMin2) { + return nowMinutes >= sumMin1 && nowMinutes <= sumMin2; + } else { + return nowMinutes >= sumMin1 && nowMinutes <= 24 * 60 || nowMinutes >= 0 && nowMinutes <= sumMin2; + } } diff --git a/src/modules/virtual/Math/SimpleTimePeriod.json b/src/modules/virtual/Math/SimpleTimePeriod.json new file mode 100644 index 00000000..1b402876 --- /dev/null +++ b/src/modules/virtual/Math/SimpleTimePeriod.json @@ -0,0 +1,57 @@ +{ + "mark": "iotm", + "config": [ + { + "global": 0, + "type": "Reading", + "subtype": "IoTMath", + "id": "math", + "widget": "anydataValue", + "page": "Ввод", + "descr": "" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "start", + "needSave": 0, + "widget": "inputTm", + "page": "Ввод", + "descr": "Введите время", + "int": "0", + "val": "02:00" + }, + { + "global": 0, + "type": "Reading", + "subtype": "Variable", + "id": "stop", + "needSave": 0, + "widget": "inputTm", + "page": "Ввод", + "descr": "Введите время", + "int": "0", + "val": "02:00" + }, + { + "global": 0, + "type": "Writing", + "subtype": "ButtonOut", + "needSave": 0, + "id": "led", + "widget": "toggle", + "page": "Ввод", + "descr": "Освещение", + "int": 0, + "inv": 0, + "pin": 2 + } + ] +} + +scenario=>if start | stop then { +if math.nowInTimePeriod(start, stop) then { +led = 1 +} else led = 0 +} \ No newline at end of file