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