summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-08-14 21:54:00 +0200
committerJean-François Milants <jf@codingfield.com>2021-08-14 21:54:00 +0200
commit0eeed5ac33a655367a3da9fb93ddc515970cd16a (patch)
tree913f71a229336809e2472321a1e21b4c438b295d
parentdec4bab33496527e43850742a4b3dafd753eab83 (diff)
parentf9319dfb91a38c773b4af221f2fd0d975cf061f2 (diff)
Merge branch 'call-improvements' of https://github.com/Riksu9000/InfiniTime into Riksu9000-call-improvements
# Conflicts: # src/displayapp/screens/Metronome.cpp
-rw-r--r--src/components/motor/MotorController.cpp37
-rw-r--r--src/components/motor/MotorController.h7
-rw-r--r--src/displayapp/DisplayApp.cpp4
-rw-r--r--src/displayapp/screens/Metronome.cpp4
-rw-r--r--src/displayapp/screens/Notifications.cpp85
-rw-r--r--src/displayapp/screens/Notifications.h13
-rw-r--r--src/displayapp/screens/settings/QuickSettings.cpp2
-rw-r--r--src/systemtask/SystemTask.cpp5
8 files changed, 87 insertions, 70 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 3afa0ced..b25e6bc8 100644
--- a/src/components/motor/MotorController.cpp
+++ b/src/components/motor/MotorController.cpp
@@ -3,7 +3,8 @@
#include "systemtask/SystemTask.h"
#include "app_timer.h"
-APP_TIMER_DEF(vibTimer);
+APP_TIMER_DEF(shortVibTimer);
+APP_TIMER_DEF(longVibTimer);
using namespace Pinetime::Controllers;
@@ -13,19 +14,39 @@ MotorController::MotorController(Controllers::Settings& settingsController) : se
void MotorController::Init() {
nrf_gpio_cfg_output(pinMotor);
nrf_gpio_pin_set(pinMotor);
- app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
+ app_timer_init();
+
+ app_timer_create(&shortVibTimer, APP_TIMER_MODE_SINGLE_SHOT, StopMotor);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, Ring);
}
-void MotorController::SetDuration(uint8_t motorDuration) {
+void MotorController::Ring(void* p_context) {
+ auto* motorController = static_cast<MotorController*>(p_context);
+ motorController->RunForDuration(50);
+}
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
+void MotorController::RunForDuration(uint8_t motorDuration) {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
return;
+ }
nrf_gpio_pin_clear(pinMotor);
- /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
- app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+ app_timer_start(shortVibTimer, APP_TIMER_TICKS(motorDuration), nullptr);
+}
+
+void MotorController::StartRinging() {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF) {
+ return;
+ }
+ Ring(this);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
-void MotorController::vibrate(void* p_context) {
+void MotorController::StopRinging() {
+ app_timer_stop(longVibTimer);
nrf_gpio_pin_set(pinMotor);
-} \ No newline at end of file
+}
+
+void MotorController::StopMotor(void* p_context) {
+ nrf_gpio_pin_set(pinMotor);
+}
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index df61af78..d2c9fe5f 100644
--- a/src/components/motor/MotorController.h
+++ b/src/components/motor/MotorController.h
@@ -12,11 +12,14 @@ namespace Pinetime {
public:
MotorController(Controllers::Settings& settingsController);
void Init();
- void SetDuration(uint8_t motorDuration);
+ void RunForDuration(uint8_t motorDuration);
+ void StartRinging();
+ static void StopRinging();
private:
+ static void Ring(void* p_context);
Controllers::Settings& settingsController;
- static void vibrate(void* p_context);
+ static void StopMotor(void* p_context);
};
}
}
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 49a56a07..5150162a 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -336,12 +336,12 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Notifications:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Normal);
+ this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Normal);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::NotificationsPreview:
currentScreen = std::make_unique<Screens::Notifications>(
- this, notificationManager, systemTask->nimble().alertService(), Screens::Notifications::Modes::Preview);
+ this, notificationManager, systemTask->nimble().alertService(), motorController, Screens::Notifications::Modes::Preview);
ReturnApp(Apps::Clock, FullRefreshDirections::Up, TouchEvents::SwipeUp);
break;
case Apps::Timer:
diff --git a/src/displayapp/screens/Metronome.cpp b/src/displayapp/screens/Metronome.cpp
index ce23cc3e..66f8f621 100644
--- a/src/displayapp/screens/Metronome.cpp
+++ b/src/displayapp/screens/Metronome.cpp
@@ -83,9 +83,9 @@ bool Metronome::Refresh() {
counter--;
if (counter == 0) {
counter = bpb;
- motorController.SetDuration(90);
+ motorController.RunForDuration(90);
} else {
- motorController.SetDuration(30);
+ motorController.RunForDuration(30);
}
}
}
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index 5c23ed1f..c061c146 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -11,6 +11,7 @@ extern lv_font_t jetbrains_mono_bold_20;
Notifications::Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Pinetime::Controllers::MotorController& motorController,
Modes mode)
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
notificationManager.ClearNewNotificationFlag();
@@ -36,25 +37,31 @@ Notifications::Notifications(DisplayApp* app,
}
if (mode == Modes::Preview) {
-
- timeoutLine = lv_line_create(lv_scr_act(), nullptr);
-
- lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
- lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
- lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
-
- lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
- timeoutTickCountStart = xTaskGetTickCount();
- timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
+ if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) {
+ motorController.StartRinging();
+ } else {
+ motorController.RunForDuration(35);
+ timeoutLine = lv_line_create(lv_scr_act(), nullptr);
+
+ lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
+ lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
+ lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
+
+ lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
+ timeoutTickCountStart = xTaskGetTickCount();
+ timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
+ }
}
}
Notifications::~Notifications() {
+ // make sure we stop any vibrations before exiting
+ Controllers::MotorController::StopRinging();
lv_obj_clean(lv_scr_act());
}
bool Notifications::Refresh() {
- if (mode == Modes::Preview) {
+ if (mode == Modes::Preview && timeoutLine != nullptr) {
auto tick = xTaskGetTickCount();
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
if (pos < 0)
@@ -63,13 +70,13 @@ bool Notifications::Refresh() {
timeoutLinePoints[1].x = pos;
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
}
-
- return running;
+ return running && currentItem->IsRunning();
}
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
- if (mode != Modes::Normal)
- return true;
+ if (mode != Modes::Normal) {
+ return false;
+ }
switch (event) {
case Pinetime::Applications::TouchEvents::SwipeDown: {
@@ -130,19 +137,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
namespace {
- static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
- auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnAcceptIncomingCall(event);
- }
-
- static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
+ void CallEventHandler(lv_obj_t* obj, lv_event_t event) {
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnMuteIncomingCall(event);
- }
-
- static void RejectIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
- auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
- item->OnRejectIncomingCall(event);
+ item->OnCallButtonEvent(obj, event);
}
}
@@ -154,7 +151,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
: notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
-
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
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,
bt_accept = lv_btn_create(lv_scr_act(), nullptr);
bt_accept->user_data = this;
- lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_accept, CallEventHandler);
lv_obj_set_size(bt_accept, 76, 76);
lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
label_accept = lv_label_create(bt_accept, nullptr);
@@ -221,7 +217,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
bt_reject = lv_btn_create(lv_scr_act(), nullptr);
bt_reject->user_data = this;
- lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_reject, CallEventHandler);
lv_obj_set_size(bt_reject, 76, 76);
lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
label_reject = lv_label_create(bt_reject, nullptr);
@@ -230,7 +226,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
bt_mute = lv_btn_create(lv_scr_act(), nullptr);
bt_mute->user_data = this;
- lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
+ lv_obj_set_event_cb(bt_mute, CallEventHandler);
lv_obj_set_size(bt_mute, 76, 76);
lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
label_mute = lv_label_create(bt_mute, nullptr);
@@ -246,25 +242,22 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_label_set_text(backgroundLabel, "");
}
-void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
- return;
-
- alertNotificationService.AcceptIncomingCall();
-}
-
-void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
+void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
+ if (event != LV_EVENT_CLICKED) {
return;
+ }
- alertNotificationService.MuteIncomingCall();
-}
+ Controllers::MotorController::StopRinging();
-void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
- if (event != LV_EVENT_CLICKED)
- return;
+ if (obj == bt_accept) {
+ alertNotificationService.AcceptIncomingCall();
+ } else if (obj == bt_reject) {
+ alertNotificationService.RejectIncomingCall();
+ } else if (obj == bt_mute) {
+ alertNotificationService.MuteIncomingCall();
+ }
- alertNotificationService.RejectIncomingCall();
+ running = false;
}
Notifications::NotificationItem::~NotificationItem() {
diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h
index 51ca81da..a02d9b46 100644
--- a/src/displayapp/screens/Notifications.h
+++ b/src/displayapp/screens/Notifications.h
@@ -5,6 +5,7 @@
#include <memory>
#include "Screen.h"
#include "components/ble/NotificationManager.h"
+#include "components/motor/MotorController.h"
namespace Pinetime {
namespace Controllers {
@@ -19,6 +20,7 @@ namespace Pinetime {
explicit Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Pinetime::Controllers::MotorController& motorController,
Modes mode);
~Notifications() override;
@@ -35,12 +37,10 @@ namespace Pinetime {
Modes mode,
Pinetime::Controllers::AlertNotificationService& alertNotificationService);
~NotificationItem();
- bool Refresh() {
- return false;
+ bool IsRunning() const {
+ return running;
}
- void OnAcceptIncomingCall(lv_event_t event);
- void OnMuteIncomingCall(lv_event_t event);
- void OnRejectIncomingCall(lv_event_t event);
+ void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
private:
uint8_t notifNr = 0;
@@ -60,6 +60,7 @@ namespace Pinetime {
lv_obj_t* bottomPlaceholder;
Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
+ bool running = true;
};
private:
@@ -75,7 +76,7 @@ namespace Pinetime {
bool validDisplay = false;
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
- lv_obj_t* timeoutLine;
+ lv_obj_t* timeoutLine = nullptr;
uint32_t timeoutTickCountStart;
uint32_t timeoutTickCountEnd;
};
diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp
index 2cd24876..0421d103 100644
--- a/src/displayapp/screens/settings/QuickSettings.cpp
+++ b/src/displayapp/screens/settings/QuickSettings.cpp
@@ -140,7 +140,7 @@ void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) {
if (lv_obj_get_state(btn3, LV_BTN_PART_MAIN) & LV_STATE_CHECKED) {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::ON);
- motorController.SetDuration(35);
+ motorController.RunForDuration(35);
lv_label_set_text_static(btn3_lvl, Symbols::notificationsOn);
} else {
settingsController.SetVibrationStatus(Controllers::Settings::Vibration::OFF);
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 8915ce74..3553f449 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -266,14 +266,13 @@ void SystemTask::Work() {
if (isSleeping && !isWakingUp) {
GoToRunning();
}
- motorController.SetDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::NewNotification);
break;
case Messages::OnTimerDone:
if (isSleeping && !isWakingUp) {
GoToRunning();
}
- motorController.SetDuration(35);
+ motorController.RunForDuration(35);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break;
case Messages::BleConnected:
@@ -326,7 +325,7 @@ void SystemTask::Work() {
stepCounterMustBeReset = true;
break;
case Messages::OnChargingEvent:
- motorController.SetDuration(15);
+ motorController.RunForDuration(15);
// Battery level is updated on every message - there's no need to do anything
break;