Added some comments for clarity. Ready for review. Tested.
This commit is contained in:
parent
02824d0671
commit
d409643b8e
2 changed files with 15 additions and 3 deletions
|
@ -85,7 +85,19 @@ StopWatch::~StopWatch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StopWatch::Refresh() {
|
bool StopWatch::Refresh() {
|
||||||
|
// @startuml CHIP8_state
|
||||||
|
// State "INIT" as init
|
||||||
|
// State "RUNNING" as run
|
||||||
|
// State "HALTED" as halt
|
||||||
|
|
||||||
|
// [*] --> init
|
||||||
|
// init -> run : press play
|
||||||
|
// run -> run : press lap
|
||||||
|
// run --> halt : press pause
|
||||||
|
// halt --> run : press play
|
||||||
|
// halt --> init : press stop
|
||||||
|
// @enduml
|
||||||
|
// Copy paste the above plantuml text to visualize the state diagram
|
||||||
switch (currentState) {
|
switch (currentState) {
|
||||||
// Init state when an user first opens the app
|
// Init state when an user first opens the app
|
||||||
// and when a stop/reset button is pressed
|
// and when a stop/reset button is pressed
|
||||||
|
@ -132,7 +144,7 @@ bool StopWatch::Refresh() {
|
||||||
if (lapBuffer[0]) {
|
if (lapBuffer[0]) {
|
||||||
lv_label_set_text_fmt(lapTwoText, "#%d %d:%d:%d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->msecs);
|
lv_label_set_text_fmt(lapTwoText, "#%d %d:%d:%d", lapNr, lapBuffer[0]->mins, lapBuffer[0]->secs, lapBuffer[0]->msecs);
|
||||||
}
|
}
|
||||||
// Reset the bool to avoid setting the text in each cycle
|
// Reset the bool to avoid setting the text in each cycle until there is a change
|
||||||
lapPressed = false;
|
lapPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ namespace Pinetime::Applications::Screens {
|
||||||
int msecs;
|
int msecs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A simple buffer to hold the latest two laps
|
||||||
template <int N> struct LapTextBuffer_t {
|
template <int N> struct LapTextBuffer_t {
|
||||||
LapTextBuffer_t() : _arr {}, currentSz {}, capacity {N}, head {-1} {
|
LapTextBuffer_t() : _arr {}, currentSz {}, capacity {N}, head {-1} {
|
||||||
}
|
}
|
||||||
|
@ -41,11 +42,11 @@ namespace Pinetime::Applications::Screens {
|
||||||
head = -1;
|
head = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional return type would be much more appropriate here
|
|
||||||
TimeSeparated_t* operator[](std::size_t idx) {
|
TimeSeparated_t* operator[](std::size_t idx) {
|
||||||
// Sanity check for out-of-bounds
|
// Sanity check for out-of-bounds
|
||||||
if (idx >= 0 && idx < capacity) {
|
if (idx >= 0 && idx < capacity) {
|
||||||
if (idx < currentSz) {
|
if (idx < currentSz) {
|
||||||
|
// This transformation is to ensure that head is always pointing to index 0.
|
||||||
const auto transformed_idx = (head - idx) % capacity;
|
const auto transformed_idx = (head - idx) % capacity;
|
||||||
return (&_arr[transformed_idx]);
|
return (&_arr[transformed_idx]);
|
||||||
}
|
}
|
||||||
|
@ -66,7 +67,6 @@ namespace Pinetime::Applications::Screens {
|
||||||
~StopWatch() override;
|
~StopWatch() override;
|
||||||
bool Refresh() override;
|
bool Refresh() override;
|
||||||
bool OnButtonPushed() override;
|
bool OnButtonPushed() override;
|
||||||
bool OnTouchEvent(uint16_t x, uint16_t y) override;
|
|
||||||
void playPauseBtnEventHandler(lv_event_t event);
|
void playPauseBtnEventHandler(lv_event_t event);
|
||||||
void stopLapBtnEventHandler(lv_event_t event);
|
void stopLapBtnEventHandler(lv_event_t event);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue