simplify timer by using first iteration functionality of the task - avoid using start and decreasing value on first iteration
This commit is contained in:
parent
5421e52bf4
commit
2c0346680d
@ -85,22 +85,20 @@ namespace Display {
|
||||
[]{
|
||||
if (!displayTask.isPerm(tDisplayTimer)) displayTask.restorePerm();
|
||||
});
|
||||
constexpr uint8 threshold = 16;
|
||||
Task tTimer(MINUTES(1), TASK_FOREVER,
|
||||
[]{
|
||||
static constexpr uint8 threshold = 16;
|
||||
timer.decrease();
|
||||
if (timer.atBeginning()) {
|
||||
if (tTimer.isFirstIteration()) {
|
||||
if (timer <= threshold) tDisplayTimer.setIterations(TASK_FOREVER);
|
||||
displayTask.activate(tDisplayTimer);
|
||||
} else if (timer == threshold) {
|
||||
tDisplayTimer.setIterations(TASK_FOREVER);
|
||||
displayTask.activate(tDisplayTimer);
|
||||
} else {
|
||||
timer.decrease();
|
||||
if (timer == threshold) {
|
||||
tDisplayTimer.setIterations(TASK_FOREVER);
|
||||
displayTask.activate(tDisplayTimer);
|
||||
}
|
||||
}
|
||||
}, &ts, false,
|
||||
[]{
|
||||
timer.start();
|
||||
return true;
|
||||
},
|
||||
}, &ts, false, nullptr,
|
||||
[]{
|
||||
tDisplayTimer.setIterations(TASK_ONCE + 1);
|
||||
displayTask.activate(tDisplayTime);
|
||||
|
||||
@ -7,25 +7,17 @@ struct : public CallbackAware<remaining_callback_t> {
|
||||
|
||||
void operator=(int8 value) {
|
||||
remaining = value;
|
||||
if (callback) callback(remaining);
|
||||
}
|
||||
|
||||
operator int8() {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
void start() {
|
||||
initial = remaining++;
|
||||
}
|
||||
|
||||
void decrease() {
|
||||
remaining--;
|
||||
if (callback) callback(remaining);
|
||||
}
|
||||
|
||||
bool atBeginning() {
|
||||
return initial == remaining;
|
||||
*this = remaining - 1;
|
||||
}
|
||||
|
||||
private:
|
||||
int8 initial = 0, remaining = 0;
|
||||
int8 remaining = 0;
|
||||
} timer;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user