diff --git a/CMakeLists.txt b/CMakeLists.txt index aa848ce..e0776c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,8 @@ target_sources(infinisim PUBLIC sim/components/battery/BatteryController.cpp sim/components/ble/MusicService.h sim/components/ble/MusicService.cpp + sim/components/ble/ImmediateAlertClient.h + sim/components/ble/ImmediateAlertClient.cpp sim/components/ble/NimbleController.h sim/components/ble/NimbleController.cpp sim/components/brightness/BrightnessController.h diff --git a/sim/components/ble/ImmediateAlertClient.cpp b/sim/components/ble/ImmediateAlertClient.cpp new file mode 100644 index 0000000..e49fb60 --- /dev/null +++ b/sim/components/ble/ImmediateAlertClient.cpp @@ -0,0 +1,26 @@ +#include "components/ble/ImmediateAlertClient.h" +#include +#include +#include "systemtask/SystemTask.h" + +using namespace Pinetime::Controllers; + +constexpr ble_uuid16_t ImmediateAlertClient::immediateAlertClientUuid; +constexpr ble_uuid16_t ImmediateAlertClient::alertLevelCharacteristicUuid; + +ImmediateAlertClient::ImmediateAlertClient(Pinetime::System::SystemTask& systemTask) + : systemTask {systemTask} { +} + +void ImmediateAlertClient::Init() { +} + +void ImmediateAlertClient::Discover(uint16_t connectionHandle, std::function onServiceDiscovered) { + NRF_LOG_INFO("[IAS] Starting discovery"); + this->onServiceDiscovered = onServiceDiscovered; + // ble_gattc_disc_svc_by_uuid(connectionHandle, &immediateAlertClientUuid.u, OnDiscoveryEventCallback, this); +} + +bool ImmediateAlertClient::SendImmediateAlert(ImmediateAlertClient::Levels level) { + return false; +} diff --git a/sim/components/ble/ImmediateAlertClient.h b/sim/components/ble/ImmediateAlertClient.h new file mode 100644 index 0000000..bacaf06 --- /dev/null +++ b/sim/components/ble/ImmediateAlertClient.h @@ -0,0 +1,50 @@ +#pragma once +#define min // workaround: nimble's min/max macros conflict with libstdc++ +#define max +#include +#undef max +#undef min +#include +#include "components/ble/BleClient.h" + +namespace Pinetime { + namespace System { + class SystemTask; + } + + namespace Controllers { + class NotificationManager; + + class ImmediateAlertClient : public BleClient { + public: + enum class Levels : uint8_t { NoAlert = 0, MildAlert = 1, HighAlert = 2 }; + enum class State { + NoConnection, + NoIAS, + Connected, + }; + + ImmediateAlertClient(Pinetime::System::SystemTask& systemTask); + void Init(); + + bool SendImmediateAlert(Levels level); + + State GetState() const { + return State::NoConnection; + } + + void Discover(uint16_t connectionHandle, std::function lambda) override; + + private: + Pinetime::System::SystemTask& systemTask; + + static constexpr uint16_t immediateAlertClientId {0x1802}; + static constexpr uint16_t alertLevelId {0x2A06}; + + static constexpr ble_uuid16_t immediateAlertClientUuid {.u {.type = BLE_UUID_TYPE_16}, .value = immediateAlertClientId}; + static constexpr ble_uuid16_t alertLevelCharacteristicUuid {.u {.type = BLE_UUID_TYPE_16}, .value = alertLevelId}; + + std::function onServiceDiscovered; + }; + } +} diff --git a/sim/components/ble/NimbleController.cpp b/sim/components/ble/NimbleController.cpp index fda4155..a015e38 100644 --- a/sim/components/ble/NimbleController.cpp +++ b/sim/components/ble/NimbleController.cpp @@ -45,6 +45,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask, // currentTimeService {dateTimeController}, musicService {systemTask}, weatherService {dateTimeController}, + iaClient {systemTask}, // batteryInformationService {batteryController}, // immediateAlertService {systemTask, notificationManager}, // heartRateService {systemTask, heartRateController}, @@ -91,6 +92,7 @@ void NimbleController::Init() { musicService.Init(); weatherService.Init(); navService.Init(); + iaClient.Init(); // anService.Init(); // dfuService.Init(); // batteryInformationService.Init(); diff --git a/sim/components/ble/NimbleController.h b/sim/components/ble/NimbleController.h index 8566d1b..a0b7c1a 100644 --- a/sim/components/ble/NimbleController.h +++ b/sim/components/ble/NimbleController.h @@ -16,6 +16,7 @@ //#include "components/ble/DfuService.h" //#include "components/ble/HeartRateService.h" //#include "components/ble/ImmediateAlertService.h" +#include "components/ble/ImmediateAlertClient.h" #include "components/ble/MusicService.h" #include "components/ble/NavigationService.h" //#include "components/ble/ServiceDiscovery.h" @@ -81,6 +82,9 @@ namespace Pinetime { Pinetime::Controllers::SimpleWeatherService& weather() { return weatherService; }; + Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient() { + return iaClient; + }; uint16_t connHandle(); void NotifyBatteryLevel(uint8_t level); @@ -115,6 +119,7 @@ namespace Pinetime { NavigationService navService; // BatteryInformationService batteryInformationService; // ImmediateAlertService immediateAlertService; + ImmediateAlertClient iaClient; // HeartRateService heartRateService; MotionService motionService; // FSService fsService;