Merge branch 'resume-timer'
This commit is contained in:
commit
9337c4a738
@ -85,22 +85,20 @@ namespace Display {
|
|||||||
[]{
|
[]{
|
||||||
if (!displayTask.isPerm(tDisplayTimer)) displayTask.restorePerm();
|
if (!displayTask.isPerm(tDisplayTimer)) displayTask.restorePerm();
|
||||||
});
|
});
|
||||||
|
constexpr uint8 threshold = 16;
|
||||||
Task tTimer(MINUTES(1), TASK_FOREVER,
|
Task tTimer(MINUTES(1), TASK_FOREVER,
|
||||||
[]{
|
[]{
|
||||||
static constexpr uint8 threshold = 16;
|
if (tTimer.isFirstIteration()) {
|
||||||
timer.decrease();
|
|
||||||
if (timer.atBeginning()) {
|
|
||||||
if (timer <= threshold) tDisplayTimer.setIterations(TASK_FOREVER);
|
if (timer <= threshold) tDisplayTimer.setIterations(TASK_FOREVER);
|
||||||
displayTask.activate(tDisplayTimer);
|
displayTask.activate(tDisplayTimer);
|
||||||
} else if (timer == threshold) {
|
} else {
|
||||||
tDisplayTimer.setIterations(TASK_FOREVER);
|
timer.decrease();
|
||||||
displayTask.activate(tDisplayTimer);
|
if (timer == threshold) {
|
||||||
|
tDisplayTimer.setIterations(TASK_FOREVER);
|
||||||
|
displayTask.activate(tDisplayTimer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, &ts, false,
|
}, &ts, false, nullptr,
|
||||||
[]{
|
|
||||||
timer.start();
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
[]{
|
[]{
|
||||||
tDisplayTimer.setIterations(TASK_ONCE + 1);
|
tDisplayTimer.setIterations(TASK_ONCE + 1);
|
||||||
displayTask.activate(tDisplayTime);
|
displayTask.activate(tDisplayTime);
|
||||||
|
|||||||
@ -6,26 +6,18 @@ typedef void (*remaining_callback_t)(int8);
|
|||||||
struct : public CallbackAware<remaining_callback_t> {
|
struct : public CallbackAware<remaining_callback_t> {
|
||||||
|
|
||||||
void operator=(int8 value) {
|
void operator=(int8 value) {
|
||||||
initial = remaining = value;
|
remaining = value;
|
||||||
|
if (callback) callback(remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator int8() {
|
operator int8() {
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
|
||||||
remaining = initial + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void decrease() {
|
void decrease() {
|
||||||
remaining--;
|
*this = remaining - 1;
|
||||||
if (callback) callback(remaining);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool atBeginning() {
|
|
||||||
return initial == remaining;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int8 initial = 0, remaining = 0;
|
int8 remaining = 0;
|
||||||
} timer;
|
} timer;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user