Merge branch 'develop' into recovery-firmware
# Conflicts: # src/CMakeLists.txt # src/displayapp/DisplayApp.h # src/systemtask/SystemTask.cpp # src/systemtask/SystemTask.h
This commit is contained in:
@@ -83,4 +83,4 @@ namespace Pinetime {
|
||||
bool isDescriptorFound = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ using namespace Pinetime::Controllers;
|
||||
|
||||
constexpr ble_uuid16_t AlertNotificationService::ansUuid;
|
||||
constexpr ble_uuid16_t AlertNotificationService::ansCharUuid;
|
||||
constexpr ble_uuid128_t AlertNotificationService::notificationEventUuid;
|
||||
|
||||
|
||||
int AlertNotificationCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
||||
@@ -33,6 +34,13 @@ AlertNotificationService::AlertNotificationService ( System::SystemTask& systemT
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_WRITE
|
||||
},
|
||||
{
|
||||
.uuid = (ble_uuid_t *) ¬ificationEventUuid,
|
||||
.access_cb = AlertNotificationCallback,
|
||||
.arg = this,
|
||||
.flags = BLE_GATT_CHR_F_NOTIFY,
|
||||
.val_handle = &eventHandle
|
||||
},
|
||||
{
|
||||
0
|
||||
}
|
||||
@@ -61,14 +69,65 @@ int AlertNotificationService::OnAlert(uint16_t conn_handle, uint16_t attr_handle
|
||||
const auto dbgPacketLen = OS_MBUF_PKTLEN(ctxt->om);
|
||||
size_t bufferSize = std::min(dbgPacketLen + stringTerminatorSize, maxBufferSize);
|
||||
auto messageSize = std::min(maxMessageSize, (bufferSize-headerSize));
|
||||
Categories category;
|
||||
|
||||
NotificationManager::Notification notif;
|
||||
os_mbuf_copydata(ctxt->om, headerSize, messageSize-1, notif.message.data());
|
||||
os_mbuf_copydata(ctxt->om, 0, 1, &category);
|
||||
notif.message[messageSize-1] = '\0';
|
||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
||||
notificationManager.Push(std::move(notif));
|
||||
|
||||
systemTask.PushMessage(Pinetime::System::SystemTask::Messages::OnNewNotification);
|
||||
// TODO convert all ANS categories to NotificationController categories
|
||||
switch(category) {
|
||||
case Categories::Call:
|
||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::IncomingCall;
|
||||
break;
|
||||
default:
|
||||
notif.category = Pinetime::Controllers::NotificationManager::Categories::SimpleAlert;
|
||||
break;
|
||||
}
|
||||
|
||||
auto event = Pinetime::System::SystemTask::Messages::OnNewNotification;
|
||||
notificationManager.Push(std::move(notif));
|
||||
systemTask.PushMessage(event);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void AlertNotificationService::AcceptIncomingCall() {
|
||||
auto response = IncomingCallResponses::Answer;
|
||||
auto *om = ble_hs_mbuf_from_flat(&response, 1);
|
||||
|
||||
uint16_t connectionHandle = systemTask.nimble().connHandle();
|
||||
|
||||
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
|
||||
}
|
||||
|
||||
void AlertNotificationService::RejectIncomingCall() {
|
||||
auto response = IncomingCallResponses::Reject;
|
||||
auto *om = ble_hs_mbuf_from_flat(&response, 1);
|
||||
|
||||
uint16_t connectionHandle = systemTask.nimble().connHandle();
|
||||
|
||||
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
|
||||
}
|
||||
|
||||
void AlertNotificationService::MuteIncomingCall() {
|
||||
auto response = IncomingCallResponses::Mute;
|
||||
auto *om = ble_hs_mbuf_from_flat(&response, 1);
|
||||
|
||||
uint16_t connectionHandle = systemTask.nimble().connHandle();
|
||||
|
||||
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
|
||||
}
|
@@ -7,6 +7,9 @@
|
||||
#undef max
|
||||
#undef min
|
||||
|
||||
//00020001-78fc-48fe-8e23-433b3a1942d0
|
||||
#define NOTIFICATION_EVENT_SERVICE_UUID_BASE {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x01, 0x00, 0x02, 0x00}
|
||||
|
||||
namespace Pinetime {
|
||||
|
||||
namespace System {
|
||||
@@ -24,8 +27,31 @@ namespace Pinetime {
|
||||
int OnAlert(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt);
|
||||
|
||||
void AcceptIncomingCall();
|
||||
void RejectIncomingCall();
|
||||
void MuteIncomingCall();
|
||||
|
||||
enum class IncomingCallResponses : uint8_t {
|
||||
Reject = 0x00,
|
||||
Answer = 0x01,
|
||||
Mute = 0x02
|
||||
};
|
||||
|
||||
private:
|
||||
enum class Categories : uint8_t {
|
||||
SimpleAlert = 0x00,
|
||||
Email = 0x01,
|
||||
News = 0x02,
|
||||
Call = 0x03,
|
||||
MissedCall = 0x04,
|
||||
MmsSms = 0x05,
|
||||
VoiceMail = 0x06,
|
||||
Schedule = 0x07,
|
||||
HighPrioritizedAlert = 0x08,
|
||||
InstantMessage = 0x09,
|
||||
All = 0xff
|
||||
};
|
||||
|
||||
static constexpr uint16_t ansId {0x1811};
|
||||
static constexpr uint16_t ansCharId {0x2a46};
|
||||
|
||||
@@ -39,11 +65,18 @@ namespace Pinetime {
|
||||
.value = ansCharId
|
||||
};
|
||||
|
||||
struct ble_gatt_chr_def characteristicDefinition[2];
|
||||
static constexpr ble_uuid128_t notificationEventUuid {
|
||||
.u { .type = BLE_UUID_TYPE_128 },
|
||||
.value = NOTIFICATION_EVENT_SERVICE_UUID_BASE
|
||||
};
|
||||
|
||||
struct ble_gatt_chr_def characteristicDefinition[3];
|
||||
struct ble_gatt_svc_def serviceDefinition[2];
|
||||
|
||||
Pinetime::System::SystemTask &systemTask;
|
||||
NotificationManager ¬ificationManager;
|
||||
|
||||
uint16_t eventHandle;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#include <nrf_log.h>
|
||||
#include "BatteryInformationService.h"
|
||||
#include "components/battery/BatteryController.h"
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "CurrentTimeClient.h"
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "CurrentTimeService.h"
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
|
@@ -57,9 +57,7 @@ void HeartRateService::Init() {
|
||||
int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle,
|
||||
ble_gatt_access_ctxt *context) {
|
||||
if(attributeHandle == heartRateMeasurementHandle) {
|
||||
NRF_LOG_INFO("BATTERY : handle = %d", heartRateMeasurementHandle);
|
||||
static uint8_t batteryValue = heartRateController.HeartRate();
|
||||
|
||||
NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle);
|
||||
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
|
||||
|
||||
int res = os_mbuf_append(context->om, buffer, 2);
|
||||
|
@@ -38,8 +38,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
|
||||
navService{systemTask},
|
||||
batteryInformationService{batteryController},
|
||||
immediateAlertService{systemTask, notificationManager},
|
||||
serviceDiscovery({¤tTimeClient, &alertNotificationClient}),
|
||||
heartRateService{systemTask, heartRateController} {
|
||||
heartRateService{systemTask, heartRateController},
|
||||
serviceDiscovery({¤tTimeClient, &alertNotificationClient}) {
|
||||
}
|
||||
|
||||
int GAPEventCallback(struct ble_gap_event *event, void *arg) {
|
||||
|
@@ -58,6 +58,7 @@ namespace Pinetime {
|
||||
|
||||
Pinetime::Controllers::MusicService& music() {return musicService;};
|
||||
Pinetime::Controllers::NavigationService& navigation() {return navService;};
|
||||
Pinetime::Controllers::AlertNotificationService& alertService() {return anService;};
|
||||
|
||||
uint16_t connHandle();
|
||||
|
||||
|
@@ -71,6 +71,14 @@ bool NotificationManager::AreNewNotificationsAvailable() {
|
||||
return newNotification;
|
||||
}
|
||||
|
||||
bool NotificationManager::IsVibrationEnabled() {
|
||||
return vibrationEnabled;
|
||||
}
|
||||
|
||||
void NotificationManager::ToggleVibrations() {
|
||||
vibrationEnabled = !vibrationEnabled;
|
||||
}
|
||||
|
||||
bool NotificationManager::ClearNewNotificationFlag() {
|
||||
return newNotification.exchange(false);
|
||||
}
|
||||
|
@@ -28,6 +28,8 @@ namespace Pinetime {
|
||||
Notification GetPrevious(Notification::Id id);
|
||||
bool ClearNewNotificationFlag();
|
||||
bool AreNewNotificationsAvailable();
|
||||
bool IsVibrationEnabled();
|
||||
void ToggleVibrations();
|
||||
|
||||
static constexpr size_t MaximumMessageSize() { return MessageSize; };
|
||||
size_t NbNotifications() const;
|
||||
@@ -40,6 +42,7 @@ namespace Pinetime {
|
||||
uint8_t writeIndex = 0;
|
||||
bool empty = true;
|
||||
std::atomic<bool> newNotification{false};
|
||||
bool vibrationEnabled = true;
|
||||
};
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ using namespace Pinetime::Controllers;
|
||||
namespace {
|
||||
int Compare(int* d1, int* d2, size_t count) {
|
||||
int e = 0;
|
||||
for(int i = 0; i < count; i++) {
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
auto d = d1[i] - d2[i];
|
||||
e += d * d;
|
||||
}
|
||||
|
25
src/components/motor/MotorController.cpp
Normal file
25
src/components/motor/MotorController.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "MotorController.h"
|
||||
#include <hal/nrf_gpio.h>
|
||||
#include "systemtask/SystemTask.h"
|
||||
#include "app_timer.h"
|
||||
|
||||
APP_TIMER_DEF(vibTimer);
|
||||
|
||||
using namespace Pinetime::Controllers;
|
||||
|
||||
void MotorController::Init() {
|
||||
nrf_gpio_cfg_output(pinMotor);
|
||||
nrf_gpio_pin_set(pinMotor);
|
||||
app_timer_init();
|
||||
app_timer_create(&vibTimer, APP_TIMER_MODE_SINGLE_SHOT, vibrate);
|
||||
}
|
||||
|
||||
void MotorController::SetDuration(uint8_t motorDuration) {
|
||||
nrf_gpio_pin_clear(pinMotor);
|
||||
/* Start timer for motorDuration miliseconds and timer triggers vibrate() when it finishes*/
|
||||
app_timer_start(vibTimer, APP_TIMER_TICKS(motorDuration), NULL);
|
||||
}
|
||||
|
||||
void MotorController::vibrate(void * p_context) {
|
||||
nrf_gpio_pin_set(pinMotor);
|
||||
}
|
19
src/components/motor/MotorController.h
Normal file
19
src/components/motor/MotorController.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "app_timer.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Controllers {
|
||||
static constexpr uint8_t pinMotor = 16;
|
||||
|
||||
class MotorController {
|
||||
public:
|
||||
void Init();
|
||||
void SetDuration(uint8_t motorDuration);
|
||||
|
||||
private:
|
||||
static void vibrate(void * p_context);
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user