mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +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:
|
||||
unsigned long _countDownPeriod = 0;
|
||||
String _key;
|
||||
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() {
|
||||
static unsigned long prevMillis1;
|
||||
static unsigned long prevMillis2;
|
||||
static int sec;
|
||||
if (_countDownPeriod > 0 && _start) {
|
||||
prevMillis1 = millis();
|
||||
_start = false;
|
||||
sec = (_countDownPeriod / 1000) + 1;
|
||||
sec = (_countDownPeriod / 1000);
|
||||
}
|
||||
unsigned long currentMillis = millis();
|
||||
unsigned long difference1 = currentMillis - prevMillis1;
|
||||
unsigned long difference2 = currentMillis - prevMillis2;
|
||||
currentMillis = millis();
|
||||
difference1 = currentMillis - prevMillis1;
|
||||
difference2 = currentMillis - prevMillis2;
|
||||
if (difference1 > _countDownPeriod && _countDownPeriod > 0) {
|
||||
_countDownPeriod = 0;
|
||||
eventGen2(_key, "0");
|
||||
Serial.println(_key + " completed");
|
||||
}
|
||||
if (difference2 > 1000 && _countDownPeriod > 0) {
|
||||
prevMillis2 = millis();
|
||||
Serial.println(sec--);
|
||||
sec--;
|
||||
Serial.println(_key + " " + String(sec));
|
||||
publishStatus(_key, String(sec));
|
||||
}
|
||||
}
|
||||
@@ -49,6 +48,9 @@ void countDown() {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user