This commit is contained in:
Dmitry Borisenko
2021-10-05 19:21:52 +08:00
parent 74c31e30ea
commit 421f3fcb9a
348 changed files with 22008 additions and 0 deletions

79
src/items/vCountDown.cpp Normal file
View File

@@ -0,0 +1,79 @@
#include "Consts.h"
#ifdef EnableCountDown
#include <Arduino.h>
#include "BufferExecute.h"
#include "Class/LineParsing.h"
#include "Global.h"
#include "items/vCountDown.h"
CountDownClass::CountDownClass(String key) {
_key = key;
}
CountDownClass::~CountDownClass() {}
void CountDownClass::execute(unsigned int countDownPeriod) {
_countDownPeriod = countDownPeriod * 1000;
_start = true;
}
void CountDownClass::loop() {
if (_countDownPeriod > 0 && _start) {
prevMillis = millis();
sec = (_countDownPeriod / 1000);
_start = false;
}
difference = millis() - prevMillis;
if (difference > 1000 && _countDownPeriod > 0) {
prevMillis = millis();
eventGen2(_key, String(sec));
String time = String(prettyMillis(sec * 1000));
jsonWriteStr(configLiveJson, _key, time);
publishStatus(_key, time);
sec--;
if (sec < 0) {
_countDownPeriod = 0;
}
}
}
MyCountDownVector* myCountDown = nullptr;
void countDown() {
myLineParsing.update();
String key = myLineParsing.gkey();
myLineParsing.clear();
countDown_EnterCounter++;
addKey(key, countDown_KeyList, countDown_EnterCounter);
//Serial.println(countDown_EnterCounter);
//Serial.println(countDown_KeyList);
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 value = sCmd.next();
if (!isDigitStr(value)) { //если значение - текст
value = getValue(value);
}
int number = getKeyNum(key, countDown_KeyList);
if (myCountDown != nullptr) {
if (number != -1) {
myCountDown->at(number).execute(value.toInt());
}
}
}
#endif