summaryrefslogtreecommitdiff
path: root/src/components/ble
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ble')
-rw-r--r--src/components/ble/AlertNotificationClient.h2
-rw-r--r--src/components/ble/AlertNotificationService.cpp65
-rw-r--r--src/components/ble/AlertNotificationService.h35
-rw-r--r--src/components/ble/BatteryInformationService.cpp1
-rw-r--r--src/components/ble/CurrentTimeClient.cpp1
-rw-r--r--src/components/ble/CurrentTimeService.cpp1
-rw-r--r--src/components/ble/HeartRateService.cpp4
-rw-r--r--src/components/ble/NimbleController.cpp4
-rw-r--r--src/components/ble/NimbleController.h1
-rw-r--r--src/components/ble/NotificationManager.cpp8
-rw-r--r--src/components/ble/NotificationManager.h3
11 files changed, 115 insertions, 10 deletions
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..0639119c 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_uuid128_t AlertNotificationService::notificationEventUuid;
int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
@@ -34,6 +35,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT
.flags = BLE_GATT_CHR_F_WRITE
},
{
+ .uuid = (ble_uuid_t *) &notificationEventUuid,
+ .access_cb = AlertNotificationCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &eventHandle
+ },
+ {
0
}
},
@@ -61,14 +69,65 @@ 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));
+ Categories category;
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));
- systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
+ // TODO convert all ANS categories to NotificationController categories
+ switch(category) {
+ case Categories::Call:
+ notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall;
+ 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::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();
+
+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
+ return;
+ }
+
+ 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 120312d2..caad7a2b 100644
--- a/src/components/ble/AlertNotificationService.h
+++ b/src/components/ble/AlertNotificationService.h
@@ -7,6 +7,9 @@
#undef max
#undef min
+//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 {
namespace System {
@@ -24,8 +27,31 @@ namespace Pinetime {
int OnAlert(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt);
+ void AcceptIncomingCall();
+ void RejectIncomingCall();
+ void MuteIncomingCall();
+
+ enum class IncomingCallResponses : uint8_t {
+ Reject = 0x00,
+ Answer = 0x01,
+ Mute = 0x02
+ };
private:
+ 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};
@@ -39,11 +65,18 @@ namespace Pinetime {
.value = ansCharId
};
- struct ble_gatt_chr_def characteristicDefinition[2];
+ 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];
struct ble_gatt_svc_def serviceDefinition[2];
Pinetime::System::SystemTask &systemTask;
NotificationManager &notificationManager;
+
+ uint16_t eventHandle;
};
}
}
diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp
index f7d895c2..bc66ff72 100644
--- a/src/components/ble/BatteryInformationService.cpp
+++ b/src/components/ble/BatteryInformationService.cpp
@@ -1,3 +1,4 @@
+#include <nrf_log.h>
#include "BatteryInformationService.h"
#include "components/battery/BatteryController.h"
diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp
index be50fede..758f636c 100644
--- a/src/components/ble/CurrentTimeClient.cpp
+++ b/src/components/ble/CurrentTimeClient.cpp
@@ -1,5 +1,6 @@
#include "CurrentTimeClient.h"
#include <hal/nrf_rtc.h>
+#include <nrf_log.h>
#include "components/datetime/DateTimeController.h"
using namespace Pinetime::Controllers;
diff --git a/src/components/ble/CurrentTimeService.cpp b/src/components/ble/CurrentTimeService.cpp
index 3a6264e2..9f14edc7 100644
--- a/src/components/ble/CurrentTimeService.cpp
+++ b/src/components/ble/CurrentTimeService.cpp
@@ -1,5 +1,6 @@
#include "CurrentTimeService.h"
#include <hal/nrf_rtc.h>
+#include <nrf_log.h>
using namespace Pinetime::Controllers;
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({&currentTimeClient, &alertNotificationClient}),
- heartRateService{systemTask, heartRateController} {
+ heartRateService{systemTask, heartRateController},
+ serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
}
int GAPEventCallback(struct ble_gap_event *event, void *arg) {
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/components/ble/NotificationManager.cpp b/src/components/ble/NotificationManager.cpp
index dabcb4ba..36abf026 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..075a9a45 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<bool> newNotification{false};
+ bool vibrationEnabled = true;
};
}
} \ No newline at end of file