From fbb77baa3b6e487f4c68e08770499cb893c4e035 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:11:53 -0500 Subject: add non-blocking motor controller --- src/components/motor/MotorController.cpp | 40 ++++++++++++++++++++++ src/components/motor/MotorController.h | 57 ++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/components/motor/MotorController.cpp create mode 100644 src/components/motor/MotorController.h (limited to 'src/components') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp new file mode 100644 index 00000000..1885f7bd --- /dev/null +++ b/src/components/motor/MotorController.cpp @@ -0,0 +1,40 @@ +#include "MotorController.h" +#include +#include "systemtask/SystemTask.h" +#include "app_timer.h" +#include "nrf_drv_clock.h" + +APP_TIMER_DEF(vibTimer); + +using namespace Pinetime::Controllers; + +static void lfclk_request(void) //get the low freq. clock +{ + nrf_drv_clock_init(); + nrf_drv_clock_lfclk_request(NULL); +} + +void vibrateTimer(void * p_context) +{ + nrf_gpio_pin_set(pinMotor); +} + +static void create_timers() +{ + //create timer, single shot, re-armable + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); +} + +void MotorController::Init() { + nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_pin_set(pinMotor); + lfclk_request(); //get lfclock ready + app_timer_init(); //start app timers to make calls + create_timers(); +} + +void MotorController::SetDuration(uint8_t motorDuration) { + nrf_gpio_pin_clear(pinMotor); + //start timer for motorDuration miliseconds + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? +} \ No newline at end of file diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h new file mode 100644 index 00000000..6712d933 --- /dev/null +++ b/src/components/motor/MotorController.h @@ -0,0 +1,57 @@ +#pragma once + +#include + +namespace Pinetime { + namespace Controllers { + static constexpr uint8_t pinMotor = 16; + + class MotorController { + public: + void Init(); + void SetDuration(uint8_t motorDuration); + #ifndef NRF_CLOCK_ENABLED + #define NRF_CLOCK_ENABLED 1 + #endif + + #ifndef CLOCK_CONFIG_LF_SRC + #define CLOCK_CONFIG_LF_SRC 1 + #endif + + #ifndef CLOCK_CONFIG_IRQ_PRIORITY + #define CLOCK_CONFIG_IRQ_PRIORITY 6 + #endif + + #define APP_TIMER_ENABLED 1 + #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz + #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 + + #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE + #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 + #endif + + #ifndef APP_TIMER_CONFIG_USE_SCHEDULER + #define APP_TIMER_CONFIG_USE_SCHEDULER 0 + #endif + + #ifndef APP_TIMER_KEEPS_RTC_ACTIVE + #define APP_TIMER_KEEPS_RTC_ACTIVE 0 + #endif + + #ifndef APP_TIMER_SAFE_WINDOW_MS + #define APP_TIMER_SAFE_WINDOW_MS 300000 + #endif + + #ifndef APP_TIMER_WITH_PROFILER + #define APP_TIMER_WITH_PROFILER 0 + #endif + + #ifndef APP_TIMER_CONFIG_SWI_NUMBER + #define APP_TIMER_CONFIG_SWI_NUMBER 0 + #endif + + private: + + }; + } +} \ No newline at end of file -- cgit v1.2.3 From b5992fd7ec369d057ce4fe1b10bbc52ed4f6f988 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Fri, 15 Jan 2021 22:49:37 -0500 Subject: add motor to notifs, fix tabs in motorcontroller.h --- src/components/motor/MotorController.h | 88 ++++++++++++++++---------------- src/displayapp/screens/Notifications.cpp | 4 ++ src/displayapp/screens/Notifications.h | 2 + 3 files changed, 50 insertions(+), 44 deletions(-) (limited to 'src/components') diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 6712d933..63bc9580 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -7,50 +7,50 @@ namespace Pinetime { static constexpr uint8_t pinMotor = 16; class MotorController { - public: - void Init(); - void SetDuration(uint8_t motorDuration); - #ifndef NRF_CLOCK_ENABLED - #define NRF_CLOCK_ENABLED 1 - #endif - - #ifndef CLOCK_CONFIG_LF_SRC - #define CLOCK_CONFIG_LF_SRC 1 - #endif - - #ifndef CLOCK_CONFIG_IRQ_PRIORITY - #define CLOCK_CONFIG_IRQ_PRIORITY 6 - #endif - - #define APP_TIMER_ENABLED 1 - #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz - #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 - - #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 - #endif - - #ifndef APP_TIMER_CONFIG_USE_SCHEDULER - #define APP_TIMER_CONFIG_USE_SCHEDULER 0 - #endif - - #ifndef APP_TIMER_KEEPS_RTC_ACTIVE - #define APP_TIMER_KEEPS_RTC_ACTIVE 0 - #endif - - #ifndef APP_TIMER_SAFE_WINDOW_MS - #define APP_TIMER_SAFE_WINDOW_MS 300000 - #endif - - #ifndef APP_TIMER_WITH_PROFILER - #define APP_TIMER_WITH_PROFILER 0 - #endif - - #ifndef APP_TIMER_CONFIG_SWI_NUMBER - #define APP_TIMER_CONFIG_SWI_NUMBER 0 - #endif - - private: + public: + void Init(); + void SetDuration(uint8_t motorDuration); + #ifndef NRF_CLOCK_ENABLED + #define NRF_CLOCK_ENABLED 1 + #endif + + #ifndef CLOCK_CONFIG_LF_SRC + #define CLOCK_CONFIG_LF_SRC 1 + #endif + + #ifndef CLOCK_CONFIG_IRQ_PRIORITY + #define CLOCK_CONFIG_IRQ_PRIORITY 6 + #endif + + #define APP_TIMER_ENABLED 1 + #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz + #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 + + #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE + #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 + #endif + + #ifndef APP_TIMER_CONFIG_USE_SCHEDULER + #define APP_TIMER_CONFIG_USE_SCHEDULER 0 + #endif + + #ifndef APP_TIMER_KEEPS_RTC_ACTIVE + #define APP_TIMER_KEEPS_RTC_ACTIVE 0 + #endif + + #ifndef APP_TIMER_SAFE_WINDOW_MS + #define APP_TIMER_SAFE_WINDOW_MS 300000 + #endif + + #ifndef APP_TIMER_WITH_PROFILER + #define APP_TIMER_WITH_PROFILER 0 + #endif + + #ifndef APP_TIMER_CONFIG_SWI_NUMBER + #define APP_TIMER_CONFIG_SWI_NUMBER 0 + #endif + + private: }; } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 51a601c4..cfcecec2 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -7,6 +7,9 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio Screen(app), notificationManager{notificationManager}, mode{mode} { notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); + + motorController.Init(); //start the vibration timer setups + if(notification.valid) { currentId = notification.id; currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); @@ -22,6 +25,7 @@ Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::Notificatio style_line.line.width = 3; style_line.line.rounded = 0; + motorController.SetDuration(35); timeoutLine = lv_line_create(lv_scr_act(), nullptr); lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index f5c6a860..345ad15a 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -5,6 +5,7 @@ #include #include "Screen.h" #include "components/ble/NotificationManager.h" +#include "components/motor/MotorController.h" namespace Pinetime { namespace Applications { @@ -45,6 +46,7 @@ namespace Pinetime { const char* text; }; Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::MotorController motorController; Modes mode = Modes::Normal; std::unique_ptr currentItem; Controllers::NotificationManager::Notification::Id currentId; -- cgit v1.2.3 From 10ba20876f37c8e18307dfbc8d06d70bb94d5fae Mon Sep 17 00:00:00 2001 From: Rasmus Schenstrom Date: Tue, 27 Oct 2020 19:51:06 +0100 Subject: Add incoming call functionality Add categories to AlertNotification Add new alert notification screens bases Add Incoming Call Add Modal Add event to AlertNotification Co-authored-by: Robin Karlsson --- src/components/ble/AlertNotificationClient.h | 2 +- src/components/ble/AlertNotificationService.cpp | 34 ++++++++++++++++- src/components/ble/AlertNotificationService.h | 27 ++++++++++++- src/components/ble/NimbleController.h | 1 + src/displayapp/DisplayApp.cpp | 3 ++ src/displayapp/DisplayApp.h | 2 +- src/displayapp/screens/Modal.cpp | 50 +++++++++++++++++++------ src/displayapp/screens/Modal.h | 11 +++++- src/systemtask/SystemTask.cpp | 4 ++ src/systemtask/SystemTask.h | 2 +- 10 files changed, 118 insertions(+), 18 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/AlertNotificationClient.h b/src/components/ble/AlertNotificationClient.h index fa10456c..d49205e3 100644 --- a/src/components/ble/AlertNotificationClient.h +++ b/src/components/ble/AlertNotificationClient.h @@ -83,4 +83,4 @@ namespace Pinetime { bool isDescriptorFound = false; }; } -} \ No newline at end of file +} diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 3156470c..9b9b4e9e 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -9,6 +9,7 @@ using namespace Pinetime::Controllers; constexpr ble_uuid16_t AlertNotificationService::ansUuid; constexpr ble_uuid16_t AlertNotificationService::ansCharUuid; +constexpr ble_uuid16_t AlertNotificationService::ansEventUuid; int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { @@ -33,6 +34,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT .arg = this, .flags = BLE_GATT_CHR_F_WRITE }, + { + .uuid = (ble_uuid_t *) &ansEventUuid, + .access_cb = AlertNotificationCallback, + .arg = this, + .flags = BLE_GATT_CHR_F_NOTIFY, + .val_handle = &eventHandle + }, { 0 } @@ -61,14 +69,36 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize)); + uint8_t* category = new uint8_t[1]; NotificationManager::Notification notif; os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data()); + os_mbuf_copydata(ctxt->om, 0, 1, category); notif.message[messageSize-1] = '\0'; notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; - notificationManager.Push(std::move(notif)); + Pinetime::System::SystemTask::Messages event = Pinetime::System::SystemTask::Messages::OnNewNotification; + + switch(*category) { + case (uint8_t) 0x05: + notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall; + event = Pinetime::System::SystemTask::Messages::OnNewCall; + break; + } - systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification); + notificationManager.Push(std::move(notif)); + systemTask.PushMessage(event); } return 0; } + +void AlertNotificationService::event(char event) { + auto *om = ble_hs_mbuf_from_flat(&event, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +} diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 120312d2..558cdf54 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -24,10 +24,28 @@ namespace Pinetime { int OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt); + void event(char event); + + static const char EVENT_HANG_UP_CALL = 0x00; + static const char EVENT_ANSWER_CALL = 0x01; + private: + static const char ALERT_UNKNOWN = 0x01; + static const char ALERT_SIMPLE_ALERT = 0x02; + static const char ALERT_EMAIL = 0x03; + static const char ALERT_NEWS = 0x04; + static const char ALERT_INCOMING_CALL = 0x05; + static const char ALERT_MISSED_CALL = 0x06; + static const char ALERT_SMS = 0x07; + static const char ALERT_VOICE_MAIL = 0x08; + static const char ALERT_SCHEDULE = 0x09; + static const char ALERT_HIGH_PRIORITY_ALERT = 0x0a; + static const char ALERT_INSTANT_MESSAGE = 0x0b; + static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansCharId {0x2a46}; + static constexpr uint16_t ansEventCharId = {0x2a47}; static constexpr ble_uuid16_t ansUuid { .u { .type = BLE_UUID_TYPE_16 }, @@ -39,11 +57,18 @@ namespace Pinetime { .value = ansCharId }; - struct ble_gatt_chr_def characteristicDefinition[2]; + static constexpr ble_uuid16_t ansEventUuid { + .u { .type = BLE_UUID_TYPE_16 }, + .value = ansEventCharId + }; + + struct ble_gatt_chr_def characteristicDefinition[3]; struct ble_gatt_svc_def serviceDefinition[2]; Pinetime::System::SystemTask &systemTask; NotificationManager ¬ificationManager; + + uint16_t eventHandle; }; } } diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h index a109800c..7bb135da 100644 --- a/src/components/ble/NimbleController.h +++ b/src/components/ble/NimbleController.h @@ -58,6 +58,7 @@ namespace Pinetime { Pinetime::Controllers::MusicService& music() {return musicService;}; Pinetime::Controllers::NavigationService& navigation() {return navService;}; + Pinetime::Controllers::AlertNotificationService& alertService() {return anService;}; uint16_t connHandle(); diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index b6ad90b4..879b5f22 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -128,6 +128,9 @@ void DisplayApp::Refresh() { } } break; + case Messages::NewCall: + modal->NewNotification(notificationManager, &systemTask.nimble().alertService()); + break; case Messages::TouchEvent: { if (state != States::Running) break; auto gesture = OnTouchEvent(); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index da5a7b22..b79df51a 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -34,7 +34,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed, - NewNotification, BleFirmwareUpdateStarted }; + NewNotification, NewCall, BleFirmwareUpdateStarted }; enum class FullRefreshDirections { None, Up, Down }; enum class TouchModes { Gestures, Polling }; diff --git a/src/displayapp/screens/Modal.cpp b/src/displayapp/screens/Modal.cpp index d1a110ea..6d6768dc 100644 --- a/src/displayapp/screens/Modal.cpp +++ b/src/displayapp/screens/Modal.cpp @@ -6,10 +6,7 @@ using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; -Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app) { - - -} +Modal::Modal(Pinetime::Applications::DisplayApp *app) : Screen(app), alertNotificationService(nullptr) {} Modal::~Modal() { lv_obj_clean(lv_scr_act()); @@ -41,13 +38,46 @@ void Modal::OnEvent(lv_obj_t *event_obj, lv_event_t evt) { if(evt == LV_EVENT_DELETE && event_obj == mbox) { Hide(); } else if(evt == LV_EVENT_VALUE_CHANGED) { - /* A button was clicked */ - lv_mbox_start_auto_close(mbox, 0); -// Hide(); + if(event_obj == mbox) { + if(strcmp(lv_mbox_get_active_btn_text(event_obj), this->positiveButton.c_str()) == 0) { + if(alertNotificationService != nullptr) { + alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_ANSWER_CALL); + } + } else { + if(alertNotificationService != nullptr) { + alertNotificationService->event(Pinetime::Controllers::AlertNotificationService::EVENT_HANG_UP_CALL); + } + } + lv_mbox_start_auto_close(mbox, 0); + } } } -void Modal::Show(const char* msg) { +void Modal::NewNotification(Pinetime::Controllers::NotificationManager ¬ificationManager, Pinetime::Controllers::AlertNotificationService* alertService) { + alertNotificationService = alertService; + auto notification = notificationManager.GetLastNotification(); + std::string msg; + if(notification.valid) { + switch(notification.category) { + case Pinetime::Controllers::NotificationManager::Categories::IncomingCall: + this->positiveButton = "Answer"; + this->negativeButton = "Hang up"; + msg += "Incoming call from:\n"; + msg += notification.message.data(); + break; + default: + this->positiveButton = "Ok"; + this->negativeButton = "Cancel"; + msg = notification.message.data(); + break; + } + + static const char *btns[] = {this->positiveButton.c_str(), this->negativeButton.c_str(), ""}; + this->Show(msg.c_str(), btns); + } +} + +void Modal::Show(const char* msg, const char *btns[]) { if(isVisible) return; isVisible = true; lv_style_copy(&modal_style, &lv_style_plain_color); @@ -60,11 +90,9 @@ void Modal::Show(const char* msg) { lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); lv_obj_set_opa_scale_enable(obj, true); /* Enable opacity scaling for the animation */ - static const char * btns2[] = {"Ok", ""}; - /* Create the message box as a child of the modal background */ mbox = lv_mbox_create(obj, nullptr); - lv_mbox_add_btns(mbox, btns2); + lv_mbox_add_btns(mbox, btns); lv_mbox_set_text(mbox, msg); lv_obj_align(mbox, nullptr, LV_ALIGN_CENTER, 0, 0); lv_obj_set_event_cb(mbox, Modal::mbox_event_cb); diff --git a/src/displayapp/screens/Modal.h b/src/displayapp/screens/Modal.h index 9cc177f0..de7575a8 100644 --- a/src/displayapp/screens/Modal.h +++ b/src/displayapp/screens/Modal.h @@ -3,6 +3,8 @@ #include "Screen.h" #include #include +#include +#include namespace Pinetime { namespace Applications { @@ -13,7 +15,9 @@ namespace Pinetime { Modal(DisplayApp* app); ~Modal() override; - void Show(const char* msg); + + void NewNotification(Pinetime::Controllers::NotificationManager ¬ificationManager, Pinetime::Controllers::AlertNotificationService* alertService); + void Show(const char* msg, const char *btns[]); void Hide(); bool Refresh() override; @@ -23,6 +27,11 @@ namespace Pinetime { private: void OnEvent(lv_obj_t *event_obj, lv_event_t evt); + Pinetime::Controllers::AlertNotificationService* alertNotificationService = nullptr; + + std::string positiveButton; + std::string negativeButton; + lv_style_t modal_style; lv_obj_t *obj; lv_obj_t *mbox; diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 13a84c26..2fbc8cf0 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -161,6 +161,10 @@ void SystemTask::Work() { if(isSleeping && !isWakingUp) GoToRunning(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); break; + case Messages::OnNewCall: + if(isSleeping && !isWakingUp) GoToRunning(); + displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewCall); + break; case Messages::BleConnected: ReloadIdleTimer(); isBleDiscoveryTimerRunning = true; diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index cf3f1021..7e031b52 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -27,7 +27,7 @@ namespace Pinetime { namespace System { class SystemTask { public: - enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, BleConnected, + enum class Messages {GoToSleep, GoToRunning, OnNewTime, OnNewNotification, OnNewCall, BleConnected, BleFirmwareUpdateStarted, BleFirmwareUpdateFinished, OnTouchEvent, OnButtonEvent, OnDisplayTaskSleeping }; -- cgit v1.2.3 From 2d90571f0d9b86d7d7fbf414bbadd5092143c670 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Fri, 8 Jan 2021 14:21:52 +0100 Subject: change Notification Event UUID --- src/components/ble/AlertNotificationService.cpp | 4 ++-- src/components/ble/AlertNotificationService.h | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 9b9b4e9e..14d58d51 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -9,7 +9,7 @@ using namespace Pinetime::Controllers; constexpr ble_uuid16_t AlertNotificationService::ansUuid; constexpr ble_uuid16_t AlertNotificationService::ansCharUuid; -constexpr ble_uuid16_t AlertNotificationService::ansEventUuid; +constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid; int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) { @@ -35,7 +35,7 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT .flags = BLE_GATT_CHR_F_WRITE }, { - .uuid = (ble_uuid_t *) &ansEventUuid, + .uuid = (ble_uuid_t *) ¬ificationEventUuid, .access_cb = AlertNotificationCallback, .arg = this, .flags = BLE_GATT_CHR_F_NOTIFY, diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 558cdf54..7c99d3de 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -7,6 +7,9 @@ #undef max #undef min +//c7e50000-78fc-48fe-8e23-433b3a1942d1 +#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd1, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0xe5, 0xc7} + namespace Pinetime { namespace System { @@ -45,7 +48,6 @@ namespace Pinetime { static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansCharId {0x2a46}; - static constexpr uint16_t ansEventCharId = {0x2a47}; static constexpr ble_uuid16_t ansUuid { .u { .type = BLE_UUID_TYPE_16 }, @@ -57,9 +59,9 @@ namespace Pinetime { .value = ansCharId }; - static constexpr ble_uuid16_t ansEventUuid { - .u { .type = BLE_UUID_TYPE_16 }, - .value = ansEventCharId + static constexpr ble_uuid128_t notificationEventUuid { + .u { .type = BLE_UUID_TYPE_128 }, + .value = NOTIFICATION_EVENT_SERVICE_UUID_BASE }; struct ble_gatt_chr_def characteristicDefinition[3]; -- cgit v1.2.3 From 6d76dbc9117693cc611ba106d696222580dbdc95 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Thu, 21 Jan 2021 23:36:17 +0100 Subject: change Notification Event base UUID --- src/components/ble/AlertNotificationService.cpp | 2 +- src/components/ble/AlertNotificationService.h | 26 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 14d58d51..88d2ea8a 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -79,7 +79,7 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle Pinetime::System::SystemTask::Messages event = Pinetime::System::SystemTask::Messages::OnNewNotification; switch(*category) { - case (uint8_t) 0x05: + case (uint8_t) ANS_TYPE_NOTIFICATION_CALL: notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall; event = Pinetime::System::SystemTask::Messages::OnNewCall; break; diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 7c99d3de..17153681 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -7,8 +7,8 @@ #undef max #undef min -//c7e50000-78fc-48fe-8e23-433b3a1942d1 -#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd1, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0xe5, 0xc7} +//00020000-78fc-48fe-8e23-433b3a1942d0 +#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x02, 0x00} namespace Pinetime { @@ -34,17 +34,17 @@ namespace Pinetime { private: - static const char ALERT_UNKNOWN = 0x01; - static const char ALERT_SIMPLE_ALERT = 0x02; - static const char ALERT_EMAIL = 0x03; - static const char ALERT_NEWS = 0x04; - static const char ALERT_INCOMING_CALL = 0x05; - static const char ALERT_MISSED_CALL = 0x06; - static const char ALERT_SMS = 0x07; - static const char ALERT_VOICE_MAIL = 0x08; - static const char ALERT_SCHEDULE = 0x09; - static const char ALERT_HIGH_PRIORITY_ALERT = 0x0a; - static const char ALERT_INSTANT_MESSAGE = 0x0b; + static const char ANS_TYPE_SIMPLE_ALERT = 0x00; + static const char ANS_TYPE_EMAIL = 0x01; + static const char ANS_TYPE_NEWS = 0x02; + static const char ANS_TYPE_NOTIFICATION_CALL = 0x03; + static const char ANS_TYPE_MISSED_CALL = 0x04; + static const char ANS_TYPE_SMS_MMS = 0x05; + static const char ANS_TYPE_VOICE_MAIL = 0x06; + static const char ANS_TYPE_SCHEDULE = 0x07; + static const char ANS_TYPE_HIGH_PRIORITIZED_ALERT = 0x08; + static const char ANS_TYPE_INSTANT_MESSAGE = 0x09; + static const char ANS_TYPE_ALL_ALERTS = 0xff; static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansCharId {0x2a46}; -- cgit v1.2.3 From bf7d77bd341de7360d7e4331ee088dc7a72620fc Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Sat, 23 Jan 2021 15:15:42 -0500 Subject: remove unneeded defines --- src/components/motor/MotorController.cpp | 1 - src/components/motor/MotorController.h | 39 +------------------------------- 2 files changed, 1 insertion(+), 39 deletions(-) (limited to 'src/components') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 1885f7bd..738e6d33 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,7 +4,6 @@ #include "app_timer.h" #include "nrf_drv_clock.h" -APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 63bc9580..01fe9304 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -10,45 +10,8 @@ namespace Pinetime { public: void Init(); void SetDuration(uint8_t motorDuration); - #ifndef NRF_CLOCK_ENABLED - #define NRF_CLOCK_ENABLED 1 - #endif - #ifndef CLOCK_CONFIG_LF_SRC - #define CLOCK_CONFIG_LF_SRC 1 - #endif - - #ifndef CLOCK_CONFIG_IRQ_PRIORITY - #define CLOCK_CONFIG_IRQ_PRIORITY 6 - #endif - - #define APP_TIMER_ENABLED 1 - #define APP_TIMER_CONFIG_RTC_FREQUENCY 15 //2048hz - #define APP_TIMER_CONFIG_IRQ_PRIORITY 6 - - #ifndef APP_TIMER_CONFIG_OP_QUEUE_SIZE - #define APP_TIMER_CONFIG_OP_QUEUE_SIZE 10 - #endif - - #ifndef APP_TIMER_CONFIG_USE_SCHEDULER - #define APP_TIMER_CONFIG_USE_SCHEDULER 0 - #endif - - #ifndef APP_TIMER_KEEPS_RTC_ACTIVE - #define APP_TIMER_KEEPS_RTC_ACTIVE 0 - #endif - - #ifndef APP_TIMER_SAFE_WINDOW_MS - #define APP_TIMER_SAFE_WINDOW_MS 300000 - #endif - - #ifndef APP_TIMER_WITH_PROFILER - #define APP_TIMER_WITH_PROFILER 0 - #endif - - #ifndef APP_TIMER_CONFIG_SWI_NUMBER - #define APP_TIMER_CONFIG_SWI_NUMBER 0 - #endif + APP_TIMER_DEF(vibTimer); private: -- cgit v1.2.3 From 219bafb01ac11a2dc0591d37f00e1acc6d478b54 Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sun, 24 Jan 2021 17:22:39 +0100 Subject: Handle call notification the same way than other notifications. Display the call notifications in the Notification app, with buttons to accept/reject the call. --- src/CMakeLists.txt | 2 - src/components/ble/AlertNotificationService.cpp | 34 ++++-- src/components/ble/AlertNotificationService.h | 38 ++++--- src/displayapp/DisplayApp.cpp | 11 +- src/displayapp/DisplayApp.h | 3 +- src/displayapp/screens/Navigation.h | 4 +- src/displayapp/screens/Notifications.cpp | 133 +++++++++++++++++++++--- src/displayapp/screens/Notifications.h | 46 ++++---- src/displayapp/screens/Tile.cpp | 1 - src/displayapp/screens/Tile.h | 2 - src/main.cpp | 4 +- src/systemtask/SystemTask.cpp | 7 +- src/systemtask/SystemTask.h | 3 +- 13 files changed, 198 insertions(+), 90 deletions(-) (limited to 'src/components') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5955d393..fda2b48e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -426,7 +426,6 @@ list(APPEND SOURCE_FILES displayapp/screens/InfiniPaint.cpp displayapp/screens/Paddle.cpp displayapp/screens/DropDownDemo.cpp - displayapp/screens/Modal.cpp displayapp/screens/BatteryIcon.cpp displayapp/screens/BleIcon.cpp displayapp/screens/NotificationIcon.cpp @@ -520,7 +519,6 @@ set(INCLUDE_FILES displayapp/screens/InfiniPaint.h displayapp/screens/Paddle.h displayapp/screens/DropDownDemo.h - displayapp/screens/Modal.h displayapp/screens/BatteryIcon.h displayapp/screens/BleIcon.h displayapp/screens/NotificationIcon.h diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 88d2ea8a..5fb8338b 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -69,30 +69,46 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om); size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize); auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize)); - uint8_t* category = new uint8_t[1]; + Categories category; NotificationManager::Notification notif; os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data()); - os_mbuf_copydata(ctxt->om, 0, 1, category); + os_mbuf_copydata(ctxt->om, 0, 1, &category); notif.message[messageSize-1] = '\0'; - notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; - Pinetime::System::SystemTask::Messages event = Pinetime::System::SystemTask::Messages::OnNewNotification; - switch(*category) { - case (uint8_t) ANS_TYPE_NOTIFICATION_CALL: + // TODO convert all ANS categories to NotificationController categories + switch(category) { + case Categories::Call: notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall; - event = Pinetime::System::SystemTask::Messages::OnNewCall; + break; + default: + notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert; break; } + auto event = Pinetime::System::SystemTask::Messages::OnNewNotification; notificationManager.Push(std::move(notif)); systemTask.PushMessage(event); } return 0; } -void AlertNotificationService::event(char event) { - auto *om = ble_hs_mbuf_from_flat(&event, 1); +void AlertNotificationService::AcceptIncomingCall() { + auto response = IncomingCallResponses::Answer; + auto *om = ble_hs_mbuf_from_flat(&response, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +} + +void AlertNotificationService::RejectIncomingCall() { + auto response = IncomingCallResponses::Reject; + auto *om = ble_hs_mbuf_from_flat(&response, 1); uint16_t connectionHandle = systemTask.nimble().connHandle(); diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 17153681..612a8a32 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -7,8 +7,8 @@ #undef max #undef min -//00020000-78fc-48fe-8e23-433b3a1942d0 -#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x02, 0x00} +//00020001-78fc-48fe-8e23-433b3a1942d0 +#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x01, 0x00, 0x02, 0x00} namespace Pinetime { @@ -27,24 +27,28 @@ namespace Pinetime { int OnAlert(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt); - void event(char event); - - static const char EVENT_HANG_UP_CALL = 0x00; - static const char EVENT_ANSWER_CALL = 0x01; + void AcceptIncomingCall(); + void RejectIncomingCall(); + enum class IncomingCallResponses : uint8_t { + Reject = 0x00, + Answer = 0x01 + }; private: - static const char ANS_TYPE_SIMPLE_ALERT = 0x00; - static const char ANS_TYPE_EMAIL = 0x01; - static const char ANS_TYPE_NEWS = 0x02; - static const char ANS_TYPE_NOTIFICATION_CALL = 0x03; - static const char ANS_TYPE_MISSED_CALL = 0x04; - static const char ANS_TYPE_SMS_MMS = 0x05; - static const char ANS_TYPE_VOICE_MAIL = 0x06; - static const char ANS_TYPE_SCHEDULE = 0x07; - static const char ANS_TYPE_HIGH_PRIORITIZED_ALERT = 0x08; - static const char ANS_TYPE_INSTANT_MESSAGE = 0x09; - static const char ANS_TYPE_ALL_ALERTS = 0xff; + enum class Categories : uint8_t { + SimpleAlert = 0x00, + Email = 0x01, + News = 0x02, + Call = 0x03, + MissedCall = 0x04, + MmsSms = 0x05, + VoiceMail = 0x06, + Schedule = 0x07, + HighPrioritizedAlert = 0x08, + InstantMessage = 0x09, + All = 0xff + }; static constexpr uint16_t ansId {0x1811}; static constexpr uint16_t ansCharId {0x2a46}; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 879b5f22..292c21f1 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -46,7 +46,6 @@ DisplayApp::DisplayApp(Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Driver heartRateController{heartRateController} { msgQueue = xQueueCreate(queueSize, itemSize); onClockApp = true; - modal.reset(new Screens::Modal(this)); } void DisplayApp::Start() { @@ -110,9 +109,6 @@ void DisplayApp::Refresh() { brightnessController.Restore(); state = States::Running; break; - case Messages::UpdateDateTime: -// modal->Show(); - break; case Messages::UpdateBleConnection: // clockScreen.SetBleConnectionState(bleController.IsConnected() ? Screens::Clock::BleConnectionStates::Connected : Screens::Clock::BleConnectionStates::NotConnected); break; @@ -124,13 +120,10 @@ void DisplayApp::Refresh() { currentScreen.reset(nullptr); lvgl.SetFullRefresh(Components::LittleVgl::FullRefreshDirections::Up); onClockApp = false; - currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Preview)); + currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Preview)); } } break; - case Messages::NewCall: - modal->NewNotification(notificationManager, &systemTask.nimble().alertService()); - break; case Messages::TouchEvent: { if (state != States::Running) break; auto gesture = OnTouchEvent(); @@ -218,7 +211,7 @@ void DisplayApp::RunningState() { case Apps::Music : currentScreen.reset(new Screens::Music(this, systemTask.nimble().music())); break; case Apps::Navigation : currentScreen.reset(new Screens::Navigation(this, systemTask.nimble().navigation())); break; case Apps::FirmwareValidation: currentScreen.reset(new Screens::FirmwareValidation(this, validator)); break; - case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, Screens::Notifications::Modes::Normal)); break; + case Apps::Notifications: currentScreen.reset(new Screens::Notifications(this, notificationManager, systemTask.nimble().alertService(), Screens::Notifications::Modes::Normal)); break; case Apps::HeartRate: currentScreen.reset(new Screens::HeartRate(this, heartRateController)); break; } nextApp = Apps::None; diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index b79df51a..077cbba0 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -34,7 +34,7 @@ namespace Pinetime { public: enum class States {Idle, Running}; enum class Messages : uint8_t {GoToSleep, GoToRunning, UpdateDateTime, UpdateBleConnection, UpdateBatteryLevel, TouchEvent, ButtonPushed, - NewNotification, NewCall, BleFirmwareUpdateStarted }; + NewNotification, BleFirmwareUpdateStarted }; enum class FullRefreshDirections { None, Up, Down }; enum class TouchModes { Gestures, Polling }; @@ -85,7 +85,6 @@ namespace Pinetime { Apps nextApp = Apps::None; bool onClockApp = false; // TODO find a better way to know that we should handle gestures and button differently for the Clock app. Controllers::BrightnessController brightnessController; - std::unique_ptr modal; Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::FirmwareValidator validator; TouchModes touchMode = TouchModes::Gestures; diff --git a/src/displayapp/screens/Navigation.h b/src/displayapp/screens/Navigation.h index 9fdd37d9..ab622496 100644 --- a/src/displayapp/screens/Navigation.h +++ b/src/displayapp/screens/Navigation.h @@ -145,7 +145,7 @@ namespace Pinetime { const lv_img_dsc_t* iconForName(std::string icon); - std::array, 89 > m_iconMap = { { + std::array, 89 > m_iconMap;/* = { { {"arrive-left", &arrive_left}, {"arrive-right", &arrive_right}, {"arrive-straight", &arrive_straight}, @@ -231,7 +231,7 @@ namespace Pinetime { {"turn-slight-right", &turn_slight_right}, {"turn-straight", &turn_straight}, {"updown", &updown}, - {"uturn", &uturn} } }; + {"uturn", &uturn} } };*/ }; } } diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 51a601c4..79189164 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -1,18 +1,34 @@ #include "Notifications.h" #include +#include "components/ble/MusicService.h" using namespace Pinetime::Applications::Screens; -Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, Modes mode) : - Screen(app), notificationManager{notificationManager}, mode{mode} { +Notifications::Notifications(DisplayApp *app, + Pinetime::Controllers::NotificationManager ¬ificationManager, + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Modes mode) : + Screen(app), notificationManager{notificationManager}, alertNotificationService{alertNotificationService}, mode{mode} { notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); if(notification.valid) { currentId = notification.id; - currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + notification.message.data(), + notification.index, + notification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); validDisplay = true; } else { - currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); + currentItem.reset(new NotificationItem("\nNotification", + "No notification to display", + 0, + notification.category, + notificationManager.NbNotifications(), + Modes::Preview, + alertNotificationService)); } if(mode == Modes::Preview) { @@ -69,7 +85,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = previousNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); - currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + previousNotification.message.data(), + previousNotification.index, + previousNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); } return true; case Pinetime::Applications::TouchEvents::SwipeDown: { @@ -85,7 +107,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentId = nextNotification.id; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); - currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); + currentItem.reset(new NotificationItem("\nNotification", + nextNotification.message.data(), + nextNotification.index, + nextNotification.category, + notificationManager.NbNotifications(), + mode, + alertNotificationService)); } return true; default: @@ -99,9 +127,26 @@ bool Notifications::OnButtonPushed() { return true; } +namespace { + static void AcceptIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast(obj->user_data); + item->OnAcceptIncomingCall(event); + } -Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) - : notifNr{notifNr}, notifNb{notifNb}, mode{mode} { + static void RejectIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast(obj->user_data); + item->OnRejectIncomingCall(event); + } +} + +Notifications::NotificationItem::NotificationItem(const char *title, + const char *msg, + uint8_t notifNr, + Controllers::NotificationManager::Categories category, + uint8_t notifNb, + Modes mode, + Pinetime::Controllers::AlertNotificationService& alertNotificationService) + : notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService} { container1 = lv_cont_create(lv_scr_act(), nullptr); static lv_style_t contStyle; lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN)); @@ -142,16 +187,59 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char auto titleHeight = lv_obj_get_height(t1); - l1 = lv_label_create(container1, nullptr); - lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); - lv_obj_set_pos(l1, textStyle.body.padding.left, - titleHeight + offscreenOffset + textStyle.body.padding.bottom + - textStyle.body.padding.top); + switch(category) { + default: { + l1 = lv_label_create(container1, nullptr); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, + titleHeight + offscreenOffset + textStyle.body.padding.bottom + + textStyle.body.padding.top); + + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l1, msg); + } + break; + case Controllers::NotificationManager::Categories::IncomingCall: { + l1 = lv_label_create(container1, nullptr); + lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l1, textStyle.body.padding.left, + titleHeight + offscreenOffset + textStyle.body.padding.bottom + + textStyle.body.padding.top); + + lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l1, true); + lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l1, "Incoming call from "); + auto l1Height = lv_obj_get_height(l1); + + l2 = lv_label_create(container1, nullptr); + lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle); + lv_obj_set_pos(l2, textStyle.body.padding.left, + titleHeight + l1Height + offscreenOffset + (textStyle.body.padding.bottom*2) + + (textStyle.body.padding.top*2)); + lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK); + lv_label_set_body_draw(l2, true); + lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); + lv_label_set_text(l2, msg); + + bt_accept = lv_btn_create(container1, nullptr); + lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20); + bt_accept->user_data = this; + lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler); - lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK); - lv_label_set_body_draw(l1, true); - lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right)); - lv_label_set_text(l1, msg); + label_accept = lv_label_create(bt_accept, nullptr); + lv_label_set_text(label_accept, "Accept"); + + bt_reject = lv_btn_create(container1, nullptr); + lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20); + bt_reject->user_data = this; + lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler); + label_reject = lv_label_create(bt_reject, nullptr); + lv_label_set_text(label_reject, "Reject"); + } + } if(mode == Modes::Normal) { if(notifNr < notifNb) { @@ -166,6 +254,17 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char } } +void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.AcceptIncomingCall(); +} + +void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.RejectIncomingCall(); +} Notifications::NotificationItem::~NotificationItem() { lv_obj_clean(lv_scr_act()); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index f5c6a860..4305c796 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -19,26 +19,36 @@ namespace Pinetime { bool OnButtonPushed() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + class NotificationItem { + public: + NotificationItem(const char* title, const char* msg, uint8_t notifNr, Controllers::NotificationManager::Categories, uint8_t notifNb, Modes mode, Pinetime::Controllers::AlertNotificationService& alertNotificationService); + ~NotificationItem(); + bool Refresh() {return false;} + void OnAcceptIncomingCall(lv_event_t event); + void OnRejectIncomingCall(lv_event_t event); + private: - bool running = true; + uint8_t notifNr = 0; + uint8_t notifNb = 0; + char pageText[4]; - class NotificationItem { - public: - NotificationItem(const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb, Modes mode); - ~NotificationItem(); - bool Refresh() {return false;} - - private: - uint8_t notifNr = 0; - uint8_t notifNb = 0; - char pageText[4]; - - lv_obj_t* container1; - lv_obj_t* t1; - lv_obj_t* l1; - lv_obj_t* bottomPlaceholder; - Modes mode; - }; + lv_obj_t* container1; + lv_obj_t* t1; + lv_obj_t* l1; + lv_obj_t* l2; + lv_obj_t* bt_accept; + lv_obj_t* bt_reject; + lv_obj_t* label_accept; + lv_obj_t* label_reject; + lv_obj_t* bottomPlaceholder; + Modes mode; + Pinetime::Controllers::AlertNotificationService& alertNotificationService; + + + }; + + private: + bool running = true; struct NotificationData { const char* title; diff --git a/src/displayapp/screens/Tile.cpp b/src/displayapp/screens/Tile.cpp index c1a5e94f..214d2736 100644 --- a/src/displayapp/screens/Tile.cpp +++ b/src/displayapp/screens/Tile.cpp @@ -22,7 +22,6 @@ Tile::Tile(DisplayApp* app, std::array& applications) : Screen( appIndex++; } } - modal.reset(new Modal(app)); btnm1 = lv_btnm_create(lv_scr_act(), nullptr); lv_btnm_set_map(btnm1, btnm_map1); diff --git a/src/displayapp/screens/Tile.h b/src/displayapp/screens/Tile.h index 7edf67b2..bf3f5d67 100644 --- a/src/displayapp/screens/Tile.h +++ b/src/displayapp/screens/Tile.h @@ -29,8 +29,6 @@ namespace Pinetime { lv_obj_t * btnm1; bool running = true; - std::unique_ptr modal; - const char* btnm_map1[8]; Pinetime::Applications::Apps apps[6]; }; diff --git a/src/main.cpp b/src/main.cpp index 3b993ee9..01ee3d86 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -98,8 +98,6 @@ void ble_manager_set_ble_disconnection_callback(void (*disconnection)()); static constexpr uint8_t pinTouchIrq = 28; std::unique_ptr systemTask; -Pinetime::Controllers::NotificationManager notificationManager; - void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { if(pin == pinTouchIrq) { systemTask->OnTouchEvent(); @@ -241,7 +239,7 @@ int main(void) { debounceTimer = xTimerCreate ("debounceTimer", 200, pdFALSE, (void *) 0, DebounceTimerCallback); systemTask.reset(new Pinetime::System::SystemTask(spi, lcd, spiNorFlash, twiMaster, touchPanel, lvgl, batteryController, bleController, - dateTimeController, notificationManager, heartRateSensor)); + dateTimeController, heartRateSensor)); systemTask->Start(); nimble_port_init(); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 2fbc8cf0..f998ac82 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -40,13 +40,12 @@ SystemTask::SystemTask(Drivers::SpiMaster &spi, Drivers::St7789 &lcd, Components::LittleVgl &lvgl, Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime &dateTimeController, - Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Drivers::Hrs3300& heartRateSensor) : spi{spi}, lcd{lcd}, spiNorFlash{spiNorFlash}, twiMaster{twiMaster}, touchPanel{touchPanel}, lvgl{lvgl}, batteryController{batteryController}, heartRateController{*this}, bleController{bleController}, dateTimeController{dateTimeController}, - watchdog{}, watchdogView{watchdog}, notificationManager{notificationManager}, + watchdog{}, watchdogView{watchdog}, heartRateSensor{heartRateSensor}, nimbleController(*this, bleController,dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { systemTasksMsgQueue = xQueueCreate(10, 1); @@ -161,10 +160,6 @@ void SystemTask::Work() { if(isSleeping && !isWakingUp) GoToRunning(); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); break; - case Messages::OnNewCall: - if(isSleeping && !isWakingUp) GoToRunning(); - displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewCall); - break; case Messages::BleConnected: ReloadIdleTimer(); isBleDiscoveryTimerRunning = true; diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 7e031b52..ed3574c0 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -37,7 +37,6 @@ namespace Pinetime { Components::LittleVgl &lvgl, Controllers::Battery &batteryController, Controllers::Ble &bleController, Controllers::DateTime &dateTimeController, - Pinetime::Controllers::NotificationManager& manager, Pinetime::Drivers::Hrs3300& heartRateSensor); @@ -73,7 +72,7 @@ namespace Pinetime { std::atomic isWakingUp{false}; Pinetime::Drivers::Watchdog watchdog; Pinetime::Drivers::WatchdogView watchdogView; - Pinetime::Controllers::NotificationManager& notificationManager; + Pinetime::Controllers::NotificationManager notificationManager; Pinetime::Drivers::Hrs3300& heartRateSensor; Pinetime::Controllers::NimbleController nimbleController; -- cgit v1.2.3 From 169b861af1fd8b1f7834ad78a8880882b236dc96 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Mon, 25 Jan 2021 14:18:57 +0100 Subject: fix build warnings in HR implementation --- src/components/ble/HeartRateService.cpp | 4 +--- src/components/ble/NimbleController.cpp | 4 ++-- src/components/heartrate/Ppg.cpp | 2 +- src/drivers/Hrs3300.cpp | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index ecd6235d..ee115ed0 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -57,9 +57,7 @@ void HeartRateService::Init() { int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context) { if(attributeHandle == heartRateMeasurementHandle) { - NRF_LOG_INFO("BATTERY : handle = %d", heartRateMeasurementHandle); - static uint8_t batteryValue = heartRateController.HeartRate(); - + NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle); uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value int res = os_mbuf_append(context->om, buffer, 2); diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp index f2786ea1..eb83c709 100644 --- a/src/components/ble/NimbleController.cpp +++ b/src/components/ble/NimbleController.cpp @@ -38,8 +38,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, navService{systemTask}, batteryInformationService{batteryController}, immediateAlertService{systemTask, notificationManager}, - serviceDiscovery({¤tTimeClient, &alertNotificationClient}), - heartRateService{systemTask, heartRateController} { + heartRateService{systemTask, heartRateController}, + serviceDiscovery({¤tTimeClient, &alertNotificationClient}) { } int GAPEventCallback(struct ble_gap_event *event, void *arg) { diff --git a/src/components/heartrate/Ppg.cpp b/src/components/heartrate/Ppg.cpp index 233c3003..e84cbdf3 100644 --- a/src/components/heartrate/Ppg.cpp +++ b/src/components/heartrate/Ppg.cpp @@ -13,7 +13,7 @@ using namespace Pinetime::Controllers; namespace { int Compare(int* d1, int* d2, size_t count) { int e = 0; - for(int i = 0; i < count; i++) { + for(size_t i = 0; i < count; i++) { auto d = d1[i] - d2[i]; e += d * d; } diff --git a/src/drivers/Hrs3300.cpp b/src/drivers/Hrs3300.cpp index 2aded7d3..a16c8e4e 100644 --- a/src/drivers/Hrs3300.cpp +++ b/src/drivers/Hrs3300.cpp @@ -73,10 +73,10 @@ void Hrs3300::SetGain(uint8_t gain) { static constexpr uint8_t maxGain = 64; gain = std::min(gain, maxGain); uint8_t hgain = 0; - while((1 << hgain) < gain) + while((1 << hgain) < gain) { hgain++; - WriteRegister(static_cast(Registers::Hgain), hgain << 2); + } } void Hrs3300::SetDrive(uint8_t drive) { -- cgit v1.2.3 From f27e63290639ca257e88298b60429d72271c4954 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Mon, 25 Jan 2021 12:44:58 -0500 Subject: move app timer def --- src/components/motor/MotorController.cpp | 3 ++- src/components/motor/MotorController.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/components') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 738e6d33..51a01b4c 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -4,6 +4,7 @@ #include "app_timer.h" #include "nrf_drv_clock.h" +APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; @@ -36,4 +37,4 @@ void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); //start timer for motorDuration miliseconds app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? -} \ No newline at end of file +} diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 01fe9304..52ab558c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -1,6 +1,7 @@ #pragma once #include +#include "app_timer.h" namespace Pinetime { namespace Controllers { @@ -11,10 +12,8 @@ namespace Pinetime { void Init(); void SetDuration(uint8_t motorDuration); - APP_TIMER_DEF(vibTimer); - private: - + app_timer_id_t vibTimer; }; } -} \ No newline at end of file +} -- cgit v1.2.3 From da56ca5bfb5c9569d53bbe26ea8e6630dbead9f6 Mon Sep 17 00:00:00 2001 From: jlukanc <27705324+jlukanc1@users.noreply.github.com> Date: Mon, 25 Jan 2021 13:03:04 -0500 Subject: remove vibtimer from .h to fix nonstop vibration --- src/components/motor/MotorController.h | 1 - 1 file changed, 1 deletion(-) (limited to 'src/components') diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 52ab558c..9ce91c52 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,7 +13,6 @@ namespace Pinetime { void SetDuration(uint8_t motorDuration); private: - app_timer_id_t vibTimer; }; } } -- cgit v1.2.3 From d4c31bcbbe2f8b6d2e6c45203193745f9cb2a41b Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Wed, 27 Jan 2021 13:45:06 +0100 Subject: add mute button and functionality for call notification + new button icons --- src/components/ble/AlertNotificationService.cpp | 13 ++++++++++ src/components/ble/AlertNotificationService.h | 4 ++- src/displayapp/screens/Notifications.cpp | 33 +++++++++++++++++++++---- src/displayapp/screens/Notifications.h | 3 +++ 4 files changed, 47 insertions(+), 6 deletions(-) (limited to 'src/components') diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp index 5fb8338b..0639119c 100644 --- a/src/components/ble/AlertNotificationService.cpp +++ b/src/components/ble/AlertNotificationService.cpp @@ -118,3 +118,16 @@ void AlertNotificationService::RejectIncomingCall() { ble_gattc_notify_custom(connectionHandle, eventHandle, om); } + +void AlertNotificationService::MuteIncomingCall() { + auto response = IncomingCallResponses::Mute; + auto *om = ble_hs_mbuf_from_flat(&response, 1); + + uint16_t connectionHandle = systemTask.nimble().connHandle(); + + if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) { + return; + } + + ble_gattc_notify_custom(connectionHandle, eventHandle, om); +} \ No newline at end of file diff --git a/src/components/ble/AlertNotificationService.h b/src/components/ble/AlertNotificationService.h index 612a8a32..caad7a2b 100644 --- a/src/components/ble/AlertNotificationService.h +++ b/src/components/ble/AlertNotificationService.h @@ -29,10 +29,12 @@ namespace Pinetime { void AcceptIncomingCall(); void RejectIncomingCall(); + void MuteIncomingCall(); enum class IncomingCallResponses : uint8_t { Reject = 0x00, - Answer = 0x01 + Answer = 0x01, + Mute = 0x02 }; private: diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 79189164..7ca91cfb 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -1,8 +1,11 @@ #include "Notifications.h" #include #include "components/ble/MusicService.h" +#include "Symbols.h" using namespace Pinetime::Applications::Screens; +extern lv_font_t jetbrains_mono_extrabold_compressed; +extern lv_font_t jetbrains_mono_bold_20; Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, @@ -132,6 +135,11 @@ namespace { auto* item = static_cast(obj->user_data); item->OnAcceptIncomingCall(event); } + + static void MuteIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { + auto* item = static_cast(obj->user_data); + item->OnMuteIncomingCall(event); + } static void RejectIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) { auto* item = static_cast(obj->user_data); @@ -225,19 +233,28 @@ Notifications::NotificationItem::NotificationItem(const char *title, lv_label_set_text(l2, msg); bt_accept = lv_btn_create(container1, nullptr); - lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20); bt_accept->user_data = this; lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler); - + lv_obj_set_size(bt_accept, LV_HOR_RES / 3, 80); + lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20); label_accept = lv_label_create(bt_accept, nullptr); - lv_label_set_text(label_accept, "Accept"); + lv_label_set_text(label_accept, Symbols::phone); bt_reject = lv_btn_create(container1, nullptr); - lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20); bt_reject->user_data = this; lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler); + lv_obj_set_size(bt_reject, LV_HOR_RES / 3, 80); + lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20); label_reject = lv_label_create(bt_reject, nullptr); - lv_label_set_text(label_reject, "Reject"); + lv_label_set_text(label_reject, Symbols::phoneSlash); + + bt_mute = lv_btn_create(container1, nullptr); + bt_mute->user_data = this; + lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler); + lv_obj_set_size(bt_mute, LV_HOR_RES / 3, 80); + lv_obj_align(bt_mute, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -20); + label_mute = lv_label_create(bt_mute, nullptr); + lv_label_set_text(label_mute, Symbols::volumMute); } } @@ -260,6 +277,12 @@ void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) { alertNotificationService.AcceptIncomingCall(); } +void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) { + if (event != LV_EVENT_CLICKED) return; + + alertNotificationService.MuteIncomingCall(); +} + void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) { if (event != LV_EVENT_CLICKED) return; diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index aafd3e33..c40e7002 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -29,6 +29,7 @@ namespace Pinetime { ~NotificationItem(); bool Refresh() {return false;} void OnAcceptIncomingCall(lv_event_t event); + void OnMuteIncomingCall(lv_event_t event); void OnRejectIncomingCall(lv_event_t event); private: @@ -41,8 +42,10 @@ namespace Pinetime { lv_obj_t* l1; lv_obj_t* l2; lv_obj_t* bt_accept; + lv_obj_t* bt_mute; lv_obj_t* bt_reject; lv_obj_t* label_accept; + lv_obj_t* label_mute; lv_obj_t* label_reject; lv_obj_t* bottomPlaceholder; Modes mode; -- cgit v1.2.3 From 7ab153cd7690db8a43bde1af792edecc5e0f8d5d Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Fri, 5 Feb 2021 17:06:56 +0100 Subject: refactor MotorController --- src/components/motor/MotorController.cpp | 33 +++++++++----------------------- src/components/motor/MotorController.h | 1 + 2 files changed, 10 insertions(+), 24 deletions(-) (limited to 'src/components') diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 51a01b4c..7f53fbf7 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -2,39 +2,24 @@ #include #include "systemtask/SystemTask.h" #include "app_timer.h" -#include "nrf_drv_clock.h" APP_TIMER_DEF(vibTimer); using namespace Pinetime::Controllers; -static void lfclk_request(void) //get the low freq. clock -{ - nrf_drv_clock_init(); - nrf_drv_clock_lfclk_request(NULL); -} - -void vibrateTimer(void * p_context) -{ - nrf_gpio_pin_set(pinMotor); -} - -static void create_timers() -{ - //create timer, single shot, re-armable - app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrateTimer); -} - void MotorController::Init() { - nrf_gpio_cfg_output(pinMotor); // set the motor pin as an output + nrf_gpio_cfg_output(pinMotor); nrf_gpio_pin_set(pinMotor); - lfclk_request(); //get lfclock ready - app_timer_init(); //start app timers to make calls - create_timers(); + app_timer_init(); + app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate); } void MotorController::SetDuration(uint8_t motorDuration) { nrf_gpio_pin_clear(pinMotor); - //start timer for motorDuration miliseconds - app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); //timers trigger at end of duration? + /* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/ + app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL); } + +void MotorController::vibrate(void * p_context) { + nrf_gpio_pin_set(pinMotor); +} \ No newline at end of file diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 9ce91c52..bdc20c0c 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -13,6 +13,7 @@ namespace Pinetime { void SetDuration(uint8_t motorDuration); private: + static void vibrate(void * p_context); }; } } -- cgit v1.2.3 From 1e2cc3ce91b402459790332b84e3f8dcbe5dc340 Mon Sep 17 00:00:00 2001 From: petter <39340152+petterhs@users.noreply.github.com> Date: Sun, 7 Feb 2021 13:31:02 +0100 Subject: add vibration toggle --- src/components/ble/NotificationManager.cpp | 8 ++++++++ src/components/ble/NotificationManager.h | 3 +++ src/displayapp/screens/Notifications.cpp | 4 ++++ src/systemtask/SystemTask.cpp | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp index dabcb4ba..fd66c194 100644 --- a/src/components/ble/NotificationManager.cpp +++ b/src/components/ble/NotificationManager.cpp @@ -71,6 +71,14 @@ bool NotificationManager::AreNewNotificationsAvailable() { return newNotification; } +bool NotificationManager::isVibrationEnabled() { + return vibrationEnabled; +} + +void NotificationManager::toggleVibrations() { + vibrationEnabled = !vibrationEnabled; +} + bool NotificationManager::ClearNewNotificationFlag() { return newNotification.exchange(false); } diff --git a/src/components/ble/NotificationManager.h b/src/components/ble/NotificationManager.h index 036d2ed9..4dce4eda 100644 --- a/src/components/ble/NotificationManager.h +++ b/src/components/ble/NotificationManager.h @@ -28,6 +28,8 @@ namespace Pinetime { Notification GetPrevious(Notification::Id id); bool ClearNewNotificationFlag(); bool AreNewNotificationsAvailable(); + bool isVibrationEnabled(); + void toggleVibrations(); static constexpr size_t MaximumMessageSize() { return MessageSize; }; size_t NbNotifications() const; @@ -40,6 +42,7 @@ namespace Pinetime { uint8_t writeIndex = 0; bool empty = true; std::atomic newNotification{false}; + bool vibrationEnabled = true; }; } } \ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index ece9eb07..b481c972 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -92,6 +92,10 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); } return true; + case Pinetime::Applications::TouchEvents::LongTap: { + notificationManager.toggleVibrations(); + return true; + } default: return false; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index e195de8e..250a4ab4 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -162,7 +162,7 @@ void SystemTask::Work() { break; case Messages::OnNewNotification: if(isSleeping && !isWakingUp) GoToRunning(); - motorController.SetDuration(35); + if(notificationManager.isVibrationEnabled()) motorController.SetDuration(35); displayApp->PushMessage(Pinetime::Applications::DisplayApp::Messages::NewNotification); break; case Messages::BleConnected: -- cgit v1.2.3