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
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "components/ble/AlertNotificationClient.h"
|
|
|
|
#include "components/ble/AlertNotificationService.h"
|
|
|
|
#include "components/ble/BatteryInformationService.h"
|
|
|
|
#include "components/ble/CurrentTimeClient.h"
|
|
|
|
#include "components/ble/CurrentTimeService.h"
|
|
|
|
#include "components/ble/DeviceInformationService.h"
|
|
|
|
#include "components/ble/DfuService.h"
|
2021-12-08 06:10:54 +00:00
|
|
|
#include "components/ble/HeartRateService.h"
|
2021-10-13 20:08:35 +00:00
|
|
|
#include "components/ble/ImmediateAlertService.h"
|
|
|
|
#include "components/ble/MusicService.h"
|
|
|
|
#include "components/ble/NavigationService.h"
|
|
|
|
#include "components/ble/ServiceDiscovery.h"
|
|
|
|
#include "components/ble/MotionService.h"
|
2021-06-09 21:44:49 +00:00
|
|
|
#include "components/ble/weather/WeatherService.h"
|
2021-12-04 20:49:49 +00:00
|
|
|
#include "components/fs/FS.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
|
|
|
|
2021-04-24 09:00:45 +00:00
|
|
|
public:
|
2021-04-18 17:28:14 +00:00
|
|
|
NimbleController(Pinetime::System::SystemTask& systemTask,
|
|
|
|
Pinetime::Controllers::Ble& bleController,
|
|
|
|
DateTime& dateTimeController,
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager,
|
|
|
|
Controllers::Battery& batteryController,
|
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
|
2021-10-17 06:23:44 +00:00
|
|
|
Controllers::HeartRateController& heartRateController,
|
2021-12-04 20:49:49 +00:00
|
|
|
Controllers::MotionController& motionController,
|
|
|
|
Pinetime::Controllers::FS& fs);
|
2021-04-18 17:28:14 +00:00
|
|
|
void Init();
|
|
|
|
void StartAdvertising();
|
|
|
|
int OnGAPEvent(ble_gap_event* event);
|
|
|
|
|
|
|
|
int OnDiscoveryEvent(uint16_t i, const ble_gatt_error* pError, const ble_gatt_svc* pSvc);
|
|
|
|
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);
|
|
|
|
|
|
|
|
void StartDiscovery();
|
|
|
|
|
|
|
|
Pinetime::Controllers::MusicService& music() {
|
|
|
|
return musicService;
|
|
|
|
};
|
|
|
|
Pinetime::Controllers::NavigationService& navigation() {
|
|
|
|
return navService;
|
|
|
|
};
|
|
|
|
Pinetime::Controllers::AlertNotificationService& alertService() {
|
|
|
|
return anService;
|
|
|
|
};
|
2021-06-20 18:37:53 +00:00
|
|
|
Pinetime::Controllers::WeatherService& weather() {
|
|
|
|
return weatherService;
|
|
|
|
};
|
2021-04-18 17:28:14 +00:00
|
|
|
|
|
|
|
uint16_t connHandle();
|
2021-07-11 14:55:06 +00:00
|
|
|
void NotifyBatteryLevel(uint8_t level);
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-09-05 20:53:20 +00:00
|
|
|
void RestartFastAdv() {
|
|
|
|
fastAdvCount = 0;
|
|
|
|
}
|
|
|
|
|
2021-04-24 09:00:45 +00:00
|
|
|
private:
|
2021-12-08 06:10:54 +00:00
|
|
|
void PersistBond(struct ble_gap_conn_desc& desc);
|
2021-12-04 20:49:49 +00:00
|
|
|
void RestoreBond();
|
|
|
|
|
2021-04-18 17:28:14 +00:00
|
|
|
static constexpr const char* deviceName = "InfiniTime";
|
|
|
|
Pinetime::System::SystemTask& systemTask;
|
|
|
|
Pinetime::Controllers::Ble& bleController;
|
|
|
|
DateTime& dateTimeController;
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager;
|
|
|
|
Pinetime::Drivers::SpiNorFlash& spiNorFlash;
|
2021-12-08 06:10:54 +00:00
|
|
|
Pinetime::Controllers::FS& fs;
|
2021-04-18 17:28:14 +00:00
|
|
|
Pinetime::Controllers::DfuService dfuService;
|
|
|
|
|
|
|
|
DeviceInformationService deviceInformationService;
|
|
|
|
CurrentTimeClient currentTimeClient;
|
|
|
|
AlertNotificationService anService;
|
|
|
|
AlertNotificationClient alertNotificationClient;
|
|
|
|
CurrentTimeService currentTimeService;
|
|
|
|
MusicService musicService;
|
2021-06-09 21:44:49 +00:00
|
|
|
WeatherService weatherService;
|
2021-04-18 17:28:14 +00:00
|
|
|
NavigationService navService;
|
|
|
|
BatteryInformationService batteryInformationService;
|
|
|
|
ImmediateAlertService immediateAlertService;
|
|
|
|
HeartRateService heartRateService;
|
2021-10-17 06:23:44 +00:00
|
|
|
MotionService motionService;
|
2021-12-08 06:10:54 +00:00
|
|
|
ServiceDiscovery serviceDiscovery;
|
2021-04-18 17:28:14 +00:00
|
|
|
|
2021-12-08 06:10:54 +00:00
|
|
|
uint8_t addrType;
|
2021-07-11 14:55:06 +00:00
|
|
|
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
|
2021-09-05 20:53:20 +00:00
|
|
|
uint8_t fastAdvCount = 0;
|
2021-12-04 20:49:49 +00:00
|
|
|
uint8_t bondId[16] = {0};
|
2021-04-18 17:28:14 +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-04-19 19:26:09 +00:00
|
|
|
};
|
2021-08-29 20:50:04 +00:00
|
|
|
|
2021-12-04 20:49:49 +00:00
|
|
|
static NimbleController* nptr;
|
2020-04-19 19:26:09 +00:00
|
|
|
}
|
|
|
|
}
|