Skip to content

Commit 13e3463

Browse files
authored
Timer App (#355)
* built timer app * Style improvements * making sure buttons stay hidden when the app is reopened and reappear after the timer runs out * more sensible calculations of time deltas. eliminated that mysterious scaling factor * changing the timer icon
1 parent 8c3b250 commit 13e3463

16 files changed

Lines changed: 385 additions & 22 deletions

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ list(APPEND SOURCE_FILES
407407
displayapp/screens/List.cpp
408408
displayapp/screens/BatteryInfo.cpp
409409
displayapp/screens/Steps.cpp
410+
displayapp/screens/Timer.cpp
410411

411412
## Settings
412413
displayapp/screens/settings/QuickSettings.cpp
@@ -459,6 +460,7 @@ list(APPEND SOURCE_FILES
459460
components/firmwarevalidator/FirmwareValidator.cpp
460461
components/motor/MotorController.cpp
461462
components/settings/Settings.cpp
463+
components/timer/TimerController.cpp
462464
drivers/Cst816s.cpp
463465
FreeRTOS/port.c
464466
FreeRTOS/port_cmsis_systick.c
@@ -520,6 +522,7 @@ list(APPEND RECOVERY_SOURCE_FILES
520522
components/ble/HeartRateService.cpp
521523
components/firmwarevalidator/FirmwareValidator.cpp
522524
components/settings/Settings.cpp
525+
components/timer/TimerController.cpp
523526
drivers/Cst816s.cpp
524527
FreeRTOS/port.c
525528
FreeRTOS/port_cmsis_systick.c
@@ -590,6 +593,7 @@ set(INCLUDE_FILES
590593
displayapp/screens/Notifications.h
591594
displayapp/screens/HeartRate.h
592595
displayapp/screens/Motion.h
596+
displayapp/screens/Timer.h
593597
drivers/St7789.h
594598
drivers/SpiNorFlash.h
595599
drivers/SpiMaster.h
@@ -619,6 +623,7 @@ set(INCLUDE_FILES
619623
components/ble/BleClient.h
620624
components/ble/HeartRateService.h
621625
components/settings/Settings.h
626+
components/timer/TimerController.h
622627
drivers/Cst816s.h
623628
FreeRTOS/portmacro.h
624629
FreeRTOS/portmacro_cmsis.h

src/components/motor/MotorController.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
1313
void MotorController::Init() {
1414
nrf_gpio_cfg_output(pinMotor);
1515
nrf_gpio_pin_set(pinMotor);
16-
app_timer_init();
1716
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
1817
}
1918

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// Created by florian on 16.05.21.
3+
//
4+
5+
#include "TimerController.h"
6+
#include "systemtask/SystemTask.h"
7+
#include "app_timer.h"
8+
#include "task.h"
9+
10+
using namespace Pinetime::Controllers;
11+
12+
13+
APP_TIMER_DEF(timerAppTimer);
14+
15+
16+
TimerController::TimerController(System::SystemTask& systemTask) : systemTask{systemTask} {
17+
}
18+
19+
20+
void TimerController::Init() {
21+
app_timer_create(&timerAppTimer, APP_TIMER_MODE_SINGLE_SHOT, timerEnd);
22+
23+
}
24+
25+
void TimerController::StartTimer(uint32_t duration) {
26+
app_timer_stop(timerAppTimer);
27+
auto currentTicks = xTaskGetTickCount();
28+
app_timer_start(timerAppTimer, APP_TIMER_TICKS(duration), this);
29+
endTicks = currentTicks + APP_TIMER_TICKS(duration);
30+
timerRunning = true;
31+
}
32+
33+
uint32_t TimerController::GetTimeRemaining() {
34+
if (!timerRunning) {
35+
return 0;
36+
}
37+
auto currentTicks = xTaskGetTickCount();
38+
39+
TickType_t deltaTicks = 0;
40+
if (currentTicks > endTicks) {
41+
deltaTicks = 0xffffffff - currentTicks;
42+
deltaTicks += (endTicks + 1);
43+
} else {
44+
deltaTicks = endTicks - currentTicks;
45+
}
46+
47+
return (static_cast<TickType_t>(deltaTicks) / static_cast<TickType_t>(configTICK_RATE_HZ)) * 1000;
48+
}
49+
50+
void TimerController::timerEnd(void* p_context) {
51+
52+
auto* controller = static_cast<Controllers::TimerController*> (p_context);
53+
controller->timerRunning = false;
54+
controller->systemTask.PushMessage(System::SystemTask::Messages::OnTimerDone);
55+
}
56+
57+
void TimerController::StopTimer() {
58+
app_timer_stop(timerAppTimer);
59+
timerRunning = false;
60+
}
61+
62+
bool TimerController::IsRunning() {
63+
return timerRunning;
64+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include "app_timer.h"
5+
#include "portmacro_cmsis.h"
6+
7+
namespace Pinetime {
8+
namespace System {
9+
class SystemTask;
10+
}
11+
namespace Controllers {
12+
13+
class TimerController {
14+
public:
15+
TimerController(Pinetime::System::SystemTask& systemTask);
16+
17+
void Init();
18+
19+
void StartTimer(uint32_t duration);
20+
21+
void StopTimer();
22+
23+
uint32_t GetTimeRemaining();
24+
25+
bool IsRunning();
26+
27+
private:
28+
System::SystemTask& systemTask;
29+
30+
static void timerEnd(void* p_context);
31+
32+
TickType_t endTicks;
33+
bool timerRunning = false;
34+
};
35+
}
36+
}

src/displayapp/Apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Pinetime {
1111
FirmwareValidation,
1212
NotificationsPreview,
1313
Notifications,
14+
Timer,
1415
FlashLight,
1516
BatteryInfo,
1617
Music,

src/displayapp/DisplayApp.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <libraries/log/nrf_log.h>
33
#include <displayapp/screens/HeartRate.h>
44
#include <displayapp/screens/Motion.h>
5+
#include <displayapp/screens/Timer.h>
56
#include "components/battery/BatteryController.h"
67
#include "components/ble/BleController.h"
78
#include "components/datetime/DateTimeController.h"
@@ -55,7 +56,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
5556
Pinetime::Controllers::HeartRateController& heartRateController,
5657
Controllers::Settings& settingsController,
5758
Pinetime::Controllers::MotorController& motorController,
58-
Pinetime::Controllers::MotionController& motionController)
59+
Pinetime::Controllers::MotionController& motionController,
60+
Pinetime::Controllers::TimerController& timerController)
5961
: lcd {lcd},
6062
lvgl {lvgl},
6163
touchPanel {touchPanel},
@@ -68,7 +70,8 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
6870
heartRateController {heartRateController},
6971
settingsController {settingsController},
7072
motorController {motorController},
71-
motionController {motionController} {
73+
motionController {motionController},
74+
timerController {timerController} {
7275
msgQueue = xQueueCreate(queueSize, itemSize);
7376
// Start clock when smartwatch boots
7477
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
@@ -148,6 +151,14 @@ void DisplayApp::Refresh() {
148151
case Messages::NewNotification:
149152
LoadApp(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
150153
break;
154+
case Messages::TimerDone:
155+
if (currentApp == Apps::Timer) {
156+
auto *timer = dynamic_cast<Screens::Timer*>(currentScreen.get());
157+
timer->setDone();
158+
} else {
159+
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
160+
}
161+
break;
151162
case Messages::TouchEvent: {
152163
if (state != States::Running)
153164
break;
@@ -264,6 +275,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
264275
this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview);
265276
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
266277
break;
278+
case Apps::Timer:
279+
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
280+
break;
267281

268282
// Settings
269283
case Apps::QuickSettings:

src/displayapp/DisplayApp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "components/firmwarevalidator/FirmwareValidator.h"
1313
#include "components/settings/Settings.h"
1414
#include "displayapp/screens/Screen.h"
15+
#include "components/timer/TimerController.h"
1516
#include "Messages.h"
1617

1718
namespace Pinetime {
@@ -53,7 +54,8 @@ namespace Pinetime {
5354
Pinetime::Controllers::HeartRateController& heartRateController,
5455
Controllers::Settings& settingsController,
5556
Pinetime::Controllers::MotorController& motorController,
56-
Pinetime::Controllers::MotionController& motionController);
57+
Pinetime::Controllers::MotionController& motionController,
58+
Pinetime::Controllers::TimerController& timerController);
5759
void Start();
5860
void PushMessage(Display::Messages msg);
5961

@@ -76,6 +78,7 @@ namespace Pinetime {
7678
Pinetime::Controllers::Settings& settingsController;
7779
Pinetime::Controllers::MotorController& motorController;
7880
Pinetime::Controllers::MotionController& motionController;
81+
Pinetime::Controllers::TimerController& timerController;
7982

8083
Pinetime::Controllers::FirmwareValidator validator;
8184
Controllers::BrightnessController brightnessController;

src/displayapp/Messages.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Pinetime {
1111
TouchEvent,
1212
ButtonPushed,
1313
NewNotification,
14+
TimerDone,
1415
BleFirmwareUpdateStarted,
1516
UpdateTimeOut
1617
};

src/displayapp/fonts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Do not enable font compression and horizontal subpixel hinting
1313
* Load the file `JetBrainsMono-Bold.tff` and specify the following range : `0x20-0x7f, 0x410-0x44f`
1414
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
15-
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024`
15+
range : `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252`
1616
* Click on Convert, and download the file `jetbrains_mono_bold_20.c` and copy it in `src/DisplayApp/Fonts`
1717

1818
Add new symbols:

src/displayapp/fonts/jetbrains_mono_bold_20.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,13 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t gylph_bitmap[] = {
900900
0x7, 0xe0, 0x0, 0x7, 0xf0, 0x0, 0x3, 0xff,
901901
0xff, 0xff, 0xcf, 0xff, 0xff, 0xe0,
902902

903+
/* U+F252 "" */
904+
0xff, 0xff, 0xff, 0xfd, 0x80, 0x33, 0x80, 0xe7,
905+
0xff, 0xc7, 0xff, 0xf, 0xfe, 0xf, 0xf8, 0xf,
906+
0xe0, 0xf, 0x80, 0x7f, 0xc0, 0xe3, 0x83, 0x83,
907+
0x86, 0x3, 0x1f, 0xff, 0x3f, 0xfe, 0x7f, 0xfd,
908+
0xff, 0xff, 0xff, 0xf8,
909+
903910
/* U+F293 "" */
904911
0x7, 0xe0, 0x3f, 0xe0, 0xfb, 0xe3, 0xf3, 0xe7,
905912
0xe3, 0xdf, 0xd3, 0xf9, 0xb3, 0xf9, 0x4f, 0xf8,
@@ -1184,17 +1191,18 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
11841191
{.bitmap_index = 3380, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
11851192
{.bitmap_index = 3418, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
11861193
{.bitmap_index = 3456, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
1187-
{.bitmap_index = 3494, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
1188-
{.bitmap_index = 3532, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1189-
{.bitmap_index = 3561, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
1190-
{.bitmap_index = 3599, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1191-
{.bitmap_index = 3665, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
1192-
{.bitmap_index = 3714, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
1193-
{.bitmap_index = 3764, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
1194-
{.bitmap_index = 3824, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1195-
{.bitmap_index = 3877, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
1196-
{.bitmap_index = 3932, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
1197-
{.bitmap_index = 3985, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
1194+
{.bitmap_index = 3494, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
1195+
{.bitmap_index = 3530, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
1196+
{.bitmap_index = 3568, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1197+
{.bitmap_index = 3597, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
1198+
{.bitmap_index = 3635, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1199+
{.bitmap_index = 3701, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
1200+
{.bitmap_index = 3750, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
1201+
{.bitmap_index = 3800, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
1202+
{.bitmap_index = 3860, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
1203+
{.bitmap_index = 3913, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
1204+
{.bitmap_index = 3968, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
1205+
{.bitmap_index = 4021, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
11981206
};
11991207

12001208
/*---------------------
@@ -1205,8 +1213,8 @@ static const uint16_t unicode_list_2[] = {
12051213
0x0, 0x16, 0x23, 0x26, 0x27, 0x28, 0x39, 0x47,
12061214
0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x94, 0x128, 0x184,
12071215
0x1e5, 0x1fb, 0x21d, 0x23f, 0x240, 0x241, 0x242, 0x243,
1208-
0x292, 0x293, 0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a, 0x55f,
1209-
0x59e, 0x59f, 0x6a8
1216+
0x251, 0x292, 0x293, 0x2f1, 0x3dc, 0x3fc, 0x45c, 0x54a,
1217+
0x55f, 0x59e, 0x59f, 0x6a8
12101218
};
12111219

12121220
/*Collect the unicode lists and glyph_id offsets*/
@@ -1222,7 +1230,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
12221230
},
12231231
{
12241232
.range_start = 61441, .range_length = 1705, .glyph_id_start = 160,
1225-
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 35, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
1233+
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 36, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
12261234
}
12271235
};
12281236

0 commit comments

Comments
 (0)