Skip to content

Commit 0b3f9fb

Browse files
committed
Initial version of configurable notification timeout
1 parent 6572b50 commit 0b3f9fb

File tree

9 files changed

+140
-14
lines changed

9 files changed

+140
-14
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ list(APPEND SOURCE_FILES
409409
displayapp/screens/settings/Settings.cpp
410410
displayapp/screens/settings/SettingWatchFace.cpp
411411
displayapp/screens/settings/SettingTimeFormat.cpp
412+
displayapp/screens/settings/SettingNotificationTimeout.cpp
412413
displayapp/screens/settings/SettingWeatherFormat.cpp
413414
displayapp/screens/settings/SettingWakeUp.cpp
414415
displayapp/screens/settings/SettingDisplay.cpp

src/components/settings/Settings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ namespace Pinetime {
196196
return settings.clockType;
197197
};
198198

199+
void SetNotificationTimeout(uint32_t notificationTimeout) {
200+
if (notificationTimeout != settings.notificationTimeout) {
201+
settingsChanged = true;
202+
}
203+
settings.notificationTimeout = notificationTimeout;
204+
};
205+
206+
uint32_t GetNotificationTimeout() const {
207+
return settings.notificationTimeout;
208+
};
209+
199210
void SetWeatherFormat(WeatherFormat weatherFormat) {
200211
if (weatherFormat != settings.weatherFormat) {
201212
settingsChanged = true;
@@ -360,6 +371,7 @@ namespace Pinetime {
360371
uint32_t version = settingsVersion;
361372
uint32_t stepsGoal = 10000;
362373
uint32_t screenTimeOut = 15000;
374+
uint32_t notificationTimeout = 7000;
363375

364376
bool alwaysOnDisplay = false;
365377

src/displayapp/DisplayApp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "displayapp/screens/settings/Settings.h"
4343
#include "displayapp/screens/settings/SettingWatchFace.h"
4444
#include "displayapp/screens/settings/SettingTimeFormat.h"
45+
#include "displayapp/screens/settings/SettingNotificationTimeout.h"
4546
#include "displayapp/screens/settings/SettingWeatherFormat.h"
4647
#include "displayapp/screens/settings/SettingWakeUp.h"
4748
#include "displayapp/screens/settings/SettingDisplay.h"
@@ -367,6 +368,7 @@ void DisplayApp::Refresh() {
367368
// Only used for recovery firmware
368369
break;
369370
case Messages::NewNotification:
371+
printf("NewNotification message received\n");
370372
LoadNewScreen(Apps::NotificationsPreview, DisplayApp::FullRefreshDirections::Down);
371373
break;
372374
case Messages::TimerDone: {
@@ -471,6 +473,7 @@ void DisplayApp::Refresh() {
471473
break;
472474
case Messages::ButtonDoubleClicked:
473475
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
476+
printf("Loading NotificationsPreview\n");
474477
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
475478
}
476479
break;
@@ -568,6 +571,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
568571
notificationManager,
569572
systemTask->nimble().alertService(),
570573
motorController,
574+
settingsController,
571575
*systemTask,
572576
Screens::Notifications::Modes::Normal);
573577
break;
@@ -576,6 +580,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
576580
notificationManager,
577581
systemTask->nimble().alertService(),
578582
motorController,
583+
settingsController,
579584
*systemTask,
580585
Screens::Notifications::Modes::Preview);
581586
break;
@@ -601,6 +606,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
601606
});
602607
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
603608
} break;
609+
case Apps::SettingNotificationTimeout:
610+
currentScreen = std::make_unique<Screens::SettingNotificationTimeout>(settingsController);
611+
break;
604612
case Apps::SettingTimeFormat:
605613
currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
606614
break;

src/displayapp/apps/Apps.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace Pinetime {
3535
Settings,
3636
SettingWatchFace,
3737
SettingTimeFormat,
38+
SettingNotificationTimeout,
3839
SettingWeatherFormat,
3940
SettingHeartRate,
4041
SettingDisplay,

src/displayapp/screens/Notifications.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ Notifications::Notifications(DisplayApp* app,
1414
Pinetime::Controllers::NotificationManager& notificationManager,
1515
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
1616
Pinetime::Controllers::MotorController& motorController,
17+
Pinetime::Controllers::Settings& settingsController,
1718
System::SystemTask& systemTask,
1819
Modes mode)
1920
: app {app},
2021
notificationManager {notificationManager},
2122
alertNotificationService {alertNotificationService},
2223
motorController {motorController},
24+
settingsController {settingsController},
2325
wakeLock(systemTask),
2426
mode {mode} {
25-
27+
printf("Notifications: mode=%d, timeoutLength=%lu\n", (int)mode, timeoutLength);
2628
notificationManager.ClearNewNotificationFlag();
2729
auto notification = notificationManager.GetLastNotification();
2830
if (notification.valid) {
@@ -33,10 +35,11 @@ Notifications::Notifications(DisplayApp* app,
3335
notification.category,
3436
notificationManager.NbNotifications(),
3537
alertNotificationService,
36-
motorController);
38+
motorController,
39+
settingsController);
3740
validDisplay = true;
3841
} else {
39-
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController);
42+
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController, settingsController);
4043
validDisplay = false;
4144
}
4245
if (mode == Modes::Preview) {
@@ -109,7 +112,8 @@ void Notifications::Refresh() {
109112
notification.category,
110113
notificationManager.NbNotifications(),
111114
alertNotificationService,
112-
motorController);
115+
motorController,
116+
settingsController);
113117
} else {
114118
running = false;
115119
}
@@ -202,7 +206,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
202206
previousNotification.category,
203207
notificationManager.NbNotifications(),
204208
alertNotificationService,
205-
motorController);
209+
motorController,
210+
settingsController);
206211
}
207212
return true;
208213
case Pinetime::Applications::TouchEvents::SwipeUp: {
@@ -229,7 +234,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
229234
nextNotification.category,
230235
notificationManager.NbNotifications(),
231236
alertNotificationService,
232-
motorController);
237+
motorController,
238+
settingsController);
233239
}
234240
return true;
235241
default:
@@ -245,14 +251,16 @@ namespace {
245251
}
246252

247253
Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService,
248-
Pinetime::Controllers::MotorController& motorController)
254+
Pinetime::Controllers::MotorController& motorController,
255+
Pinetime::Controllers::Settings& settingsController)
249256
: NotificationItem("Notifications",
250257
"No notifications to display",
251258
0,
252259
Controllers::NotificationManager::Categories::Unknown,
253260
0,
254261
alertNotificationService,
255-
motorController) {
262+
motorController,
263+
settingsController) {
256264
}
257265

258266
Notifications::NotificationItem::NotificationItem(const char* title,
@@ -261,8 +269,9 @@ Notifications::NotificationItem::NotificationItem(const char* title,
261269
Controllers::NotificationManager::Categories category,
262270
uint8_t notifNb,
263271
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
264-
Pinetime::Controllers::MotorController& motorController)
265-
: alertNotificationService {alertNotificationService}, motorController {motorController} {
272+
Pinetime::Controllers::MotorController& motorController,
273+
Pinetime::Controllers::Settings& settingsController)
274+
: alertNotificationService {alertNotificationService}, motorController {motorController}, settingsController {settingsController} {
266275
container = lv_cont_create(lv_scr_act(), nullptr);
267276
lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES);
268277
lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);

src/displayapp/screens/Notifications.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "displayapp/screens/Screen.h"
88
#include "components/ble/NotificationManager.h"
99
#include "components/motor/MotorController.h"
10+
#include "components/settings/Settings.h"
1011
#include "systemtask/SystemTask.h"
1112
#include "systemtask/WakeLock.h"
1213

@@ -25,6 +26,7 @@ namespace Pinetime {
2526
Pinetime::Controllers::NotificationManager& notificationManager,
2627
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
2728
Pinetime::Controllers::MotorController& motorController,
29+
Pinetime::Controllers::Settings& settingsController,
2830
System::SystemTask& systemTask,
2931
Modes mode);
3032
~Notifications() override;
@@ -38,14 +40,16 @@ namespace Pinetime {
3840
class NotificationItem {
3941
public:
4042
NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService,
41-
Pinetime::Controllers::MotorController& motorController);
43+
Pinetime::Controllers::MotorController& motorController,
44+
Pinetime::Controllers::Settings& settingsController);
4245
NotificationItem(const char* title,
4346
const char* msg,
4447
uint8_t notifNr,
4548
Controllers::NotificationManager::Categories,
4649
uint8_t notifNb,
4750
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
48-
Pinetime::Controllers::MotorController& motorController);
51+
Pinetime::Controllers::MotorController& motorController,
52+
Pinetime::Controllers::Settings& settingsController);
4953
~NotificationItem();
5054

5155
bool IsRunning() const {
@@ -65,6 +69,7 @@ namespace Pinetime {
6569
lv_obj_t* label_reject;
6670
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
6771
Pinetime::Controllers::MotorController& motorController;
72+
Pinetime::Controllers::Settings& settingsController;
6873

6974
bool running = true;
7075
};
@@ -74,6 +79,7 @@ namespace Pinetime {
7479
Pinetime::Controllers::NotificationManager& notificationManager;
7580
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
7681
Pinetime::Controllers::MotorController& motorController;
82+
Pinetime::Controllers::Settings& settingsController;
7783
System::WakeLock wakeLock;
7884
Modes mode = Modes::Normal;
7985
std::unique_ptr<NotificationItem> currentItem;
@@ -85,7 +91,7 @@ namespace Pinetime {
8591
lv_obj_t* timeoutLine = nullptr;
8692
TickType_t timeoutTickCountStart;
8793

88-
static const TickType_t timeoutLength = pdMS_TO_TICKS(7000);
94+
const TickType_t timeoutLength = pdMS_TO_TICKS(settingsController.GetNotificationTimeout());
8995
bool interacted = true;
9096

9197
bool dismissingNotification = false;
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "displayapp/screens/settings/SettingNotificationTimeout.h"
2+
#include <lvgl/lvgl.h>
3+
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/Styles.h"
5+
#include "displayapp/screens/Screen.h"
6+
#include "displayapp/screens/Symbols.h"
7+
8+
using namespace Pinetime::Applications::Screens;
9+
10+
namespace {
11+
struct Option {
12+
uint32_t notificationTimeout;
13+
const char* name;
14+
};
15+
16+
constexpr std::array<Option, 3> options = {{
17+
{7000, "7s"},
18+
{15000, "15s"},
19+
{30000, "30s"},
20+
}};
21+
22+
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
23+
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
24+
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
25+
if (i >= options.size()) {
26+
optionArray[i].name = "";
27+
optionArray[i].enabled = false;
28+
} else {
29+
optionArray[i].name = options[i].name;
30+
optionArray[i].enabled = true;
31+
}
32+
}
33+
return optionArray;
34+
}
35+
36+
uint32_t GetDefaultOption(uint32_t currentOption) {
37+
for (size_t i = 0; i < options.size(); i++) {
38+
if (options[i].notificationTimeout == currentOption) {
39+
return i;
40+
}
41+
}
42+
return 0;
43+
}
44+
}
45+
46+
SettingNotificationTimeout::SettingNotificationTimeout(Pinetime::Controllers::Settings& settingsController)
47+
: checkboxList(
48+
0,
49+
1,
50+
"Notification\nTimeout",
51+
Symbols::bell,
52+
GetDefaultOption(settingsController.GetNotificationTimeout()),
53+
[&settings = settingsController](uint32_t index) {
54+
settings.SetNotificationTimeout(options[index].notificationTimeout);
55+
settings.SaveSettings();
56+
},
57+
CreateOptionArray()) {
58+
}
59+
60+
SettingNotificationTimeout::~SettingNotificationTimeout() {
61+
lv_obj_clean(lv_scr_act());
62+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <lvgl/lvgl.h>
6+
7+
#include "components/settings/Settings.h"
8+
#include "displayapp/screens/Screen.h"
9+
#include "displayapp/screens/CheckboxList.h"
10+
11+
namespace Pinetime {
12+
13+
namespace Applications {
14+
namespace Screens {
15+
16+
class SettingNotificationTimeout : public Screen {
17+
public:
18+
SettingNotificationTimeout(Pinetime::Controllers::Settings& settingsController);
19+
~SettingNotificationTimeout() override;
20+
21+
private:
22+
CheckboxList checkboxList;
23+
};
24+
}
25+
}
26+
}

src/displayapp/screens/settings/Settings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ namespace Pinetime {
4444

4545
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
4646
{Symbols::clock, "Chimes", Apps::SettingChimes},
47+
{Symbols::bell, "Notifications", Apps::SettingNotificationTimeout},
4748
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
48-
{Symbols::check, "Firmware", Apps::FirmwareValidation},
4949

50+
{Symbols::check, "Firmware", Apps::FirmwareValidation},
5051
{Symbols::shieldAlt, "Over-the-air", Apps::SettingOTA},
5152
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
5253
{Symbols::list, "About", Apps::SysInfo},

0 commit comments

Comments
 (0)