summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/motor/MotorController.cpp39
-rw-r--r--src/components/motor/MotorController.h7
-rw-r--r--src/displayapp/DisplayApp.cpp4
-rw-r--r--src/displayapp/screens/Notifications.cpp57
-rw-r--r--src/displayapp/screens/Notifications.h16
-rw-r--r--src/displayapp/screens/settings/QuickSettings.cpp2
-rw-r--r--src/systemtask/SystemTask.cpp9
7 files changed, 104 insertions, 30 deletions
diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp
index 3afa0ced..80883025 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,43 @@ 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, vibrate);
+ app_timer_create(&longVibTimer, APP_TIMER_MODE_REPEATED, vibrate);
+ isBusy = false;
}
-void MotorController::SetDuration(uint8_t motorDuration) {
+void MotorController::runForDuration(uint8_t motorDuration) {
- if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF)
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy)
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), NULL);
}
-void MotorController::vibrate(void* p_context) {
+void MotorController::startRunning(uint8_t motorDuration) {
+ if (settingsController.GetVibrationStatus() == Controllers::Settings::Vibration::OFF || isBusy )
+ return;
+ //prevent other vibrations while running
+ isBusy = true;
+ nrf_gpio_pin_clear(pinMotor);
+ app_timer_start(longVibTimer, APP_TIMER_TICKS(motorDuration), NULL);
+}
+
+void MotorController::stopRunning() {
+
+ app_timer_stop(longVibTimer);
nrf_gpio_pin_set(pinMotor);
-} \ No newline at end of file
+ isBusy = false;
+}
+
+void MotorController::vibrate(void* p_context) {
+ if (nrf_gpio_pin_out_read(pinMotor) == 0) {
+ nrf_gpio_pin_set(pinMotor);
+ } else {
+ nrf_gpio_pin_clear(pinMotor);
+ }
+}
diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h
index df61af78..5daeb8ce 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 startRunning(uint8_t motorDuration);
+ void stopRunning();
private:
Controllers::Settings& settingsController;
static void vibrate(void* p_context);
- };
+ bool isBusy;
+ };
}
}
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index d4a73f5e..bdd703ee 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/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index 5c23ed1f..5eecb421 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -11,8 +11,13 @@ extern lv_font_t jetbrains_mono_bold_20;
Notifications::Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Controllers::MotorController& motorController,
Modes mode)
- : Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
+ : Screen(app),
+ notificationManager{notificationManager},
+ alertNotificationService{alertNotificationService},
+ motorController{motorController},
+ mode{mode} {
notificationManager.ClearNewNotificationFlag();
auto notification = notificationManager.GetLastNotification();
if (notification.valid) {
@@ -23,7 +28,10 @@ Notifications::Notifications(DisplayApp* app,
notification.category,
notificationManager.NbNotifications(),
mode,
- alertNotificationService);
+ alertNotificationService,
+ motorController,
+ &timeoutTickCountEnd,
+ &timeoutTickCountStart);
validDisplay = true;
} else {
currentItem = std::make_unique<NotificationItem>("Notification",
@@ -32,7 +40,10 @@ Notifications::Notifications(DisplayApp* app,
notification.category,
notificationManager.NbNotifications(),
Modes::Preview,
- alertNotificationService);
+ alertNotificationService,
+ motorController,
+ &timeoutTickCountEnd,
+ &timeoutTickCountStart);
}
if (mode == Modes::Preview) {
@@ -54,7 +65,7 @@ Notifications::~Notifications() {
}
bool Notifications::Refresh() {
- if (mode == Modes::Preview) {
+ if (mode == Modes::Preview && !currentItem->timeoutOnHold) {
auto tick = xTaskGetTickCount();
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
if (pos < 0)
@@ -63,7 +74,9 @@ bool Notifications::Refresh() {
timeoutLinePoints[1].x = pos;
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
}
-
+ //make sure we stop any vibrations before exiting
+ if (!running)
+ motorController.stopRunning();
return running;
}
@@ -92,7 +105,10 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
previousNotification.category,
notificationManager.NbNotifications(),
mode,
- alertNotificationService);
+ alertNotificationService,
+ motorController,
+ &timeoutTickCountEnd,
+ &timeoutTickCountStart);
}
return true;
case Pinetime::Applications::TouchEvents::SwipeUp: {
@@ -117,7 +133,10 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
nextNotification.category,
notificationManager.NbNotifications(),
mode,
- alertNotificationService);
+ alertNotificationService,
+ motorController,
+ &timeoutTickCountEnd,
+ &timeoutTickCountStart);
}
return true;
case Pinetime::Applications::TouchEvents::LongTap: {
@@ -152,9 +171,12 @@ Notifications::NotificationItem::NotificationItem(const char* title,
Controllers::NotificationManager::Categories category,
uint8_t notifNb,
Modes mode,
- Pinetime::Controllers::AlertNotificationService& alertNotificationService)
- : notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
-
+ Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Controllers::MotorController& motorController,
+ uint32_t* timeoutEnd,
+ uint32_t* timeoutStart)
+ : notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService},
+ motorController{motorController}, timeoutEnd{timeoutEnd}, timeoutStart{timeoutStart} {
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));
@@ -236,6 +258,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
label_mute = lv_label_create(bt_mute, nullptr);
lv_label_set_text(label_mute, Symbols::volumMute);
lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
+ timeoutOnHold = true;
} break;
}
@@ -249,24 +272,32 @@ Notifications::NotificationItem::NotificationItem(const char* title,
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED)
return;
-
+ callPreviewInteraction();
alertNotificationService.AcceptIncomingCall();
}
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED)
return;
-
+ callPreviewInteraction();
alertNotificationService.MuteIncomingCall();
}
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
if (event != LV_EVENT_CLICKED)
return;
-
+ callPreviewInteraction();
alertNotificationService.RejectIncomingCall();
}
+inline void Notifications::NotificationItem::callPreviewInteraction() {
+ *timeoutStart = xTaskGetTickCount();
+ *timeoutEnd = *timeoutStart + (5 * 1024);
+ timeoutOnHold = false;
+ motorController.stopRunning();
+}
+
+
Notifications::NotificationItem::~NotificationItem() {
lv_obj_clean(lv_scr_act());
}
diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h
index 51ca81da..32bd0770 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,
+ Controllers::MotorController& motorController,
Modes mode);
~Notifications() override;
@@ -33,7 +35,10 @@ namespace Pinetime {
Controllers::NotificationManager::Categories,
uint8_t notifNb,
Modes mode,
- Pinetime::Controllers::AlertNotificationService& alertNotificationService);
+ Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Controllers::MotorController& motorController,
+ uint32_t* timeoutEnd,
+ uint32_t* timeoutStart);
~NotificationItem();
bool Refresh() {
return false;
@@ -41,8 +46,11 @@ namespace Pinetime {
void OnAcceptIncomingCall(lv_event_t event);
void OnMuteIncomingCall(lv_event_t event);
void OnRejectIncomingCall(lv_event_t event);
-
+
+ bool timeoutOnHold = false;
private:
+ void callPreviewInteraction();
+
uint8_t notifNr = 0;
uint8_t notifNb = 0;
char pageText[4];
@@ -58,8 +66,11 @@ namespace Pinetime {
lv_obj_t* label_mute;
lv_obj_t* label_reject;
lv_obj_t* bottomPlaceholder;
+ uint32_t* timeoutEnd;
+ uint32_t* timeoutStart;
Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
+ Controllers::MotorController& motorController;
};
private:
@@ -72,6 +83,7 @@ namespace Pinetime {
Modes mode = Modes::Normal;
std::unique_ptr<NotificationItem> currentItem;
Controllers::NotificationManager::Notification::Id currentId;
+ Controllers::MotorController& motorController;
bool validDisplay = false;
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp
index 2cd24876..5e46e2e5 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..f05ade65 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -266,14 +266,17 @@ void SystemTask::Work() {
if (isSleeping && !isWakingUp) {
GoToRunning();
}
- motorController.SetDuration(35);
+ if (notificationManager.GetLastNotification().category == Controllers::NotificationManager::Categories::IncomingCall) {
+ motorController.startRunning(500);
+ } else {
+ motorController.runForDuration(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: