Skip to content

Commit d13dd6d

Browse files
committed
implemented continuous vibration pattern for incoming calls
1 parent d7fa000 commit d13dd6d

7 files changed

Lines changed: 78 additions & 24 deletions

File tree

src/components/motor/MotorController.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "systemtask/SystemTask.h"
44
#include "app_timer.h"
55

6-
APP_TIMER_DEF(vibTimer);
6+
APP_TIMER_DEF(shortVibTimer);
7+
APP_TIMER_DEF(longVibTimer);
78

89
using namespace Pinetime::Controllers;
910

@@ -14,19 +15,42 @@ void MotorController::Init() {
1415
nrf_gpio_cfg_output(pinMotor);
1516
nrf_gpio_pin_set(pinMotor);
1617
app_timer_init();
17-
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
18+
19+
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
20+
app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, vibrate);
21+
isBusy = false;
1822
}
1923

20-
void MotorController::SetDuration(uint8_t motorDuration) {
24+
void MotorController::RunForDuration(uint8_t motorDuration) {
2125

22-
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
26+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy)
2327
return;
2428

2529
nrf_gpio_pin_clear(pinMotor);
2630
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
27-
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
31+
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
2832
}
2933

30-
void MotorController::vibrate(void* p_context) {
34+
void MotorController::startRunning(uint8_t motorDuration) {
35+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy )
36+
return;
37+
//prevent other vibrations while running
38+
isBusy = true;
39+
nrf_gpio_pin_clear(pinMotor);
40+
app_timer_start(longVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
41+
}
42+
43+
void MotorController::stopRunning() {
44+
45+
app_timer_stop(longVibTimer);
3146
nrf_gpio_pin_set(pinMotor);
47+
isBusy = false;
48+
}
49+
50+
void MotorController::vibrate(void* p_context) {
51+
if (nrf_gpio_pin_out_read(pinMotor) == 0) {
52+
nrf_gpio_pin_set(pinMotor);
53+
} else {
54+
nrf_gpio_pin_clear(pinMotor);
55+
}
3256
}

src/components/motor/MotorController.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ namespace Pinetime {
1212
public:
1313
MotorController(Controllers::Settings& settingsController);
1414
void Init();
15-
void SetDuration(uint8_t motorDuration);
15+
void RunForDuration(uint8_t motorDuration);
16+
void startRunning(uint8_t motorDuration);
17+
void stopRunning();
1618

1719
private:
1820
Controllers::Settings& settingsController;
1921
static void vibrate(void* p_context);
20-
};
22+
bool isBusy;
23+
};
2124
}
2225
}

src/displayapp/DisplayApp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
256256

257257
case Apps::Notifications:
258258
currentScreen = std::make_unique<Screens::Notifications>(
259-
this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal);
259+
this, notificationManager, systemTask.nimble().alertService(), motorController, Screens::Notifications::Modes::Normal);
260260
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
261261
break;
262262
case Apps::NotificationsPreview:
263263
currentScreen = std::make_unique<Screens::Notifications>(
264-
this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview);
264+
this, notificationManager, systemTask.nimble().alertService(), motorController, Screens::Notifications::Modes::Preview);
265265
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
266266
break;
267267

src/displayapp/screens/Notifications.cpp

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,13 @@ extern lv_font_t jetbrains_mono_bold_20;
1111
Notifications::Notifications(DisplayApp* app,
1212
Pinetime::Controllers::NotificationManager& notificationManager,
1313
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
14+
Controllers::MotorController& motorController,
1415
Modes mode)
15-
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
16+
: Screen(app),
17+
notificationManager {notificationManager},
18+
alertNotificationService {alertNotificationService},
19+
motorController{motorController},
20+
mode {mode} {
1621
notificationManager.ClearNewNotificationFlag();
1722
auto notification = notificationManager.GetLastNotification();
1823
if (notification.valid) {
@@ -23,7 +28,8 @@ Notifications::Notifications(DisplayApp* app,
2328
notification.category,
2429
notificationManager.NbNotifications(),
2530
mode,
26-
alertNotificationService);
31+
alertNotificationService,
32+
motorController);
2733
validDisplay = true;
2834
} else {
2935
currentItem = std::make_unique<NotificationItem>("Notification",
@@ -32,10 +38,13 @@ Notifications::Notifications(DisplayApp* app,
3238
notification.category,
3339
notificationManager.NbNotifications(),
3440
Modes::Preview,
35-
alertNotificationService);
41+
alertNotificationService,
42+
motorController);
3643
}
3744

3845
if (mode == Modes::Preview) {
46+
47+
3948

4049
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
4150

@@ -63,7 +72,10 @@ bool Notifications::Refresh() {
6372
timeoutLinePoints[1].x = pos;
6473
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
6574
}
66-
75+
//make sure we stop any vibrations before exiting
76+
if (!running) {
77+
motorController.stopRunning();
78+
}
6779
return running;
6880
}
6981

@@ -92,7 +104,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
92104
previousNotification.category,
93105
notificationManager.NbNotifications(),
94106
mode,
95-
alertNotificationService);
107+
alertNotificationService,
108+
motorController);
96109
}
97110
return true;
98111
case Pinetime::Applications::TouchEvents::SwipeUp: {
@@ -117,7 +130,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
117130
nextNotification.category,
118131
notificationManager.NbNotifications(),
119132
mode,
120-
alertNotificationService);
133+
alertNotificationService,
134+
motorController);
121135
}
122136
return true;
123137
case Pinetime::Applications::TouchEvents::LongTap: {
@@ -152,8 +166,9 @@ Notifications::NotificationItem::NotificationItem(const char* title,
152166
Controllers::NotificationManager::Categories category,
153167
uint8_t notifNb,
154168
Modes mode,
155-
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
156-
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
169+
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
170+
Controllers::MotorController& motorController)
171+
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService}, motorController{motorController} {
157172

158173
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
159174

@@ -236,8 +251,10 @@ Notifications::NotificationItem::NotificationItem(const char* title,
236251
label_mute = lv_label_create(bt_mute, nullptr);
237252
lv_label_set_text(label_mute, Symbols::volumMute);
238253
lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
254+
239255
} break;
240256
}
257+
241258

242259
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
243260
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
@@ -249,21 +266,21 @@ Notifications::NotificationItem::NotificationItem(const char* title,
249266
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
250267
if (event != LV_EVENT_CLICKED)
251268
return;
252-
269+
motorController.stopRunning();
253270
alertNotificationService.AcceptIncomingCall();
254271
}
255272

256273
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
257274
if (event != LV_EVENT_CLICKED)
258275
return;
259-
276+
motorController.stopRunning();
260277
alertNotificationService.MuteIncomingCall();
261278
}
262279

263280
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
264281
if (event != LV_EVENT_CLICKED)
265282
return;
266-
283+
motorController.stopRunning();
267284
alertNotificationService.RejectIncomingCall();
268285
}
269286

src/displayapp/screens/Notifications.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <memory>
66
#include "Screen.h"
77
#include "components/ble/NotificationManager.h"
8+
#include "components/motor/MotorController.h"
89

910
namespace Pinetime {
1011
namespace Controllers {
@@ -19,6 +20,7 @@ namespace Pinetime {
1920
explicit Notifications(DisplayApp* app,
2021
Pinetime::Controllers::NotificationManager& notificationManager,
2122
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
23+
Controllers::MotorController& motorController,
2224
Modes mode);
2325
~Notifications() override;
2426

@@ -33,7 +35,8 @@ namespace Pinetime {
3335
Controllers::NotificationManager::Categories,
3436
uint8_t notifNb,
3537
Modes mode,
36-
Pinetime::Controllers::AlertNotificationService& alertNotificationService);
38+
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
39+
Controllers::MotorController& motorController);
3740
~NotificationItem();
3841
bool Refresh() {
3942
return false;
@@ -60,6 +63,7 @@ namespace Pinetime {
6063
lv_obj_t* bottomPlaceholder;
6164
Modes mode;
6265
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
66+
Controllers::MotorController& motorController;
6367
};
6468

6569
private:
@@ -72,6 +76,8 @@ namespace Pinetime {
7276
Modes mode = Modes::Normal;
7377
std::unique_ptr<NotificationItem> currentItem;
7478
Controllers::NotificationManager::Notification::Id currentId;
79+
Controllers::MotorController& motorController;
80+
7581
bool validDisplay = false;
7682

7783
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};

src/displayapp/screens/settings/QuickSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
140140

141141
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
142142
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::ON);
143-
motorController.SetDuration(35);
143+
motorController.RunForDuration(35);
144144
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
145145
} else {
146146
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);

src/systemtask/SystemTask.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ void SystemTask::Work() {
225225
case Messages::OnNewNotification:
226226
if (isSleeping && !isWakingUp)
227227
GoToRunning();
228-
motorController.SetDuration(35);
228+
if (notificationManager.GetLastNotification().category == Controllers::NotificationManager::Categories::IncomingCall) {
229+
motorController.startRunning(50);
230+
} else {
231+
motorController.RunForDuration(35);
232+
}
229233
displayApp->PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
230234
break;
231235
case Messages::BleConnected:

0 commit comments

Comments
 (0)