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
|
2021-10-13 16:08:35 -04: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 01:10:54 -05:00
|
|
|
#include "components/ble/HeartRateService.h"
|
2021-10-13 16:08:35 -04: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 17:44:49 -04:00
|
|
|
#include "components/ble/weather/WeatherService.h"
|
2021-12-04 15:49:49 -05:00
|
|
|
#include "components/fs/FS.h"
|
2021-10-16 21:09:26 -04:00
|
|
|
#include "components/ble/FSService.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
|
|
|
|
2021-04-24 05:00:45 -04:00
|
|
|
public:
|
2021-04-18 13:28:14 -04: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 02:23:44 -04:00
|
|
|
Controllers::HeartRateController& heartRateController,
|
2021-12-04 15:49:49 -05:00
|
|
|
Controllers::MotionController& motionController,
|
|
|
|
Pinetime::Controllers::FS& fs);
|
2021-04-18 13:28:14 -04: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 14:37:53 -04:00
|
|
|
Pinetime::Controllers::WeatherService& weather() {
|
|
|
|
return weatherService;
|
|
|
|
};
|
2021-04-18 13:28:14 -04:00
|
|
|
|
|
|
|
uint16_t connHandle();
|
2021-07-11 10:55:06 -04:00
|
|
|
void NotifyBatteryLevel(uint8_t level);
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-09-05 16:53:20 -04:00
|
|
|
void RestartFastAdv() {
|
|
|
|
fastAdvCount = 0;
|
|
|
|
}
|
|
|
|
|
2021-04-24 05:00:45 -04:00
|
|
|
private:
|
2021-12-08 01:10:54 -05:00
|
|
|
void PersistBond(struct ble_gap_conn_desc& desc);
|
2021-12-04 15:49:49 -05:00
|
|
|
void RestoreBond();
|
|
|
|
|
2021-04-18 13:28:14 -04: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 01:10:54 -05:00
|
|
|
Pinetime::Controllers::FS& fs;
|
2021-04-18 13:28:14 -04:00
|
|
|
Pinetime::Controllers::DfuService dfuService;
|
|
|
|
|
|
|
|
DeviceInformationService deviceInformationService;
|
|
|
|
CurrentTimeClient currentTimeClient;
|
|
|
|
AlertNotificationService anService;
|
|
|
|
AlertNotificationClient alertNotificationClient;
|
|
|
|
CurrentTimeService currentTimeService;
|
|
|
|
MusicService musicService;
|
2021-06-09 17:44:49 -04:00
|
|
|
WeatherService weatherService;
|
2021-04-18 13:28:14 -04:00
|
|
|
NavigationService navService;
|
|
|
|
BatteryInformationService batteryInformationService;
|
|
|
|
ImmediateAlertService immediateAlertService;
|
|
|
|
HeartRateService heartRateService;
|
2021-10-17 02:23:44 -04:00
|
|
|
MotionService motionService;
|
2021-10-16 21:09:26 -04:00
|
|
|
FSService fsService;
|
2021-12-21 17:02:01 -05:00
|
|
|
ServiceDiscovery serviceDiscovery;
|
2021-04-18 13:28:14 -04:00
|
|
|
|
2021-12-08 01:10:54 -05:00
|
|
|
uint8_t addrType;
|
2021-07-11 10:55:06 -04:00
|
|
|
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
|
2021-09-05 16:53:20 -04:00
|
|
|
uint8_t fastAdvCount = 0;
|
2021-12-04 15:49:49 -05:00
|
|
|
uint8_t bondId[16] = {0};
|
2021-04-18 13:28:14 -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-04-19 15:26:09 -04:00
|
|
|
};
|
2021-08-29 16:50:04 -04:00
|
|
|
|
2021-12-04 15:49:49 -05:00
|
|
|
static NimbleController* nptr;
|
2020-04-19 15:26:09 -04:00
|
|
|
}
|
|
|
|
}
|