2020-04-25 07:09:47 -04:00
|
|
|
#pragma once
|
2020-04-25 09:52:00 -04:00
|
|
|
|
2020-04-25 07:09:47 -04:00
|
|
|
#include <cstdint>
|
2020-11-15 09:05:51 -05:00
|
|
|
#include <functional>
|
|
|
|
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
|
|
|
#define max
|
2020-04-25 07:09:47 -04:00
|
|
|
#include <host/ble_gap.h>
|
2020-11-15 09:05:51 -05:00
|
|
|
#undef max
|
|
|
|
#undef min
|
2020-10-29 11:06:01 -04:00
|
|
|
#include "BleClient.h"
|
2020-04-25 07:09:47 -04:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-11-15 09:05:51 -05:00
|
|
|
|
|
|
|
namespace System {
|
|
|
|
class SystemTask;
|
|
|
|
}
|
|
|
|
|
2020-04-25 07:09:47 -04:00
|
|
|
namespace Controllers {
|
2020-11-15 09:05:51 -05:00
|
|
|
class NotificationManager;
|
|
|
|
|
2020-10-29 11:06:01 -04:00
|
|
|
class AlertNotificationClient : public BleClient {
|
2021-04-24 05:00:45 -04:00
|
|
|
public:
|
2021-04-18 13:28:14 -04:00
|
|
|
explicit AlertNotificationClient(Pinetime::System::SystemTask& systemTask,
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager);
|
2020-04-25 07:09:47 -04:00
|
|
|
|
2021-04-18 13:28:14 -04: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);
|
|
|
|
void Reset();
|
|
|
|
void Discover(uint16_t connectionHandle, std::function<void(uint16_t)> lambda) override;
|
2020-04-25 09:52:00 -04:00
|
|
|
|
2021-04-24 05:00:45 -04:00
|
|
|
private:
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr uint16_t ansServiceId {0x1811};
|
|
|
|
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 07:09:47 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr ble_uuid16_t ansServiceUuid {.u {.type = BLE_UUID_TYPE_16}, .value = ansServiceId};
|
|
|
|
static constexpr ble_uuid16_t supportedNewAlertCategoryUuid {.u {.type = BLE_UUID_TYPE_16}, .value = supportedNewAlertCategoryId};
|
|
|
|
static constexpr ble_uuid16_t supportedUnreadAlertCategoryUuid {.u {.type = BLE_UUID_TYPE_16},
|
|
|
|
.value = supportedUnreadAlertCategoryId};
|
|
|
|
static constexpr ble_uuid16_t newAlertUuid {.u {.type = BLE_UUID_TYPE_16}, .value = newAlertId};
|
|
|
|
static constexpr ble_uuid16_t unreadAlertStatusUuid {.u {.type = BLE_UUID_TYPE_16}, .value = unreadAlertStatusId};
|
|
|
|
static constexpr ble_uuid16_t controlPointUuid {.u {.type = BLE_UUID_TYPE_16}, .value = controlPointId};
|
2020-04-25 07:09:47 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
uint16_t ansStartHandle = 0;
|
|
|
|
uint16_t ansEndHandle = 0;
|
|
|
|
uint16_t supportedNewAlertCategoryHandle = 0;
|
|
|
|
uint16_t supportedUnreadAlertCategoryHandle = 0;
|
|
|
|
uint16_t newAlertHandle = 0;
|
|
|
|
uint16_t newAlertDescriptorHandle = 0;
|
|
|
|
uint16_t newAlertDefHandle = 0;
|
|
|
|
uint16_t unreadAlertStatusHandle = 0;
|
|
|
|
uint16_t controlPointHandle = 0;
|
|
|
|
bool isDiscovered = false;
|
|
|
|
Pinetime::System::SystemTask& systemTask;
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
|
|
|
std::function<void(uint16_t)> onServiceDiscovered;
|
|
|
|
bool isCharacteristicDiscovered = false;
|
|
|
|
bool isDescriptorFound = false;
|
2020-04-25 07:09:47 -04:00
|
|
|
};
|
|
|
|
}
|
2020-10-27 14:51:06 -04:00
|
|
|
}
|