From 66051080526df52c90f243d2e50812d216b3be64 Mon Sep 17 00:00:00 2001 From: Ilya Belyakov Date: Wed, 1 May 2024 10:06:10 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D1=8F=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BF=D0=B5=D1=80=D0=B8=D0=BE=D0=B4=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=B8=20nowInTimePeriod=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=20=D0=B2=20IoTItem.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/classes/IoTItem.h | 1 + src/modules/virtual/Math/Math.cpp | 9 ++- .../virtual/Math/SimpleTimePeriod.json | 57 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/modules/virtual/Math/SimpleTimePeriod.json 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