diff options
Diffstat (limited to 'src/components/ble')
-rw-r--r-- | src/components/ble/AlertNotificationService.cpp | 34 | ||||
-rw-r--r-- | src/components/ble/AlertNotificationService.h | 38 |
2 files changed, 46 insertions, 26 deletions
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}; |