Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImmediateAlertClient to support FindMyPhone functionality. #165

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions sim/components/ble/ImmediateAlertClient.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "components/ble/ImmediateAlertClient.h"
#include <cstring>
#include <nrf_log.h>
#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<void(uint16_t)> 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;
}
50 changes: 50 additions & 0 deletions sim/components/ble/ImmediateAlertClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#pragma once
#define min // workaround: nimble's min/max macros conflict with libstdc++
#define max
#include <host/ble_gap.h>
#undef max
#undef min
#include <cstdint>
#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<void(uint16_t)> 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<void(uint16_t)> onServiceDiscovered;
};
}
}
2 changes: 2 additions & 0 deletions sim/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -91,6 +92,7 @@ void NimbleController::Init() {
musicService.Init();
weatherService.Init();
navService.Init();
iaClient.Init();
// anService.Init();
// dfuService.Init();
// batteryInformationService.Init();
Expand Down
5 changes: 5 additions & 0 deletions sim/components/ble/NimbleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -115,6 +119,7 @@ namespace Pinetime {
NavigationService navService;
// BatteryInformationService batteryInformationService;
// ImmediateAlertService immediateAlertService;
ImmediateAlertClient iaClient;
// HeartRateService heartRateService;
MotionService motionService;
// FSService fsService;
Expand Down