mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
add count down timer
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "items/vPwmOut.h"
|
||||
#include "items/vInOutput.h"
|
||||
#include "items/vLogging.h"
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "items/vCountDown.h"
|
||||
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
orderBuf += cmdStr;
|
||||
@@ -89,6 +91,9 @@ void csvCmdExecute(String& cmdStr) {
|
||||
else if (order == F("impuls-out")) {
|
||||
sCmd.addCommand(order.c_str(), impuls);
|
||||
}
|
||||
else if (order == F("count-down")) {
|
||||
sCmd.addCommand(order.c_str(), countDown);
|
||||
}
|
||||
|
||||
sCmd.readStr(buf);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ int inOutput_EnterCounter = -1;
|
||||
String pwmOut_KeyList = "";
|
||||
int pwmOut_EnterCounter = -1;
|
||||
//=========================================
|
||||
String countDown_KeyList = "";
|
||||
int countDown_EnterCounter = -1;
|
||||
//=========================================
|
||||
|
||||
// Sensors
|
||||
String sensorReadingMap10sec;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vInOutput.h"
|
||||
#include "items/vPwmOut.h"
|
||||
#include "items/vCountDown.h"
|
||||
|
||||
void loadConfig() {
|
||||
configSetupJson = readFile("config.json", 4096);
|
||||
@@ -73,6 +74,12 @@ void Device_init() {
|
||||
pwmOut_KeyList = "";
|
||||
pwmOut_EnterCounter = -1;
|
||||
//===================================
|
||||
if (myCountDown != nullptr) {
|
||||
myCountDown->clear();
|
||||
}
|
||||
countDown_KeyList = "";
|
||||
countDown_EnterCounter = -1;
|
||||
//===================================
|
||||
|
||||
|
||||
#ifdef LAYOUT_IN_RAM
|
||||
|
||||
71
src/items/vCountDown.cpp
Normal file
71
src/items/vCountDown.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "items/vCountDown.h"
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
CountDownClass::CountDownClass(String key) {
|
||||
_key = key;
|
||||
}
|
||||
|
||||
CountDownClass::~CountDownClass() {}
|
||||
|
||||
void CountDownClass::execute(unsigned int countDownPeriod) {
|
||||
_countDownPeriod = countDownPeriod * 1000;
|
||||
_start = true;
|
||||
}
|
||||
|
||||
void CountDownClass::loop() {
|
||||
static unsigned long prevMillis1;
|
||||
static unsigned long prevMillis2;
|
||||
static int sec;
|
||||
if (_countDownPeriod > 0 && _start) {
|
||||
prevMillis1 = millis();
|
||||
_start = false;
|
||||
sec = (_countDownPeriod / 1000) + 1;
|
||||
}
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long difference1 = currentMillis - prevMillis1;
|
||||
unsigned long difference2 = currentMillis - prevMillis2;
|
||||
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
||||
_countDownPeriod = 0;
|
||||
eventGen2(_key, "0");
|
||||
}
|
||||
if (difference2 > 1000 && _countDownPeriod > 0) {
|
||||
prevMillis2 = millis();
|
||||
Serial.println(sec--);
|
||||
publishStatus(_key, String(sec));
|
||||
}
|
||||
}
|
||||
|
||||
MyCountDownVector* myCountDown = nullptr;
|
||||
|
||||
void countDown() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
myLineParsing.clear();
|
||||
|
||||
countDown_EnterCounter++;
|
||||
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) myCountDown = new MyCountDownVector();
|
||||
firstTime = false;
|
||||
myCountDown->push_back(CountDownClass(key));
|
||||
|
||||
sCmd.addCommand(key.c_str(), countDownExecute);
|
||||
}
|
||||
|
||||
void countDownExecute() {
|
||||
String key = sCmd.order();
|
||||
String countDownPeriod = sCmd.next();
|
||||
|
||||
int number = getKeyNum(key, countDown_KeyList);
|
||||
|
||||
if (myCountDown != nullptr) {
|
||||
if (number != -1) {
|
||||
myCountDown->at(number).execute(countDownPeriod.toInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "items/vImpulsOut.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
#include "BufferExecute.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
ImpulsOutClass::ImpulsOutClass(unsigned int impulsPin) {
|
||||
_impulsPin = impulsPin;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "items/vLogging.h"
|
||||
#include "items/vImpulsOut.h"
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vCountDown.h"
|
||||
#include "Telegram.h"
|
||||
|
||||
void not_async_actions();
|
||||
@@ -156,16 +157,19 @@ void loop() {
|
||||
myLogging->at(i).loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (myImpulsOut != nullptr) {
|
||||
for (unsigned int i = 0; i < myImpulsOut->size(); i++) {
|
||||
myImpulsOut->at(i).loop();
|
||||
}
|
||||
}
|
||||
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorDallas2->size(); i++) {
|
||||
mySensorDallas2->at(i).loop();
|
||||
}
|
||||
}
|
||||
if (myCountDown != nullptr) {
|
||||
for (unsigned int i = 0; i < myCountDown->size(); i++) {
|
||||
myCountDown->at(i).loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user