Skip to content

Commit df8d396

Browse files
committed
Merge branch 'Riksu9000-call-improvements' into develop
2 parents dec4bab + 0eeed5a commit df8d396

8 files changed

Lines changed: 87 additions & 70 deletions

File tree

src/components/motor/MotorController.cpp

Lines changed: 29 additions & 8 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

@@ -13,19 +14,39 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
1314
void MotorController::Init() {
1415
nrf_gpio_cfg_output(pinMotor);
1516
nrf_gpio_pin_set(pinMotor);
16-
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
17+
app_timer_init();
18+
19+
app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
20+
app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
1721
}
1822

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

21-
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
28+
void MotorController::RunForDuration(uint8_t motorDuration) {
29+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
2230
return;
31+
}
2332

2433
nrf_gpio_pin_clear(pinMotor);
25-
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
26-
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
34+
app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
35+
}
36+
37+
void MotorController::StartRinging() {
38+
if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
39+
return;
40+
}
41+
Ring(this);
42+
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
2743
}
2844

29-
void MotorController::vibrate(void* p_context) {
45+
void MotorController::StopRinging() {
46+
app_timer_stop(longVibTimer);
3047
nrf_gpio_pin_set(pinMotor);
31-
}
48+
}
49+
50+
void MotorController::StopMotor(void* p_context) {
51+
nrf_gpio_pin_set(pinMotor);
52+
}

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 StartRinging();
17+
static void StopRinging();
1618

1719
private:
20+
static void Ring(void* p_context);
1821
Controllers::Settings& settingsController;
19-
static void vibrate(void* p_context);
22+
static void StopMotor(void* p_context);
2023
};
2124
}
2225
}

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(), Screens::Notifications::Modes::Normal);
339+
this, notificationManager, systemTask->nimble().alertService(), motorController, 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(), Screens::Notifications::Modes::Preview);
344+
this, notificationManager, systemTask->nimble().alertService(), motorController, 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
@@ -83,9 +83,9 @@ bool Metronome::Refresh() {
8383
counter--;
8484
if (counter == 0) {
8585
counter = bpb;
86-
motorController.SetDuration(90);
86+
motorController.RunForDuration(90);
8787
} else {
88-
motorController.SetDuration(30);
88+
motorController.RunForDuration(30);
8989
}
9090
}
9191
}

src/displayapp/screens/Notifications.cpp

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern lv_font_t jetbrains_mono_bold_20;
1111
Notifications::Notifications(DisplayApp* app,
1212
Pinetime::Controllers::NotificationManager& notificationManager,
1313
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
14+
Pinetime::Controllers::MotorController& motorController,
1415
Modes mode)
1516
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
1617
notificationManager.ClearNewNotificationFlag();
@@ -36,25 +37,31 @@ Notifications::Notifications(DisplayApp* app,
3637
}
3738

3839
if (mode == Modes::Preview) {
39-
40-
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
41-
42-
lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
43-
lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
44-
lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
45-
46-
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
47-
timeoutTickCountStart = xTaskGetTickCount();
48-
timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
40+
if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
41+
motorController.StartRinging();
42+
} else {
43+
motorController.RunForDuration(35);
44+
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
45+
46+
lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
47+
lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
48+
lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
49+
50+
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
51+
timeoutTickCountStart = xTaskGetTickCount();
52+
timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
53+
}
4954
}
5055
}
5156

5257
Notifications::~Notifications() {
58+
// make sure we stop any vibrations before exiting
59+
Controllers::MotorController::StopRinging();
5360
lv_obj_clean(lv_scr_act());
5461
}
5562

5663
bool Notifications::Refresh() {
57-
if (mode == Modes::Preview) {
64+
if (mode == Modes::Preview && timeoutLine != nullptr) {
5865
auto tick = xTaskGetTickCount();
5966
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
6067
if (pos < 0)
@@ -63,13 +70,13 @@ bool Notifications::Refresh() {
6370
timeoutLinePoints[1].x = pos;
6471
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
6572
}
66-
67-
return running;
73+
return running && currentItem->IsRunning();
6874
}
6975

7076
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
71-
if (mode != Modes::Normal)
72-
return true;
77+
if (mode != Modes::Normal) {
78+
return false;
79+
}
7380

7481
switch (event) {
7582
case Pinetime::Applications::TouchEvents::SwipeDown: {
@@ -130,19 +137,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
130137
}
131138

132139
namespace {
133-
static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
134-
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
135-
item->OnAcceptIncomingCall(event);
136-
}
137-
138-
static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
140+
void CallEventHandler(lv_obj_t* obj, lv_event_t event) {
139141
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
140-
item->OnMuteIncomingCall(event);
141-
}
142-
143-
static void RejectIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
144-
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
145-
item->OnRejectIncomingCall(event);
142+
item->OnCallButtonEvent(obj, event);
146143
}
147144
}
148145

@@ -154,7 +151,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
154151
Modes mode,
155152
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
156153
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
157-
158154
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
159155

160156
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
@@ -212,7 +208,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
212208

213209
bt_accept = lv_btn_create(lv_scr_act(), nullptr);
214210
bt_accept->user_data = this;
215-
lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
211+
lv_obj_set_event_cb(bt_accept, CallEventHandler);
216212
lv_obj_set_size(bt_accept, 76, 76);
217213
lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
218214
label_accept = lv_label_create(bt_accept, nullptr);
@@ -221,7 +217,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
221217

222218
bt_reject = lv_btn_create(lv_scr_act(), nullptr);
223219
bt_reject->user_data = this;
224-
lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
220+
lv_obj_set_event_cb(bt_reject, CallEventHandler);
225221
lv_obj_set_size(bt_reject, 76, 76);
226222
lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
227223
label_reject = lv_label_create(bt_reject, nullptr);
@@ -230,7 +226,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
230226

231227
bt_mute = lv_btn_create(lv_scr_act(), nullptr);
232228
bt_mute->user_data = this;
233-
lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
229+
lv_obj_set_event_cb(bt_mute, CallEventHandler);
234230
lv_obj_set_size(bt_mute, 76, 76);
235231
lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
236232
label_mute = lv_label_create(bt_mute, nullptr);
@@ -246,25 +242,22 @@ Notifications::NotificationItem::NotificationItem(const char* title,
246242
lv_label_set_text(backgroundLabel, "");
247243
}
248244

249-
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
250-
if (event != LV_EVENT_CLICKED)
251-
return;
252-
253-
alertNotificationService.AcceptIncomingCall();
254-
}
255-
256-
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
257-
if (event != LV_EVENT_CLICKED)
245+
void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
246+
if (event != LV_EVENT_CLICKED) {
258247
return;
248+
}
259249

260-
alertNotificationService.MuteIncomingCall();
261-
}
250+
Controllers::MotorController::StopRinging();
262251

263-
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
264-
if (event != LV_EVENT_CLICKED)
265-
return;
252+
if (obj == bt_accept) {
253+
alertNotificationService.AcceptIncomingCall();
254+
} else if (obj == bt_reject) {
255+
alertNotificationService.RejectIncomingCall();
256+
} else if (obj == bt_mute) {
257+
alertNotificationService.MuteIncomingCall();
258+
}
266259

267-
alertNotificationService.RejectIncomingCall();
260+
running = false;
268261
}
269262

270263
Notifications::NotificationItem::~NotificationItem() {

src/displayapp/screens/Notifications.h

Lines changed: 7 additions & 6 deletions
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+
Pinetime::Controllers::MotorController& motorController,
2224
Modes mode);
2325
~Notifications() override;
2426

@@ -35,12 +37,10 @@ namespace Pinetime {
3537
Modes mode,
3638
Pinetime::Controllers::AlertNotificationService& alertNotificationService);
3739
~NotificationItem();
38-
bool Refresh() {
39-
return false;
40+
bool IsRunning() const {
41+
return running;
4042
}
41-
void OnAcceptIncomingCall(lv_event_t event);
42-
void OnMuteIncomingCall(lv_event_t event);
43-
void OnRejectIncomingCall(lv_event_t event);
43+
void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
4444

4545
private:
4646
uint8_t notifNr = 0;
@@ -60,6 +60,7 @@ namespace Pinetime {
6060
lv_obj_t* bottomPlaceholder;
6161
Modes mode;
6262
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
63+
bool running = true;
6364
};
6465

6566
private:
@@ -75,7 +76,7 @@ namespace Pinetime {
7576
bool validDisplay = false;
7677

7778
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
78-
lv_obj_t* timeoutLine;
79+
lv_obj_t* timeoutLine = nullptr;
7980
uint32_t timeoutTickCountStart;
8081
uint32_t timeoutTickCountEnd;
8182
};

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: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,13 @@ void SystemTask::Work() {
266266
if (isSleeping && !isWakingUp) {
267267
GoToRunning();
268268
}
269-
motorController.SetDuration(35);
270269
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
271270
break;
272271
case Messages::OnTimerDone:
273272
if (isSleeping && !isWakingUp) {
274273
GoToRunning();
275274
}
276-
motorController.SetDuration(35);
275+
motorController.RunForDuration(35);
277276
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
278277
break;
279278
case Messages::BleConnected:
@@ -326,7 +325,7 @@ void SystemTask::Work() {
326325
stepCounterMustBeReset = true;
327326
break;
328327
case Messages::OnChargingEvent:
329-
motorController.SetDuration(15);
328+
motorController.RunForDuration(15);
330329
// Battery level is updated on every message - there's no need to do anything
331330
break;
332331

0 commit comments

Comments
 (0)