Skip to content

Commit 754ac23

Browse files
author
panky-codes
committed
Reworked based on PR comments.
1 parent abc3002 commit 754ac23

4 files changed

Lines changed: 56 additions & 38 deletions

File tree

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"cmake.configureArgs": [
3+
"-DARM_NONE_EABI_TOOLCHAIN_PATH=/home/panky92/embedded/gcc-arm-none-eabi-9-2020-q2-update",
4+
"-DNRF5_SDK_PATH=/home/panky92/embedded/nRF5_sdk",
5+
"-DUSE_OPENOCD=1"
6+
],
7+
"cmake.buildTask": true,
8+
"files.associations": {
9+
"streambuf": "cpp",
10+
"chrono": "cpp",
11+
"tuple": "cpp",
12+
"functional": "cpp",
13+
"*.tcc": "cpp",
14+
"string": "cpp",
15+
"fstream": "cpp",
16+
"iosfwd": "cpp",
17+
"nrf_rtc.h": "c"
18+
}
19+
}

src/displayapp/screens/ApplicationList.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
5757
std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
5858
std::array<Screens::Tile::Applications, 6> applications {
5959
{{Symbols::map, Apps::Navigation},
60-
{Symbols::asterisk, Apps::Meter},
60+
{Symbols::stopWatch, Apps::StopWatch},
6161
{Symbols::paintbrush, Apps::Paint},
62-
{Symbols::info, Apps::Notifications},
63-
//TODO: Need to find the right place based on comments from JF
64-
{Symbols::stopWatch, Apps::StopWatch},
65-
{"2", Apps::Twos}
62+
{Symbols::info, Apps::Notifications},
63+
{Symbols::paddle, Apps::Paddle},
64+
{"2", Apps::Twos}
6665
}
6766
};
6867

src/displayapp/screens/StopWatch.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void stop_lap_event_handler(lv_obj_t* obj, lv_event_t event) {
4646
}
4747

4848
StopWatch::StopWatch(DisplayApp* app)
49-
: Screen(app), running {true}, currentState {States::INIT}, currentEvent {Events::STOP}, startTime {}, oldTimeElapsed {},
49+
: Screen(app), running {true}, currentState {States::Init}, currentEvent {Events::Stop}, startTime {}, oldTimeElapsed {},
5050
currentTimeSeparated {}, lapBuffer {}, lapNr {}, lapPressed {false} {
5151

5252
time = lv_label_create(lv_scr_act(), nullptr);
@@ -87,9 +87,9 @@ StopWatch::~StopWatch() {
8787

8888
bool StopWatch::Refresh() {
8989
// @startuml CHIP8_state
90-
// State "INIT" as init
91-
// State "RUNNING" as run
92-
// State "HALTED" as halt
90+
// State "Init" as init
91+
// State "Running" as run
92+
// State "Halted" as halt
9393

9494
// [*] --> init
9595
// init -> run : press play
@@ -102,7 +102,7 @@ bool StopWatch::Refresh() {
102102
switch (currentState) {
103103
// Init state when an user first opens the app
104104
// and when a stop/reset button is pressed
105-
case States::INIT: {
105+
case States::Init: {
106106
if (btnStopLap) {
107107
lv_obj_del(btnStopLap);
108108
}
@@ -115,7 +115,7 @@ bool StopWatch::Refresh() {
115115
lapBuffer.clearBuffer();
116116
lapNr = 0;
117117

118-
if (currentEvent == Events::PLAY) {
118+
if (currentEvent == Events::Play) {
119119
btnStopLap = lv_btn_create(lv_scr_act(), nullptr);
120120
btnStopLap->user_data = this;
121121
lv_obj_set_event_cb(btnStopLap, stop_lap_event_handler);
@@ -125,11 +125,11 @@ bool StopWatch::Refresh() {
125125
lv_label_set_text(txtStopLap, Symbols::lapsFlag);
126126

127127
startTime = xTaskGetTickCount();
128-
currentState = States::RUNNING;
128+
currentState = States::Running;
129129
}
130130
break;
131131
}
132-
case States::RUNNING: {
132+
case States::Running: {
133133
lv_label_set_text(txtPlayPause, Symbols::pause);
134134
lv_label_set_text(txtStopLap, Symbols::lapsFlag);
135135

@@ -150,25 +150,25 @@ bool StopWatch::Refresh() {
150150
lapPressed = false;
151151
}
152152

153-
if (currentEvent == Events::PAUSE) {
153+
if (currentEvent == Events::Pause) {
154154
// Reset the start time
155155
startTime = 0;
156156
// Store the current time elapsed in cache
157157
oldTimeElapsed += timeElapsed;
158-
currentState = States::HALTED;
158+
currentState = States::Halted;
159159
}
160160
break;
161161
}
162-
case States::HALTED: {
162+
case States::Halted: {
163163
lv_label_set_text(txtPlayPause, Symbols::play);
164164
lv_label_set_text(txtStopLap, Symbols::stop);
165165

166-
if (currentEvent == Events::PLAY) {
166+
if (currentEvent == Events::Play) {
167167
startTime = xTaskGetTickCount();
168-
currentState = States::RUNNING;
168+
currentState = States::Running;
169169
}
170-
if (currentEvent == Events::STOP) {
171-
currentState = States::INIT;
170+
if (currentEvent == Events::Stop) {
171+
currentState = States::Init;
172172
oldTimeElapsed = 0;
173173
}
174174
break;
@@ -184,25 +184,25 @@ bool StopWatch::OnButtonPushed() {
184184

185185
void StopWatch::playPauseBtnEventHandler(lv_event_t event) {
186186
if (event == LV_EVENT_CLICKED) {
187-
if (currentState == States::INIT) {
188-
currentEvent = Events::PLAY;
187+
if (currentState == States::Init) {
188+
currentEvent = Events::Play;
189189
} else {
190190
// Simple Toggle for play/pause
191-
currentEvent = (currentEvent == Events::PLAY ? Events::PAUSE : Events::PLAY);
191+
currentEvent = (currentEvent == Events::Play ? Events::Pause : Events::Play);
192192
}
193193
}
194194
}
195195

196196
void StopWatch::stopLapBtnEventHandler(lv_event_t event) {
197197
if (event == LV_EVENT_CLICKED) {
198198
// If running, then this button is used to save laps
199-
if (currentState == States::RUNNING) {
199+
if (currentState == States::Running) {
200200
lapBuffer.addLaps(currentTimeSeparated);
201201
lapNr++;
202202
lapPressed = true;
203203

204-
} else if (currentState == States::HALTED) {
205-
currentEvent = Events::STOP;
204+
} else if (currentState == States::Halted) {
205+
currentEvent = Events::Stop;
206206
} else {
207207
// Not possible to reach here. Do nothing.
208208
}

src/displayapp/screens/StopWatch.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
namespace Pinetime::Applications::Screens {
1313

14-
enum class States { INIT, RUNNING, HALTED };
14+
enum class States { Init, Running, Halted };
1515

16-
enum class Events { PLAY, PAUSE, STOP };
16+
enum class Events { Play, Pause, Stop };
1717

1818
struct TimeSeparated_t {
1919
int mins;
@@ -23,40 +23,40 @@ namespace Pinetime::Applications::Screens {
2323

2424
// A simple buffer to hold the latest two laps
2525
template <int N> struct LapTextBuffer_t {
26-
LapTextBuffer_t() : _arr {}, currentSz {}, capacity {N}, head {-1} {
26+
LapTextBuffer_t() : buffer {}, currentSize {}, capacity {N}, head {-1} {
2727
}
2828

2929
void addLaps(const TimeSeparated_t& timeVal) {
3030
head++;
3131
head %= capacity;
32-
_arr[head] = timeVal;
32+
buffer[head] = timeVal;
3333

34-
if (currentSz < capacity) {
35-
currentSz++;
34+
if (currentSize < capacity) {
35+
currentSize++;
3636
}
3737
}
3838

3939
void clearBuffer() {
40-
_arr = {};
41-
currentSz = 0;
40+
buffer = {};
41+
currentSize = 0;
4242
head = -1;
4343
}
4444

4545
TimeSeparated_t* operator[](std::size_t idx) {
4646
// Sanity check for out-of-bounds
4747
if (idx >= 0 && idx < capacity) {
48-
if (idx < currentSz) {
48+
if (idx < currentSize) {
4949
// This transformation is to ensure that head is always pointing to index 0.
5050
const auto transformed_idx = (head - idx) % capacity;
51-
return (&_arr[transformed_idx]);
51+
return (&buffer[transformed_idx]);
5252
}
5353
}
5454
return nullptr;
5555
}
5656

5757
private:
58-
std::array<TimeSeparated_t, N> _arr;
59-
uint8_t currentSz;
58+
std::array<TimeSeparated_t, N> buffer;
59+
uint8_t currentSize;
6060
uint8_t capacity;
6161
int8_t head;
6262
};

0 commit comments

Comments
 (0)