2020-04-19 15:26:09 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
2020-10-02 15:16:48 -04:00
|
|
|
|
2020-11-15 09:05:51 -05: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 07:09:47 -04:00
|
|
|
#include "AlertNotificationClient.h"
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "AlertNotificationService.h"
|
|
|
|
#include "BatteryInformationService.h"
|
2020-04-23 14:57:53 -04:00
|
|
|
#include "CurrentTimeClient.h"
|
2020-05-04 16:43:51 -04:00
|
|
|
#include "CurrentTimeService.h"
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "DeviceInformationService.h"
|
|
|
|
#include "DfuService.h"
|
2020-09-27 14:59:06 -04:00
|
|
|
#include "ImmediateAlertService.h"
|
2020-11-15 09:05:51 -05:00
|
|
|
#include "MusicService.h"
|
2021-01-20 15:34:09 -05:00
|
|
|
#include "NavigationService.h"
|
2020-10-29 11:06:01 -04:00
|
|
|
#include "ServiceDiscovery.h"
|
2021-01-17 10:34:14 -05:00
|
|
|
#include "HeartRateService.h"
|
2020-04-19 15:26:09 -04:00
|
|
|
|
|
|
|
namespace Pinetime {
|
2020-05-11 12:50:37 -04:00
|
|
|
namespace Drivers {
|
|
|
|
class SpiNorFlash;
|
|
|
|
}
|
2020-11-15 09:05:51 -05:00
|
|
|
|
|
|
|
namespace System {
|
|
|
|
class SystemTask;
|
|
|
|
}
|
|
|
|
|
2020-04-19 15:26:09 -04:00
|
|
|
namespace Controllers {
|
2020-11-15 09:05:51 -05:00
|
|
|
class Ble;
|
2020-04-22 14:19:36 -04:00
|
|
|
class DateTime;
|
2020-11-15 09:05:51 -05:00
|
|
|
class NotificationManager;
|
2020-07-20 16:28:21 -04:00
|
|
|
|
2020-04-19 15:26:09 -04:00
|
|
|
class NimbleController {
|
2020-04-25 09:52:00 -04:00
|
|
|
|
2020-04-19 15:26:09 -04:00
|
|
|
public:
|
2020-05-11 12:50:37 -04:00
|
|
|
NimbleController(Pinetime::System::SystemTask& systemTask, Pinetime::Controllers::Ble& bleController,
|
|
|
|
DateTime& dateTimeController, Pinetime::Controllers::NotificationManager& notificationManager,
|
2021-01-17 10:34:14 -05:00
|
|
|
Controllers::Battery& batteryController, Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
|
|
|
Controllers::HeartRateController& heartRateController);
|
2020-04-19 15:26:09 -04:00
|
|
|
void Init();
|
|
|
|
void StartAdvertising();
|
|
|
|
int OnGAPEvent(ble_gap_event *event);
|
2020-04-23 14:57:53 -04:00
|
|
|
|
2020-04-25 07:09:47 -04:00
|
|
|
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error *pError, const ble_gatt_svc *pSvc);
|
2020-04-25 09:52:00 -04: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 15:58:31 -04:00
|
|
|
|
|
|
|
void StartDiscovery();
|
2020-07-11 16:37:28 -04:00
|
|
|
|
|
|
|
Pinetime::Controllers::MusicService& music() {return musicService;};
|
2021-01-20 15:34:09 -05:00
|
|
|
Pinetime::Controllers::NavigationService& navigation() {return navService;};
|
2020-07-11 16:37:28 -04:00
|
|
|
|
2020-07-20 16:28:21 -04:00
|
|
|
uint16_t connHandle();
|
|
|
|
|
2020-04-19 15:26:09 -04:00
|
|
|
private:
|
2020-09-20 05:09:50 -04:00
|
|
|
static constexpr const char* deviceName = "InfiniTime";
|
2020-04-25 07:09:47 -04:00
|
|
|
Pinetime::System::SystemTask& systemTask;
|
2020-04-27 14:13:27 -04:00
|
|
|
Pinetime::Controllers::Ble& bleController;
|
2020-04-22 14:19:36 -04:00
|
|
|
DateTime& dateTimeController;
|
2020-04-25 07:09:47 -04:00
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
2020-05-11 12:50:37 -04:00
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
2020-05-02 08:16:57 -04:00
|
|
|
Pinetime::Controllers::DfuService dfuService;
|
2020-04-25 07:09:47 -04:00
|
|
|
|
2020-04-23 14:34:38 -04:00
|
|
|
DeviceInformationService deviceInformationService;
|
2020-04-23 14:57:53 -04:00
|
|
|
CurrentTimeClient currentTimeClient;
|
2020-04-28 13:39:26 -04:00
|
|
|
AlertNotificationService anService;
|
2020-04-25 07:09:47 -04:00
|
|
|
AlertNotificationClient alertNotificationClient;
|
2020-05-04 16:43:51 -04:00
|
|
|
CurrentTimeService currentTimeService;
|
2020-07-11 16:37:28 -04:00
|
|
|
MusicService musicService;
|
2021-01-20 15:34:09 -05:00
|
|
|
NavigationService navService;
|
2020-09-27 14:02:47 -04:00
|
|
|
BatteryInformationService batteryInformationService;
|
2020-09-27 14:59:06 -04:00
|
|
|
ImmediateAlertService immediateAlertService;
|
2021-01-17 10:34:14 -05:00
|
|
|
HeartRateService heartRateService;
|
2020-04-28 13:39:26 -04:00
|
|
|
|
2020-06-08 15:51:34 -04:00
|
|
|
uint8_t addrType; // 1 = Random, 0 = PUBLIC
|
2020-07-20 16:28:21 -04:00
|
|
|
uint16_t connectionHandle = 0;
|
2020-04-27 14:16:03 -04: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 11:06:01 -04:00
|
|
|
|
|
|
|
ServiceDiscovery serviceDiscovery;
|
2020-04-19 15:26:09 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|