Skip to content

Commit e6dcb30

Browse files
committed
Improvements
1 parent 5bdef36 commit e6dcb30

8 files changed

Lines changed: 70 additions & 131 deletions

File tree

src/components/motor/MotorController.cpp

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,37 @@ void MotorController::Init() {
1616
nrf_gpio_pin_set(pinMotor);
1717
app_timer_init();
1818

19-
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
20-
app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, vibrate);
21-
isBusy = false;
19+
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
20+
app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
2221
}
2322

24-
void MotorController::runForDuration(uint8_t motorDuration) {
23+
void MotorController::Ring(void* p_context) {
24+
auto* motorController = static_cast<MotorController*>(p_context);
25+
motorController->RunForDuration(50);
26+
}
2527

26-
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy)
28+
void MotorController::RunForDuration(uint8_t motorDuration) {
29+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
2730
return;
31+
}
2832

2933
nrf_gpio_pin_clear(pinMotor);
30-
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
31-
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
34+
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
3235
}
3336

34-
void MotorController::startRunning(uint8_t motorDuration) {
35-
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy )
37+
void MotorController::StartRinging() {
38+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
3639
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);
40+
}
41+
Ring(this);
42+
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
4143
}
4244

43-
void MotorController::stopRunning() {
44-
45+
void MotorController::StopRinging() {
4546
app_timer_stop(longVibTimer);
4647
nrf_gpio_pin_set(pinMotor);
47-
isBusy = false;
4848
}
4949

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-
}
50+
void MotorController::StopMotor(void* p_context) {
51+
nrf_gpio_pin_set(pinMotor);
5652
}

src/components/motor/MotorController.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace Pinetime {
1212
public:
1313
MotorController(Controllers::Settings& settingsController);
1414
void Init();
15-
void runForDuration(uint8_t motorDuration);
16-
void startRunning(uint8_t motorDuration);
17-
void stopRunning();
15+
void RunForDuration(uint8_t motorDuration);
16+
void StartRinging();
17+
static void StopRinging();
1818

1919
private:
20+
static void Ring(void* p_context);
2021
Controllers::Settings& settingsController;
21-
static void vibrate(void* p_context);
22-
bool isBusy;
23-
};
22+
static void StopMotor(void* p_context);
23+
};
2424
}
2525
}

src/displayapp/DisplayApp.cpp

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

337337
case Apps::Notifications:
338338
currentScreen = std::make_unique<Screens::Notifications>(
339-
this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Normal);
339+
this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Normal);
340340
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
341341
break;
342342
case Apps::NotificationsPreview:
343343
currentScreen = std::make_unique<Screens::Notifications>(
344-
this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Preview);
344+
this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Preview);
345345
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
346346
break;
347347
case Apps::Timer:

src/displayapp/screens/Metronome.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ bool Metronome::Refresh() {
109109
startTime = xTaskGetTickCount();
110110
if (counter == 0) {
111111
counter = bpb;
112-
motorController.SetDuration(90);
112+
motorController.RunForDuration(90);
113113
} else {
114-
motorController.SetDuration(30);
114+
motorController.RunForDuration(30);
115115
}
116116
}
117117
break;

src/displayapp/screens/Notifications.cpp

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ 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,
1514
Modes mode)
16-
: Screen(app),
17-
notificationManager{notificationManager},
18-
alertNotificationService{alertNotificationService},
19-
motorController{motorController},
20-
mode{mode} {
15+
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
2116
notificationManager.ClearNewNotificationFlag();
2217
auto notification = notificationManager.GetLastNotification();
2318
if (notification.valid) {
@@ -28,10 +23,7 @@ Notifications::Notifications(DisplayApp* app,
2823
notification.category,
2924
notificationManager.NbNotifications(),
3025
mode,
31-
alertNotificationService,
32-
motorController,
33-
&timeoutTickCountEnd,
34-
&timeoutTickCountStart);
26+
alertNotificationService);
3527
validDisplay = true;
3628
} else {
3729
currentItem = std::make_unique<NotificationItem>("Notification",
@@ -40,14 +32,10 @@ Notifications::Notifications(DisplayApp* app,
4032
notification.category,
4133
notificationManager.NbNotifications(),
4234
Modes::Preview,
43-
alertNotificationService,
44-
motorController,
45-
&timeoutTickCountEnd,
46-
&timeoutTickCountStart);
35+
alertNotificationService);
4736
}
4837

49-
if (mode == Modes::Preview) {
50-
38+
if (mode == Modes::Preview && notification.category != Controllers::NotificationManager::Categories::IncomingCall) {
5139
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
5240

5341
lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
@@ -61,11 +49,13 @@ Notifications::Notifications(DisplayApp* app,
6149
}
6250

6351
Notifications::~Notifications() {
52+
// make sure we stop any vibrations before exiting
53+
Controllers::MotorController::StopRinging();
6454
lv_obj_clean(lv_scr_act());
6555
}
6656

6757
bool Notifications::Refresh() {
68-
if (mode == Modes::Preview && !currentItem->timeoutOnHold) {
58+
if (mode == Modes::Preview && timeoutLine != nullptr) {
6959
auto tick = xTaskGetTickCount();
7060
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
7161
if (pos < 0)
@@ -74,10 +64,7 @@ bool Notifications::Refresh() {
7464
timeoutLinePoints[1].x = pos;
7565
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
7666
}
77-
//make sure we stop any vibrations before exiting
78-
if (!running)
79-
motorController.stopRunning();
80-
return running;
67+
return running && currentItem->IsRunning();
8168
}
8269

8370
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
@@ -105,10 +92,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
10592
previousNotification.category,
10693
notificationManager.NbNotifications(),
10794
mode,
108-
alertNotificationService,
109-
motorController,
110-
&timeoutTickCountEnd,
111-
&timeoutTickCountStart);
95+
alertNotificationService);
11296
}
11397
return true;
11498
case Pinetime::Applications::TouchEvents::SwipeUp: {
@@ -133,10 +117,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
133117
nextNotification.category,
134118
notificationManager.NbNotifications(),
135119
mode,
136-
alertNotificationService,
137-
motorController,
138-
&timeoutTickCountEnd,
139-
&timeoutTickCountStart);
120+
alertNotificationService);
140121
}
141122
return true;
142123
case Pinetime::Applications::TouchEvents::LongTap: {
@@ -149,19 +130,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
149130
}
150131

151132
namespace {
152-
static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
153-
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
154-
item->OnAcceptIncomingCall(event);
155-
}
156-
157-
static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
133+
void CallEventHandler(lv_obj_t* obj, lv_event_t event) {
158134
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
159-
item->OnMuteIncomingCall(event);
160-
}
161-
162-
static void RejectIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
163-
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
164-
item->OnRejectIncomingCall(event);
135+
item->OnCallButtonEvent(obj, event);
165136
}
166137
}
167138

@@ -171,12 +142,8 @@ Notifications::NotificationItem::NotificationItem(const char* title,
171142
Controllers::NotificationManager::Categories category,
172143
uint8_t notifNb,
173144
Modes mode,
174-
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
175-
Controllers::MotorController& motorController,
176-
uint32_t* timeoutEnd,
177-
uint32_t* timeoutStart)
178-
: notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService},
179-
motorController{motorController}, timeoutEnd{timeoutEnd}, timeoutStart{timeoutStart} {
145+
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
146+
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
180147
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
181148

182149
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
@@ -234,7 +201,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
234201

235202
bt_accept = lv_btn_create(lv_scr_act(), nullptr);
236203
bt_accept->user_data = this;
237-
lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
204+
lv_obj_set_event_cb(bt_accept, CallEventHandler);
238205
lv_obj_set_size(bt_accept, 76, 76);
239206
lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
240207
label_accept = lv_label_create(bt_accept, nullptr);
@@ -243,7 +210,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
243210

244211
bt_reject = lv_btn_create(lv_scr_act(), nullptr);
245212
bt_reject->user_data = this;
246-
lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
213+
lv_obj_set_event_cb(bt_reject, CallEventHandler);
247214
lv_obj_set_size(bt_reject, 76, 76);
248215
lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
249216
label_reject = lv_label_create(bt_reject, nullptr);
@@ -252,13 +219,12 @@ Notifications::NotificationItem::NotificationItem(const char* title,
252219

253220
bt_mute = lv_btn_create(lv_scr_act(), nullptr);
254221
bt_mute->user_data = this;
255-
lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
222+
lv_obj_set_event_cb(bt_mute, CallEventHandler);
256223
lv_obj_set_size(bt_mute, 76, 76);
257224
lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
258225
label_mute = lv_label_create(bt_mute, nullptr);
259226
lv_label_set_text(label_mute, Symbols::volumMute);
260227
lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
261-
timeoutOnHold = true;
262228
} break;
263229
}
264230

@@ -269,35 +235,24 @@ Notifications::NotificationItem::NotificationItem(const char* title,
269235
lv_label_set_text(backgroundLabel, "");
270236
}
271237

272-
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
273-
if (event != LV_EVENT_CLICKED)
238+
void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
239+
if (event != LV_EVENT_CLICKED) {
274240
return;
275-
callPreviewInteraction();
276-
alertNotificationService.AcceptIncomingCall();
277-
}
241+
}
278242

279-
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
280-
if (event != LV_EVENT_CLICKED)
281-
return;
282-
callPreviewInteraction();
283-
alertNotificationService.MuteIncomingCall();
284-
}
243+
Controllers::MotorController::StopRinging();
285244

286-
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
287-
if (event != LV_EVENT_CLICKED)
288-
return;
289-
callPreviewInteraction();
290-
alertNotificationService.RejectIncomingCall();
291-
}
245+
if (obj == bt_accept) {
246+
alertNotificationService.AcceptIncomingCall();
247+
} else if (obj == bt_reject) {
248+
alertNotificationService.RejectIncomingCall();
249+
} else if (obj == bt_mute) {
250+
alertNotificationService.MuteIncomingCall();
251+
}
292252

293-
inline void Notifications::NotificationItem::callPreviewInteraction() {
294-
*timeoutStart = xTaskGetTickCount();
295-
*timeoutEnd = *timeoutStart + (5 * 1024);
296-
timeoutOnHold = false;
297-
motorController.stopRunning();
253+
running = false;
298254
}
299255

300-
301256
Notifications::NotificationItem::~NotificationItem() {
302257
lv_obj_clean(lv_scr_act());
303258
}

src/displayapp/screens/Notifications.h

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

109
namespace Pinetime {
1110
namespace Controllers {
@@ -20,7 +19,6 @@ namespace Pinetime {
2019
explicit Notifications(DisplayApp* app,
2120
Pinetime::Controllers::NotificationManager& notificationManager,
2221
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
23-
Controllers::MotorController& motorController,
2422
Modes mode);
2523
~Notifications() override;
2624

@@ -35,22 +33,14 @@ namespace Pinetime {
3533
Controllers::NotificationManager::Categories,
3634
uint8_t notifNb,
3735
Modes mode,
38-
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
39-
Controllers::MotorController& motorController,
40-
uint32_t* timeoutEnd,
41-
uint32_t* timeoutStart);
36+
Pinetime::Controllers::AlertNotificationService& alertNotificationService);
4237
~NotificationItem();
43-
bool Refresh() {
44-
return false;
38+
bool IsRunning() const {
39+
return running;
4540
}
46-
void OnAcceptIncomingCall(lv_event_t event);
47-
void OnMuteIncomingCall(lv_event_t event);
48-
void OnRejectIncomingCall(lv_event_t event);
49-
50-
bool timeoutOnHold = false;
41+
void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
42+
5143
private:
52-
void callPreviewInteraction();
53-
5444
uint8_t notifNr = 0;
5545
uint8_t notifNb = 0;
5646
char pageText[4];
@@ -66,11 +56,9 @@ namespace Pinetime {
6656
lv_obj_t* label_mute;
6757
lv_obj_t* label_reject;
6858
lv_obj_t* bottomPlaceholder;
69-
uint32_t* timeoutEnd;
70-
uint32_t* timeoutStart;
7159
Modes mode;
7260
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
73-
Controllers::MotorController& motorController;
61+
bool running = true;
7462
};
7563

7664
private:
@@ -83,11 +71,10 @@ namespace Pinetime {
8371
Modes mode = Modes::Normal;
8472
std::unique_ptr<NotificationItem> currentItem;
8573
Controllers::NotificationManager::Notification::Id currentId;
86-
Controllers::MotorController& motorController;
8774
bool validDisplay = false;
8875

8976
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
90-
lv_obj_t* timeoutLine;
77+
lv_obj_t* timeoutLine = nullptr;
9178
uint32_t timeoutTickCountStart;
9279
uint32_t timeoutTickCountEnd;
9380
};

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.runForDuration(35);
143+
motorController.RunForDuration(35);
144144
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
145145
} else {
146146
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);

0 commit comments

Comments
 (0)