summaryrefslogtreecommitdiff
path: root/src/components/ble/ImmediateAlertService.cpp
diff options
context:
space:
mode:
authorAvamander <avamander@gmail.com>2020-10-02 22:16:48 +0300
committerAvamander <avamander@gmail.com>2020-10-02 22:16:48 +0300
commit6c86d1d9d706706fcb6f214aba8259e61ed68755 (patch)
tree2f4137a9916869cee18fd01449aa83ee586b9604 /src/components/ble/ImmediateAlertService.cpp
parent4daab2692692d47af24a9384eb0f402821527882 (diff)
Fixed all the includes that were broken due to the renames
Diffstat (limited to 'src/components/ble/ImmediateAlertService.cpp')
-rw-r--r--src/components/ble/ImmediateAlertService.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/components/ble/ImmediateAlertService.cpp b/src/components/ble/ImmediateAlertService.cpp
new file mode 100644
index 00000000..3b7f47bf
--- /dev/null
+++ b/src/components/ble/ImmediateAlertService.cpp
@@ -0,0 +1,76 @@
+#include <systemtask/SystemTask.h>
+#include "ImmediateAlertService.h"
+#include "AlertNotificationService.h"
+
+using namespace Pinetime::Controllers;
+
+constexpr ble_uuid16_t ImmediateAlertService::immediateAlertServiceUuid;
+constexpr ble_uuid16_t ImmediateAlertService::alertLevelUuid;
+
+namespace {
+ int AlertLevelCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
+ auto *immediateAlertService = static_cast<ImmediateAlertService *>(arg);
+ return immediateAlertService->OnAlertLevelChanged(conn_handle, attr_handle, ctxt);
+ }
+
+ const char* ToString(ImmediateAlertService::Levels level) {
+ switch (level) {
+ case ImmediateAlertService::Levels::NoAlert: return "Alert : None";
+ case ImmediateAlertService::Levels::HighAlert: return "Alert : High";
+ case ImmediateAlertService::Levels::MildAlert: return "Alert : Mild";
+ default: return "";
+ }
+ }
+}
+
+ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask &systemTask,
+ Pinetime::Controllers::NotificationManager &notificationManager) :
+ systemTask{systemTask},
+ notificationManager{notificationManager},
+ characteristicDefinition{
+ {
+ .uuid = (ble_uuid_t *) &alertLevelUuid,
+ .access_cb = AlertLevelCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+ .val_handle = &alertLevelHandle
+ },
+ {
+ 0
+ }
+ },
+ serviceDefinition{
+ {
+ /* Device Information Service */
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = (ble_uuid_t *) &immediateAlertServiceUuid,
+ .characteristics = characteristicDefinition
+ },
+ {
+ 0
+ },
+ }{
+
+}
+
+void ImmediateAlertService::Init() {
+ int res = 0;
+ res = ble_gatts_count_cfg(serviceDefinition);
+ ASSERT(res == 0);
+
+ res = ble_gatts_add_svcs(serviceDefinition);
+ ASSERT(res == 0);
+}
+
+int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt *context) {
+ if(attributeHandle == alertLevelHandle) {
+ if(context->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ auto alertLevel = static_cast<Levels>(context->om->om_data[0]);
+ auto* alertString = ToString(alertLevel);
+ notificationManager.Push(Pinetime::Controllers::NotificationManager::Categories::SimpleAlert, alertString, strlen(alertString));
+ systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
+ }
+ }
+
+ return 0;
+} \ No newline at end of file