@@ -9,6 +9,7 @@ using namespace Pinetime::Controllers;
99
1010constexpr ble_uuid16_t AlertNotificationService::ansUuid;
1111constexpr ble_uuid16_t AlertNotificationService::ansCharUuid;
12+ constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid;
1213
1314
1415int 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
3334 .arg = this ,
3435 .flags = BLE_GATT_CHR_F_WRITE
3536 },
37+ {
38+ .uuid = (ble_uuid_t *) ¬ificationEventUuid,
39+ .access_cb = AlertNotificationCallback,
40+ .arg = this ,
41+ .flags = BLE_GATT_CHR_F_NOTIFY,
42+ .val_handle = &eventHandle
43+ },
3644 {
3745 0
3846 }
@@ -61,14 +69,65 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
6169 const auto dbgPacketLen = OS_MBUF_PKTLEN (ctxt->om );
6270 size_t bufferSize = std::min (dbgPacketLen + stringTerminatorSize, maxBufferSize);
6371 auto messageSize = std::min (maxMessageSize, (bufferSize-headerSize));
72+ Categories category;
6473
6574 NotificationManager::Notification notif;
6675 os_mbuf_copydata (ctxt->om , headerSize, messageSize-1 , notif.message .data ());
76+ os_mbuf_copydata (ctxt->om , 0 , 1 , &category);
6777 notif.message [messageSize-1 ] = ' \0 ' ;
68- notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
69- notificationManager.Push (std::move (notif));
7078
71- systemTask.PushMessage (Pinetime::System::SystemTask::Messages::OnNewNotification);
79+ // TODO convert all ANS categories to NotificationController categories
80+ switch (category) {
81+ case Categories::Call:
82+ notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall;
83+ break ;
84+ default :
85+ notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
86+ break ;
87+ }
88+
89+ auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
90+ notificationManager.Push (std::move (notif));
91+ systemTask.PushMessage (event);
7292 }
7393 return 0 ;
7494}
95+
96+ void AlertNotificationService::AcceptIncomingCall () {
97+ auto response = IncomingCallResponses::Answer;
98+ auto *om = ble_hs_mbuf_from_flat (&response, 1 );
99+
100+ uint16_t connectionHandle = systemTask.nimble ().connHandle ();
101+
102+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
103+ return ;
104+ }
105+
106+ ble_gattc_notify_custom (connectionHandle, eventHandle, om);
107+ }
108+
109+ void AlertNotificationService::RejectIncomingCall () {
110+ auto response = IncomingCallResponses::Reject;
111+ auto *om = ble_hs_mbuf_from_flat (&response, 1 );
112+
113+ uint16_t connectionHandle = systemTask.nimble ().connHandle ();
114+
115+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
116+ return ;
117+ }
118+
119+ ble_gattc_notify_custom (connectionHandle, eventHandle, om);
120+ }
121+
122+ void AlertNotificationService::MuteIncomingCall () {
123+ auto response = IncomingCallResponses::Mute;
124+ auto *om = ble_hs_mbuf_from_flat (&response, 1 );
125+
126+ uint16_t connectionHandle = systemTask.nimble ().connHandle ();
127+
128+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
129+ return ;
130+ }
131+
132+ ble_gattc_notify_custom (connectionHandle, eventHandle, om);
133+ }
0 commit comments