mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
timer bug fully fixed
This commit is contained in:
@@ -1 +1 @@
|
|||||||
0;count-down;id;na;na;na;order
|
0;count-down;id;anydata;Таймер;Обратный#отчет;order
|
||||||
@@ -16,8 +16,15 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned long _countDownPeriod = 0;
|
unsigned long _countDownPeriod = 0;
|
||||||
String _key;
|
|
||||||
bool _start = false;
|
bool _start = false;
|
||||||
|
String _key;
|
||||||
|
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long prevMillis1;
|
||||||
|
unsigned long prevMillis2;
|
||||||
|
unsigned long difference1;
|
||||||
|
unsigned long difference2;
|
||||||
|
int sec;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,24 +17,23 @@ void CountDownClass::execute(unsigned int countDownPeriod) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CountDownClass::loop() {
|
void CountDownClass::loop() {
|
||||||
static unsigned long prevMillis1;
|
|
||||||
static unsigned long prevMillis2;
|
|
||||||
static int sec;
|
|
||||||
if (_countDownPeriod > 0 && _start) {
|
if (_countDownPeriod > 0 && _start) {
|
||||||
prevMillis1 = millis();
|
prevMillis1 = millis();
|
||||||
_start = false;
|
_start = false;
|
||||||
sec = (_countDownPeriod / 1000) + 1;
|
sec = (_countDownPeriod / 1000);
|
||||||
}
|
}
|
||||||
unsigned long currentMillis = millis();
|
currentMillis = millis();
|
||||||
unsigned long difference1 = currentMillis - prevMillis1;
|
difference1 = currentMillis - prevMillis1;
|
||||||
unsigned long difference2 = currentMillis - prevMillis2;
|
difference2 = currentMillis - prevMillis2;
|
||||||
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
||||||
_countDownPeriod = 0;
|
_countDownPeriod = 0;
|
||||||
eventGen2(_key, "0");
|
eventGen2(_key, "0");
|
||||||
|
Serial.println(_key + " completed");
|
||||||
}
|
}
|
||||||
if (difference2 > 1000 && _countDownPeriod > 0) {
|
if (difference2 > 1000 && _countDownPeriod > 0) {
|
||||||
prevMillis2 = millis();
|
prevMillis2 = millis();
|
||||||
Serial.println(sec--);
|
sec--;
|
||||||
|
Serial.println(_key + " " + String(sec));
|
||||||
publishStatus(_key, String(sec));
|
publishStatus(_key, String(sec));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,6 +48,9 @@ void countDown() {
|
|||||||
countDown_EnterCounter++;
|
countDown_EnterCounter++;
|
||||||
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
addKey(key, countDown_KeyList, countDown_EnterCounter);
|
||||||
|
|
||||||
|
Serial.println(countDown_EnterCounter);
|
||||||
|
Serial.println(countDown_KeyList);
|
||||||
|
|
||||||
static bool firstTime = true;
|
static bool firstTime = true;
|
||||||
if (firstTime) myCountDown = new MyCountDownVector();
|
if (firstTime) myCountDown = new MyCountDownVector();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user