2020-04-25 11:09:47 +00:00
|
|
|
#pragma once
|
2020-04-25 13:52:00 +00:00
|
|
|
|
2020-04-25 11:09:47 +00:00
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
|
|
|
#include <host/ble_gap.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
int NewAlertSubcribeCallback(uint16_t conn_handle,
|
2020-04-25 13:52:00 +00:00
|
|
|
const struct ble_gatt_error *error,
|
|
|
|
struct ble_gatt_attr *attr,
|
|
|
|
void *arg);
|
2020-04-25 11:09:47 +00:00
|
|
|
|
|
|
|
class AlertNotificationClient {
|
|
|
|
public:
|
2020-04-25 13:52:00 +00:00
|
|
|
explicit AlertNotificationClient(Pinetime::System::SystemTask &systemTask,
|
|
|
|
Pinetime::Controllers::NotificationManager ¬ificationManager);
|
2020-04-25 11:09:47 +00:00
|
|
|
|
|
|
|
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error, const ble_gatt_svc *service);
|
|
|
|
int OnCharacteristicsDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
|
|
|
const ble_gatt_chr *characteristic);
|
|
|
|
int OnNewAlertSubcribe(uint16_t connectionHandle, const ble_gatt_error *error, ble_gatt_attr *attribute);
|
|
|
|
int OnDescriptorDiscoveryEventCallback(uint16_t connectionHandle, const ble_gatt_error *error,
|
|
|
|
uint16_t characteristicValueHandle, const ble_gatt_dsc *descriptor);
|
|
|
|
void OnNotification(ble_gap_event *event);
|
2020-04-25 13:52:00 +00:00
|
|
|
bool IsDiscovered() const;
|
|
|
|
uint16_t StartHandle() const;
|
|
|
|
uint16_t EndHandle() const;
|
2020-10-28 17:23:09 +00:00
|
|
|
void Reset();
|
2020-04-25 13:52:00 +00:00
|
|
|
|
|
|
|
static constexpr const ble_uuid16_t &Uuid() { return ansServiceUuid; }
|
|
|
|
|
|
|
|
uint16_t NewAlerthandle() const;
|
2020-04-25 11:09:47 +00:00
|
|
|
private:
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr uint16_t ansServiceId{0x1811};
|
2020-04-25 11:09:47 +00:00
|
|
|
static constexpr uint16_t supportedNewAlertCategoryId = 0x2a47;
|
|
|
|
static constexpr uint16_t supportedUnreadAlertCategoryId = 0x2a48;
|
|
|
|
static constexpr uint16_t newAlertId = 0x2a46;
|
|
|
|
static constexpr uint16_t unreadAlertStatusId = 0x2a45;
|
|
|
|
static constexpr uint16_t controlPointId = 0x2a44;
|
|
|
|
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t ansServiceUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = ansServiceId
|
|
|
|
};
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t supportedNewAlertCategoryUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = supportedNewAlertCategoryId
|
|
|
|
};
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t supportedUnreadAlertCategoryUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = supportedUnreadAlertCategoryId
|
|
|
|
};
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t newAlertUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = newAlertId
|
|
|
|
};
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t unreadAlertStatusUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = unreadAlertStatusId
|
|
|
|
};
|
2020-04-25 13:52:00 +00:00
|
|
|
static constexpr ble_uuid16_t controlPointUuid{
|
|
|
|
.u {.type = BLE_UUID_TYPE_16},
|
2020-04-25 11:09:47 +00:00
|
|
|
.value = controlPointId
|
|
|
|
};
|
|
|
|
|
2020-10-28 17:23:09 +00:00
|
|
|
uint16_t ansStartHandle = 0;
|
|
|
|
uint16_t ansEndHandle = 0;
|
|
|
|
uint16_t supportedNewAlertCategoryHandle = 0;
|
|
|
|
uint16_t supportedUnreadAlertCategoryHandle = 0;
|
|
|
|
uint16_t newAlertHandle = 0;
|
2020-04-25 11:09:47 +00:00
|
|
|
uint16_t newAlertDescriptorHandle = 0;
|
2020-10-28 17:23:09 +00:00
|
|
|
uint16_t newAlertDefHandle = 0;
|
|
|
|
uint16_t unreadAlertStatusHandle = 0;
|
|
|
|
uint16_t controlPointHandle = 0;
|
2020-04-25 13:52:00 +00:00
|
|
|
bool isDiscovered = false;
|
|
|
|
Pinetime::System::SystemTask &systemTask;
|
|
|
|
Pinetime::Controllers::NotificationManager ¬ificationManager;
|
2020-04-25 11:09:47 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|