Merge branch 'resume-timer'
This commit is contained in:
commit
9337c4a738
@ -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);
|
||||
|
||||
@ -6,26 +6,18 @@ typedef void (*remaining_callback_t)(int8);
|
||||
struct : public CallbackAware<remaining_callback_t> {
|
||||
|
||||
void operator=(int8 value) {
|
||||
initial = remaining = value;
|
||||
remaining = value;
|
||||
if (callback) callback(remaining);
|
||||
}
|
||||
|
||||
operator int8() {
|
||||
return remaining;
|
||||
}
|
||||
|
||||
void start() {
|
||||
remaining = initial + 1;
|
||||
}
|
||||
|
||||
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