ceiling Rest time depending on smallest displayed time-unit
This commit is contained in:
parent
4fe7d9cb81
commit
87509eb5f1
@ -8,6 +8,14 @@
|
|||||||
#include "Rest.h"
|
#include "Rest.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
|
#define DEC_MIL ( 100 )
|
||||||
|
#define SEC_MIL ( 1000 )
|
||||||
|
#define MIN_MIL ( 60 * SEC_MIL )
|
||||||
|
#define HOU_MIL ( 60 * MIN_MIL )
|
||||||
|
#define DAY_MIL ( 24 * HOU_MIL )
|
||||||
|
|
||||||
|
#define ENABLE_DECIS false
|
||||||
|
|
||||||
enum Stage {
|
enum Stage {
|
||||||
FIRST_HALF, SECOND_HALF, LAST_MINUTE, FINALE
|
FIRST_HALF, SECOND_HALF, LAST_MINUTE, FINALE
|
||||||
};
|
};
|
||||||
@ -69,7 +77,6 @@ class ModeTimer final : public Mode {
|
|||||||
Rest last{0};
|
Rest last{0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit ModeTimer()
|
explicit ModeTimer()
|
||||||
: Mode("Timer"),
|
: Mode("Timer"),
|
||||||
countdown("countdown", [this]() {
|
countdown("countdown", [this]() {
|
||||||
@ -140,7 +147,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw(Display &display) override {
|
void draw(Display &display) override {
|
||||||
rest = Rest(countdown.getRestMillis());
|
if (countdown.getRestMillis() >= DAY_MIL) {
|
||||||
|
rest = Rest(intCeilDiv(countdown.getRestMillis(), HOU_MIL) * HOU_MIL);
|
||||||
|
} else if (countdown.getRestMillis() >= MIN_MIL) {
|
||||||
|
rest = Rest(intCeilDiv(countdown.getRestMillis(), SEC_MIL) * SEC_MIL);
|
||||||
|
} else {
|
||||||
|
#if ENABLE_DECIS
|
||||||
|
rest = Rest(intCeilDiv(countdown.getRestMillis(), DEC_MIL) * DEC_MIL);
|
||||||
|
#else
|
||||||
|
rest = Rest(intCeilDiv(countdown.getRestMillis(), SEC_MIL) * SEC_MIL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
display.clear();
|
display.clear();
|
||||||
if (flash.isRunning()) {
|
if (flash.isRunning()) {
|
||||||
@ -174,7 +191,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void doBeep(const uint32_t count) {
|
void doBeep(const uint32_t count) {
|
||||||
beepSet(true);
|
beepSet(true);
|
||||||
beep.startCount(count * 2 - 1);
|
beep.startCount(count * 2 - 1);
|
||||||
@ -215,7 +231,8 @@ private:
|
|||||||
dirty |= rest.hourChanged(last);
|
dirty |= rest.hourChanged(last);
|
||||||
dirtyPrint = true;
|
dirtyPrint = true;
|
||||||
} else if (rest.hoursTotal > 0) {
|
} else if (rest.hoursTotal > 0) {
|
||||||
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d:%02d:%02d", rest.hoursPart, rest.minutesPart, rest.secondsPart);
|
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d:%02d:%02d", rest.hoursPart, rest.minutesPart,
|
||||||
|
rest.secondsPart);
|
||||||
dirty |= rest.secondChanged(last);
|
dirty |= rest.secondChanged(last);
|
||||||
dirtyPrint = true;
|
dirtyPrint = true;
|
||||||
} else if (rest.minutesTotal > 0) {
|
} else if (rest.minutesTotal > 0) {
|
||||||
@ -223,7 +240,15 @@ private:
|
|||||||
dirty |= rest.secondChanged(last);
|
dirty |= rest.secondChanged(last);
|
||||||
dirtyPrint = true;
|
dirtyPrint = true;
|
||||||
} else {
|
} else {
|
||||||
|
#if ENABLE_DECIS
|
||||||
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d.%d", rest.secondsPart, rest.decisPart);
|
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d.%d", rest.secondsPart, rest.decisPart);
|
||||||
|
#else
|
||||||
|
if (rest.secondsTotal > 9) {
|
||||||
|
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d", rest.secondsPart, rest.secondsPart);
|
||||||
|
} else {
|
||||||
|
display.print(16, 0, ALIGN_CENTER, FONT7, color, "%d %d %d", rest.secondsPart, rest.secondsPart, rest.secondsPart);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
dirty |= rest.deciChanged(last);
|
dirty |= rest.deciChanged(last);
|
||||||
dirtyPrint |= rest.secondChanged(last);
|
dirtyPrint |= rest.secondChanged(last);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
#ifndef REST_H
|
#ifndef REST_H
|
||||||
#define REST_H
|
#define REST_H
|
||||||
|
|
||||||
|
inline uint32_t intCeilDiv(const uint32_t dividend, const uint32_t divisor) {
|
||||||
|
if (dividend == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (dividend + divisor - 1) / divisor;
|
||||||
|
}
|
||||||
|
|
||||||
struct Rest {
|
struct Rest {
|
||||||
|
|
||||||
uint64_t millisTotal;
|
uint64_t millisTotal;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user