Skip to content

Commit ffff67a

Browse files
committed
feat: add notification and chime vibration settings
1 parent ff352f4 commit ffff67a

11 files changed

+248
-5
lines changed

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,8 @@ list(APPEND SOURCE_FILES
418418
displayapp/screens/settings/SettingChimes.cpp
419419
displayapp/screens/settings/SettingShakeThreshold.cpp
420420
displayapp/screens/settings/SettingBluetooth.cpp
421+
displayapp/screens/settings/SettingNotifVibration.cpp
422+
displayapp/screens/settings/SettingChimeVibration.cpp
421423

422424
## Watch faces
423425
displayapp/screens/WatchFaceAnalog.cpp

src/components/settings/Settings.h

+26
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace Pinetime {
3434
Orange,
3535
Pink
3636
};
37+
enum class VibrationStrength : uint8_t { Weak = 15, Normal = 35, Strong = 75 };
3738
enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric };
3839
enum class PTSWeather : uint8_t { On, Off };
3940

@@ -283,6 +284,28 @@ namespace Pinetime {
283284
return bleRadioEnabled;
284285
};
285286

287+
void SetNotifVibration(VibrationStrength strength) {
288+
if (strength != settings.notifVibration) {
289+
settingsChanged = true;
290+
}
291+
settings.notifVibration = strength;
292+
};
293+
294+
VibrationStrength GetNotifVibration() const {
295+
return settings.notifVibration;
296+
}
297+
298+
void SetChimeVibration(VibrationStrength strength) {
299+
if (strength != settings.chimeVibration) {
300+
settingsChanged = true;
301+
}
302+
settings.chimeVibration = strength;
303+
};
304+
305+
VibrationStrength GetChimeVibration() const {
306+
return settings.chimeVibration;
307+
}
308+
286309
private:
287310
Pinetime::Controllers::FS& fs;
288311

@@ -308,6 +331,9 @@ namespace Pinetime {
308331
uint16_t shakeWakeThreshold = 150;
309332

310333
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
334+
335+
VibrationStrength notifVibration = VibrationStrength::Normal;
336+
VibrationStrength chimeVibration = VibrationStrength::Normal;
311337
};
312338

313339
SettingsData settings;

src/displayapp/DisplayApp.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#include "displayapp/screens/settings/SettingChimes.h"
5050
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5151
#include "displayapp/screens/settings/SettingBluetooth.h"
52+
#include "displayapp/screens/settings/SettingNotifVibration.h"
53+
#include "displayapp/screens/settings/SettingChimeVibration.h"
5254

5355
#include "libs/lv_conf.h"
5456
#include "UserApps.h"
@@ -270,7 +272,7 @@ void DisplayApp::Refresh() {
270272
} else {
271273
LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up);
272274
}
273-
motorController.RunForDuration(35);
275+
motorController.RunForDuration(static_cast<uint8_t>(settingsController.GetNotifVibration()));
274276
break;
275277
case Messages::AlarmTriggered:
276278
if (currentApp == Apps::Alarm) {
@@ -282,7 +284,7 @@ void DisplayApp::Refresh() {
282284
break;
283285
case Messages::ShowPairingKey:
284286
LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up);
285-
motorController.RunForDuration(35);
287+
motorController.RunForDuration(static_cast<uint8_t>(settingsController.GetNotifVibration()));
286288
break;
287289
case Messages::TouchEvent: {
288290
if (state != States::Running) {
@@ -375,7 +377,7 @@ void DisplayApp::Refresh() {
375377
break;
376378
case Messages::Chime:
377379
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
378-
motorController.RunForDuration(35);
380+
motorController.RunForDuration(static_cast<uint8_t>(settingsController.GetChimeVibration()));
379381
break;
380382
case Messages::OnChargingEvent:
381383
RestoreBrightness();
@@ -465,6 +467,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
465467
notificationManager,
466468
systemTask->nimble().alertService(),
467469
motorController,
470+
settingsController,
468471
*systemTask,
469472
Screens::Notifications::Modes::Normal);
470473
break;
@@ -473,6 +476,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
473476
notificationManager,
474477
systemTask->nimble().alertService(),
475478
motorController,
479+
settingsController,
476480
*systemTask,
477481
Screens::Notifications::Modes::Preview);
478482
break;
@@ -524,6 +528,12 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
524528
case Apps::SettingBluetooth:
525529
currentScreen = std::make_unique<Screens::SettingBluetooth>(this, settingsController);
526530
break;
531+
case Apps::SettingNotifVibration:
532+
currentScreen = std::make_unique<Screens::SettingNotifVibration>(settingsController, motorController);
533+
break;
534+
case Apps::SettingChimeVibration:
535+
currentScreen = std::make_unique<Screens::SettingChimeVibration>(settingsController, motorController);
536+
break;
527537
case Apps::BatteryInfo:
528538
currentScreen = std::make_unique<Screens::BatteryInfo>(batteryController);
529539
break;

src/displayapp/apps/Apps.h.in

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace Pinetime {
4242
SettingChimes,
4343
SettingShakeThreshold,
4444
SettingBluetooth,
45+
SettingNotifVibration,
46+
SettingChimeVibration,
4547
Error
4648
};
4749

src/displayapp/screens/Notifications.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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},
@@ -44,7 +45,7 @@ Notifications::Notifications(DisplayApp* app,
4445
if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
4546
motorController.StartRinging();
4647
} else {
47-
motorController.RunForDuration(35);
48+
motorController.RunForDuration(static_cast<uint8_t>(settingsController.GetNotifVibration()));
4849
}
4950

5051
timeoutLine = lv_line_create(lv_scr_act(), nullptr);

src/displayapp/screens/Notifications.h

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Pinetime {
2424
Pinetime::Controllers::NotificationManager& notificationManager,
2525
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
2626
Pinetime::Controllers::MotorController& motorController,
27+
Pinetime::Controllers::Settings& settingsController,
2728
System::SystemTask& systemTask,
2829
Modes mode);
2930
~Notifications() override;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "displayapp/screens/settings/SettingChimeVibration.h"
2+
3+
#include <lvgl/lvgl.h>
4+
5+
#include "displayapp/DisplayApp.h"
6+
#include "displayapp/screens/Styles.h"
7+
#include "displayapp/screens/Screen.h"
8+
#include "displayapp/screens/Symbols.h"
9+
10+
using namespace Pinetime::Applications::Screens;
11+
12+
namespace {
13+
struct Option {
14+
Pinetime::Controllers::Settings::VibrationStrength vibrationStrength;
15+
const char* name;
16+
};
17+
18+
constexpr std::array<Option, 3> options = {{
19+
{Pinetime::Controllers::Settings::VibrationStrength::Weak, "Weak"},
20+
{Pinetime::Controllers::Settings::VibrationStrength::Normal, "Normal"},
21+
{Pinetime::Controllers::Settings::VibrationStrength::Strong, "Strong"},
22+
}};
23+
24+
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
25+
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
26+
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
27+
if (i >= options.size()) {
28+
optionArray[i].name = "";
29+
optionArray[i].enabled = false;
30+
} else {
31+
optionArray[i].name = options[i].name;
32+
optionArray[i].enabled = true;
33+
}
34+
}
35+
return optionArray;
36+
}
37+
38+
uint32_t GetDefaultOption(Pinetime::Controllers::Settings::VibrationStrength currentOption) {
39+
for (size_t i = 0; i < options.size(); i++) {
40+
if (options[i].vibrationStrength == currentOption) {
41+
return i;
42+
}
43+
}
44+
return 0;
45+
}
46+
}
47+
48+
SettingChimeVibration::SettingChimeVibration(
49+
Pinetime::Controllers::Settings& settingsController,
50+
Pinetime::Controllers::MotorController& motorController
51+
)
52+
: checkboxList(
53+
0,
54+
1,
55+
"Chime strength",
56+
Symbols::tachometer,
57+
GetDefaultOption(settingsController.GetChimeVibration()),
58+
[&settings = settingsController, &motor = motorController](uint32_t index) {
59+
// Preview current setting
60+
motor.RunForDuration(static_cast<uint8_t>(options[index].vibrationStrength));
61+
62+
settings.SetChimeVibration(options[index].vibrationStrength);
63+
settings.SaveSettings();
64+
},
65+
CreateOptionArray()) {
66+
}
67+
68+
SettingChimeVibration::~SettingChimeVibration() {
69+
lv_obj_clean(lv_scr_act());
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <lvgl/lvgl.h>
6+
7+
#include "components/settings/Settings.h"
8+
#include "components/motor/MotorController.h"
9+
#include "displayapp/screens/Screen.h"
10+
#include "displayapp/screens/CheckboxList.h"
11+
12+
namespace Pinetime {
13+
14+
namespace Applications {
15+
namespace Screens {
16+
17+
class SettingChimeVibration : public Screen {
18+
public:
19+
explicit SettingChimeVibration(
20+
Pinetime::Controllers::Settings& settingsController,
21+
Pinetime::Controllers::MotorController& motorController
22+
);
23+
~SettingChimeVibration() override;
24+
25+
private:
26+
CheckboxList checkboxList;
27+
};
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "displayapp/screens/settings/SettingNotifVibration.h"
2+
3+
#include <lvgl/lvgl.h>
4+
5+
#include "displayapp/DisplayApp.h"
6+
#include "displayapp/screens/Styles.h"
7+
#include "displayapp/screens/Screen.h"
8+
#include "displayapp/screens/Symbols.h"
9+
10+
using namespace Pinetime::Applications::Screens;
11+
12+
namespace {
13+
struct Option {
14+
Pinetime::Controllers::Settings::VibrationStrength vibrationStrength;
15+
const char* name;
16+
};
17+
18+
constexpr std::array<Option, 3> options = {{
19+
{Pinetime::Controllers::Settings::VibrationStrength::Weak, "Weak"},
20+
{Pinetime::Controllers::Settings::VibrationStrength::Normal, "Normal"},
21+
{Pinetime::Controllers::Settings::VibrationStrength::Strong, "Strong"},
22+
}};
23+
24+
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
25+
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
26+
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
27+
if (i >= options.size()) {
28+
optionArray[i].name = "";
29+
optionArray[i].enabled = false;
30+
} else {
31+
optionArray[i].name = options[i].name;
32+
optionArray[i].enabled = true;
33+
}
34+
}
35+
return optionArray;
36+
}
37+
38+
uint32_t GetDefaultOption(Pinetime::Controllers::Settings::VibrationStrength currentOption) {
39+
for (size_t i = 0; i < options.size(); i++) {
40+
if (options[i].vibrationStrength == currentOption) {
41+
return i;
42+
}
43+
}
44+
return 0;
45+
}
46+
}
47+
48+
SettingNotifVibration::SettingNotifVibration(
49+
Pinetime::Controllers::Settings& settingsController,
50+
Pinetime::Controllers::MotorController& motorController
51+
)
52+
: checkboxList(
53+
0,
54+
1,
55+
"Notif. strength",
56+
Symbols::tachometer,
57+
GetDefaultOption(settingsController.GetNotifVibration()),
58+
[&settings = settingsController, &motor = motorController](uint32_t index) {
59+
motor.RunForDuration(static_cast<uint8_t>(options[index].vibrationStrength));
60+
61+
settings.SetNotifVibration(options[index].vibrationStrength);
62+
settings.SaveSettings();
63+
},
64+
CreateOptionArray()) {
65+
}
66+
67+
SettingNotifVibration::~SettingNotifVibration() {
68+
lv_obj_clean(lv_scr_act());
69+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <lvgl/lvgl.h>
6+
7+
#include "components/settings/Settings.h"
8+
#include "components/motor/MotorController.h"
9+
#include "displayapp/screens/Screen.h"
10+
#include "displayapp/screens/CheckboxList.h"
11+
12+
namespace Pinetime {
13+
14+
namespace Applications {
15+
namespace Screens {
16+
17+
class SettingNotifVibration : public Screen {
18+
public:
19+
explicit SettingNotifVibration(
20+
Pinetime::Controllers::Settings& settingsController,
21+
Pinetime::Controllers::MotorController& motorController
22+
);
23+
~SettingNotifVibration() override;
24+
25+
private:
26+
CheckboxList checkboxList;
27+
};
28+
}
29+
}
30+
}

src/displayapp/screens/settings/Settings.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ namespace Pinetime {
4343
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
4444

4545
{Symbols::clock, "Chimes", Apps::SettingChimes},
46+
{Symbols::none, "Chime strength", Apps::SettingChimeVibration},
47+
{Symbols::none, "Notif. str.", Apps::SettingNotifVibration},
4648
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
49+
4750
{Symbols::check, "Firmware", Apps::FirmwareValidation},
4851
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
49-
5052
{Symbols::list, "About", Apps::SysInfo},
5153

5254
// {Symbols::none, "None", Apps::None},

0 commit comments

Comments
 (0)