Skip to content

Commit ef22a1c

Browse files
committed
Add ImmediateAlertClient to support FindMyPhone functionality.
Signed-off-by: Vyacheslav Chigrin <vyacheslav.chigrin@izba.dev>
1 parent eedcaf4 commit ef22a1c

File tree

5 files changed

+85
-0
lines changed

5 files changed

+85
-0
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ target_sources(infinisim PUBLIC
131131
sim/components/battery/BatteryController.cpp
132132
sim/components/ble/MusicService.h
133133
sim/components/ble/MusicService.cpp
134+
sim/components/ble/ImmediateAlertClient.h
135+
sim/components/ble/ImmediateAlertClient.cpp
134136
sim/components/ble/NimbleController.h
135137
sim/components/ble/NimbleController.cpp
136138
sim/components/brightness/BrightnessController.h
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "components/ble/ImmediateAlertClient.h"
2+
#include <cstring>
3+
#include <nrf_log.h>
4+
#include "systemtask/SystemTask.h"
5+
6+
using namespace Pinetime::Controllers;
7+
8+
constexpr ble_uuid16_t ImmediateAlertClient::immediateAlertClientUuid;
9+
constexpr ble_uuid16_t ImmediateAlertClient::alertLevelCharacteristicUuid;
10+
11+
ImmediateAlertClient::ImmediateAlertClient(Pinetime::System::SystemTask& systemTask)
12+
: systemTask {systemTask} {
13+
}
14+
15+
void ImmediateAlertClient::Init() {
16+
}
17+
18+
void ImmediateAlertClient::Discover(uint16_t connectionHandle, std::function<void(uint16_t)> onServiceDiscovered) {
19+
NRF_LOG_INFO("[IAS] Starting discovery");
20+
this->onServiceDiscovered = onServiceDiscovered;
21+
// ble_gattc_disc_svc_by_uuid(connectionHandle, &immediateAlertClientUuid.u, OnDiscoveryEventCallback, this);
22+
}
23+
24+
bool ImmediateAlertClient::SendImmediateAlert(ImmediateAlertClient::Levels level) {
25+
return false;
26+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
#define min // workaround: nimble's min/max macros conflict with libstdc++
3+
#define max
4+
#include <host/ble_gap.h>
5+
#undef max
6+
#undef min
7+
#include <cstdint>
8+
#include "components/ble/BleClient.h"
9+
10+
namespace Pinetime {
11+
namespace System {
12+
class SystemTask;
13+
}
14+
15+
namespace Controllers {
16+
class NotificationManager;
17+
18+
class ImmediateAlertClient : public BleClient {
19+
public:
20+
enum class Levels : uint8_t { NoAlert = 0, MildAlert = 1, HighAlert = 2 };
21+
enum class State {
22+
NoConnection,
23+
NoIAS,
24+
Connected,
25+
};
26+
27+
ImmediateAlertClient(Pinetime::System::SystemTask& systemTask);
28+
void Init();
29+
30+
bool SendImmediateAlert(Levels level);
31+
32+
State GetState() const {
33+
return State::NoConnection;
34+
}
35+
36+
void Discover(uint16_t connectionHandle, std::function<void(uint16_t)> lambda) override;
37+
38+
private:
39+
Pinetime::System::SystemTask& systemTask;
40+
41+
static constexpr uint16_t immediateAlertClientId {0x1802};
42+
static constexpr uint16_t alertLevelId {0x2A06};
43+
44+
static constexpr ble_uuid16_t immediateAlertClientUuid {.u {.type = BLE_UUID_TYPE_16}, .value = immediateAlertClientId};
45+
static constexpr ble_uuid16_t alertLevelCharacteristicUuid {.u {.type = BLE_UUID_TYPE_16}, .value = alertLevelId};
46+
47+
std::function<void(uint16_t)> onServiceDiscovered;
48+
};
49+
}
50+
}

sim/components/ble/NimbleController.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
4545
// currentTimeService {dateTimeController},
4646
musicService {systemTask},
4747
weatherService {dateTimeController},
48+
iaClient {systemTask},
4849
// batteryInformationService {batteryController},
4950
// immediateAlertService {systemTask, notificationManager},
5051
// heartRateService {systemTask, heartRateController},
@@ -91,6 +92,7 @@ void NimbleController::Init() {
9192
musicService.Init();
9293
weatherService.Init();
9394
navService.Init();
95+
iaClient.Init();
9496
// anService.Init();
9597
// dfuService.Init();
9698
// batteryInformationService.Init();

sim/components/ble/NimbleController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//#include "components/ble/DfuService.h"
1717
//#include "components/ble/HeartRateService.h"
1818
//#include "components/ble/ImmediateAlertService.h"
19+
#include "components/ble/ImmediateAlertClient.h"
1920
#include "components/ble/MusicService.h"
2021
#include "components/ble/NavigationService.h"
2122
//#include "components/ble/ServiceDiscovery.h"
@@ -81,6 +82,9 @@ namespace Pinetime {
8182
Pinetime::Controllers::SimpleWeatherService& weather() {
8283
return weatherService;
8384
};
85+
Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient() {
86+
return iaClient;
87+
};
8488

8589
uint16_t connHandle();
8690
void NotifyBatteryLevel(uint8_t level);
@@ -115,6 +119,7 @@ namespace Pinetime {
115119
NavigationService navService;
116120
// BatteryInformationService batteryInformationService;
117121
// ImmediateAlertService immediateAlertService;
122+
ImmediateAlertClient iaClient;
118123
// HeartRateService heartRateService;
119124
MotionService motionService;
120125
// FSService fsService;

0 commit comments

Comments
 (0)