2020-04-19 19:26:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-10-02 19:16:48 +00:00
|
|
|
|
2020-11-15 14:05:51 +00:00
|
|
|
#define min // workaround: nimble's min/max macros conflict with libstdc++
|
|
|
|
#define max
|
|
|
|
#include <host/ble_gap.h>
|
|
|
|
#undef max
|
|
|
|
#undef min
|
2020-04-25 11:09:47 +00:00
|
|
|
#include "AlertNotificationClient.h"
|
2020-11-15 14:05:51 +00:00
|
|
|
#include "AlertNotificationService.h"
|
|
|
|
#include "BatteryInformationService.h"
|
2020-04-23 18:57:53 +00:00
|
|
|
#include "CurrentTimeClient.h"
|
2020-05-04 20:43:51 +00:00
|
|
|
#include "CurrentTimeService.h"
|
2020-11-15 14:05:51 +00:00
|
|
|
#include "DeviceInformationService.h"
|
|
|
|
#include "DfuService.h"
|
2020-09-27 18:59:06 +00:00
|
|
|
#include "ImmediateAlertService.h"
|
2020-11-15 14:05:51 +00:00
|
|
|
#include "MusicService.h"
|
2021-01-20 20:34:09 +00:00
|
|
|
#include "NavigationService.h"
|
2020-10-29 15:06:01 +00:00
|
|
|
#include "ServiceDiscovery.h"
|
2021-01-17 15:34:14 +00:00
|
|
|
#include "HeartRateService.h"
|
2020-04-19 19:26:09 +00:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-05-11 16:50:37 +00:00
|
|
|
namespace Drivers {
|
|
|
|
class SpiNorFlash;
|
|
|
|
}
|
2020-11-15 14:05:51 +00:00
|
|
|
|
|
|
|
namespace System {
|
|
|
|
class SystemTask;
|
|
|
|
}
|
|
|
|
|
2020-04-19 19:26:09 +00:00
|
|
|
namespace Controllers {
|
2020-11-15 14:05:51 +00:00
|
|
|
class Ble;
|
2020-04-22 18:19:36 +00:00
|
|
|
class DateTime;
|
2020-11-15 14:05:51 +00:00
|
|
|
class NotificationManager;
|
2020-07-20 20:28:21 +00:00
|
|
|
|
2020-04-19 19:26:09 +00:00
|
|
|
class NimbleController {
|
2020-04-25 13:52:00 +00:00
|
|
|
|
2020-04-19 19:26:09 +00:00
|
|
|
public:
|
2020-05-11 16:50:37 +00:00
|
|
|
NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController,
|
|
|
|
DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager,
|
2021-01-17 15:34:14 +00:00
|
|
|
Controllers::Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
|
|
|
Controllers::HeartRateController& heartRateController);
|
2020-04-19 19:26:09 +00:00
|
|
|
void Init();
|
|
|
|
void StartAdvertising();
|
|
|
|
int OnGAPEvent(ble_gap_event *event);
|
2020-04-23 18:57:53 +00:00
|
|
|
|
2020-04-25 11:09:47 +00:00
|
|
|
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error *pError, const ble_gatt_svc *pSvc);
|
2020-04-25 13:52:00 +00:00
|
|
|
int OnCTSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
|
|
|
const ble_gatt_chr *characteristic);
|
|
|
|
int OnANSCharacteristicDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error *error,
|
|
|
|
const ble_gatt_chr *characteristic);
|
|
|
|
int OnCurrentTimeReadResult(uint16_t connectionHandle, const ble_gatt_error *error, ble_gatt_attr *attribute);
|
|
|
|
int OnANSDescriptorDiscoveryEventCallback(uint16_t connectionHandle, const ble_gatt_error *error,
|
|
|
|
uint16_t characteristicValueHandle, const ble_gatt_dsc *descriptor);
|
2020-05-01 19:58:31 +00:00
|
|
|
|
|
|
|
void StartDiscovery();
|
2020-07-11 20:37:28 +00:00
|
|
|
|
|
|
|
Pinetime::Controllers::MusicService& music() {return musicService;};
|
2021-01-20 20:34:09 +00:00
|
|
|
Pinetime::Controllers::NavigationService& navigation() {return navService;};
|
2020-07-11 20:37:28 +00:00
|
|
|
|
2020-07-20 20:28:21 +00:00
|
|
|
uint16_t connHandle();
|
|
|
|
|
2020-04-19 19:26:09 +00:00
|
|
|
private:
|
2020-09-20 09:09:50 +00:00
|
|
|
static constexpr const char* deviceName = "InfiniTime";
|
2020-04-25 11:09:47 +00:00
|
|
|
Pinetime::System::SystemTask& systemTask;
|
2020-04-27 18:13:27 +00:00
|
|
|
Pinetime::Controllers::Ble& bleController;
|
2020-04-22 18:19:36 +00:00
|
|
|
DateTime& dateTimeController;
|
2020-04-25 11:09:47 +00:00
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
2020-05-11 16:50:37 +00:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
2020-05-02 12:16:57 +00:00
|
|
|
Pinetime::Controllers::DfuService dfuService;
|
2020-04-25 11:09:47 +00:00
|
|
|
|
2020-04-23 18:34:38 +00:00
|
|
|
DeviceInformationService deviceInformationService;
|
2020-04-23 18:57:53 +00:00
|
|
|
CurrentTimeClient currentTimeClient;
|
2020-04-28 17:39:26 +00:00
|
|
|
AlertNotificationService anService;
|
2020-04-25 11:09:47 +00:00
|
|
|
AlertNotificationClient alertNotificationClient;
|
2020-05-04 20:43:51 +00:00
|
|
|
CurrentTimeService currentTimeService;
|
2020-07-11 20:37:28 +00:00
|
|
|
MusicService musicService;
|
2021-01-20 20:34:09 +00:00
|
|
|
NavigationService navService;
|
2020-09-27 18:02:47 +00:00
|
|
|
BatteryInformationService batteryInformationService;
|
2020-09-27 18:59:06 +00:00
|
|
|
ImmediateAlertService immediateAlertService;
|
2021-01-17 15:34:14 +00:00
|
|
|
HeartRateService heartRateService;
|
2020-04-28 17:39:26 +00:00
|
|
|
|
2020-06-08 19:51:34 +00:00
|
|
|
uint8_t addrType; // 1 = Random, 0 = PUBLIC
|
2020-07-20 20:28:21 +00:00
|
|
|
uint16_t connectionHandle = 0;
|
2020-04-27 18:16:03 +00:00
|
|
|
|
|
|
|
ble_uuid128_t dfuServiceUuid {
|
|
|
|
.u { .type = BLE_UUID_TYPE_128},
|
|
|
|
.value = {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15,
|
|
|
|
0xDE, 0xEF, 0x12, 0x12, 0x30, 0x15, 0x00, 0x00}
|
|
|
|
};
|
2020-10-29 15:06:01 +00:00
|
|
|
|
|
|
|
ServiceDiscovery serviceDiscovery;
|
2020-04-19 19:26:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|