summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-11-11 09:08:20 (GMT)
committerJean-François Milants <jf@codingfield.com>2021-11-11 09:08:20 (GMT)
commitf6d0ec49e6f2669c64729b081eb3342f02151f4a (patch)
tree7e21c83726bd3e0d18ec4ebe871274b1dbe2eb38 /src/components
parentf41aaad6836ae348d1b5b084b4533b636f516b93 (diff)
parenta57fda6ba4a29866083a1254ffdf92939d00e182 (diff)
Merge branch 'develop'
# Conflicts: # doc/buildAndProgram.md
Diffstat (limited to 'src/components')
-rw-r--r--src/components/battery/BatteryController.cpp29
-rw-r--r--src/components/battery/BatteryController.h9
-rw-r--r--src/components/ble/AlertNotificationClient.cpp14
-rw-r--r--src/components/ble/AlertNotificationService.cpp11
-rw-r--r--src/components/ble/BatteryInformationService.cpp6
-rw-r--r--src/components/ble/CurrentTimeClient.cpp4
-rw-r--r--src/components/ble/CurrentTimeService.cpp4
-rw-r--r--src/components/ble/DeviceInformationService.cpp14
-rw-r--r--src/components/ble/DfuService.cpp26
-rw-r--r--src/components/ble/HeartRateService.cpp20
-rw-r--r--src/components/ble/HeartRateService.h7
-rw-r--r--src/components/ble/ImmediateAlertService.cpp6
-rw-r--r--src/components/ble/MotionService.cpp124
-rw-r--r--src/components/ble/MotionService.h39
-rw-r--r--src/components/ble/NavigationService.cpp77
-rw-r--r--src/components/ble/NavigationService.h17
-rw-r--r--src/components/ble/NimbleController.cpp18
-rw-r--r--src/components/ble/NimbleController.h5
-rw-r--r--src/components/datetime/DateTimeController.cpp44
-rw-r--r--src/components/datetime/DateTimeController.h16
-rw-r--r--src/components/fs/FS.h2
-rw-r--r--src/components/motion/MotionController.cpp11
-rw-r--r--src/components/motion/MotionController.h3
23 files changed, 337 insertions, 169 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 4ef20a2..e807f03 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -13,10 +13,20 @@ Battery::Battery() {
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
}
-void Battery::Update() {
+void Battery::ReadPowerState() {
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
+ if (isPowerPresent && !isCharging) {
+ isFull = true;
+ } else if (!isPowerPresent) {
+ isFull = false;
+ }
+}
+
+void Battery::MeasureVoltage() {
+ ReadPowerState();
+
if (isReading) {
return;
}
@@ -63,18 +73,23 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
- if (voltage > battery_max) {
- percentRemaining = 100;
+ uint8_t newPercent;
+ if (isFull) {
+ newPercent = 100;
} else if (voltage < battery_min) {
- percentRemaining = 0;
+ newPercent = 0;
} else {
- percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
+ newPercent = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), isCharging ? 99 : 100);
+ }
+
+ if ((isPowerPresent && newPercent > percentRemaining) || (!isPowerPresent && newPercent < percentRemaining) || firstMeasurement) {
+ firstMeasurement = false;
+ percentRemaining = newPercent;
+ systemTask->PushMessage(System::Messages::BatteryPercentageUpdated);
}
nrfx_saadc_uninit();
isReading = false;
-
- systemTask->PushMessage(System::Messages::BatteryMeasurementDone);
}
}
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 8af27ea..5a7394c 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -10,7 +10,8 @@ namespace Pinetime {
public:
Battery();
- void Update();
+ void ReadPowerState();
+ void MeasureVoltage();
void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const {
@@ -22,7 +23,9 @@ namespace Pinetime {
}
bool IsCharging() const {
- return isCharging;
+ // isCharging will go up and down when fully charged
+ // isFull makes sure this returns false while fully charged.
+ return isCharging && !isFull;
}
bool IsPowerPresent() const {
@@ -37,8 +40,10 @@ namespace Pinetime {
uint16_t voltage = 0;
uint8_t percentRemaining = 0;
+ bool isFull = false;
bool isCharging = false;
bool isPowerPresent = false;
+ bool firstMeasurement = true;
void SaadcInit();
diff --git a/src/components/ble/AlertNotificationClient.cpp b/src/components/ble/AlertNotificationClient.cpp
index c3d1d69..5e5c25c 100644
--- a/src/components/ble/AlertNotificationClient.cpp
+++ b/src/components/ble/AlertNotificationClient.cpp
@@ -55,7 +55,7 @@ bool AlertNotificationClient::OnDiscoveryEvent(uint16_t connectionHandle, const
return true;
}
- if (service != nullptr && ble_uuid_cmp(((ble_uuid_t*) &ansServiceUuid), &service->uuid.u) == 0) {
+ if (service != nullptr && ble_uuid_cmp(&ansServiceUuid.u, &service->uuid.u) == 0) {
NRF_LOG_INFO("ANS discovered : 0x%x - 0x%x", service->start_handle, service->end_handle);
ansStartHandle = service->start_handle;
ansEndHandle = service->end_handle;
@@ -80,21 +80,21 @@ int AlertNotificationClient::OnCharacteristicsDiscoveryEvent(uint16_t connection
} else
onServiceDiscovered(connectionHandle);
} else {
- if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &supportedNewAlertCategoryUuid), &characteristic->uuid.u) == 0) {
+ if (characteristic != nullptr && ble_uuid_cmp(&supportedNewAlertCategoryUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : supportedNewAlertCategoryUuid");
supportedNewAlertCategoryHandle = characteristic->val_handle;
- } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &supportedUnreadAlertCategoryUuid), &characteristic->uuid.u) == 0) {
+ } else if (characteristic != nullptr && ble_uuid_cmp(&supportedUnreadAlertCategoryUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : supportedUnreadAlertCategoryUuid");
supportedUnreadAlertCategoryHandle = characteristic->val_handle;
- } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &newAlertUuid), &characteristic->uuid.u) == 0) {
+ } else if (characteristic != nullptr && ble_uuid_cmp(&newAlertUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : newAlertUuid");
newAlertHandle = characteristic->val_handle;
newAlertDefHandle = characteristic->def_handle;
isCharacteristicDiscovered = true;
- } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &unreadAlertStatusUuid), &characteristic->uuid.u) == 0) {
+ } else if (characteristic != nullptr && ble_uuid_cmp(&unreadAlertStatusUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : unreadAlertStatusUuid");
unreadAlertStatusHandle = characteristic->val_handle;
- } else if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &controlPointUuid), &characteristic->uuid.u) == 0) {
+ } else if (characteristic != nullptr && ble_uuid_cmp(&controlPointUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("ANS Characteristic discovered : controlPointUuid");
controlPointHandle = characteristic->val_handle;
} else
@@ -119,7 +119,7 @@ int AlertNotificationClient::OnDescriptorDiscoveryEventCallback(uint16_t connect
uint16_t characteristicValueHandle,
const ble_gatt_dsc* descriptor) {
if (error->status == 0) {
- if (characteristicValueHandle == newAlertHandle && ble_uuid_cmp(((ble_uuid_t*) &newAlertUuid), &descriptor->uuid.u)) {
+ if (characteristicValueHandle == newAlertHandle && ble_uuid_cmp(&newAlertUuid.u, &descriptor->uuid.u)) {
if (newAlertDescriptorHandle == 0) {
NRF_LOG_INFO("ANS Descriptor discovered : %d", descriptor->handle);
newAlertDescriptorHandle = descriptor->handle;
diff --git a/src/components/ble/AlertNotificationService.cpp b/src/components/ble/AlertNotificationService.cpp
index d5fc7f6..56fc595 100644
--- a/src/components/ble/AlertNotificationService.cpp
+++ b/src/components/ble/AlertNotificationService.cpp
@@ -26,11 +26,8 @@ void AlertNotificationService::Init() {
}
AlertNotificationService::AlertNotificationService(System::SystemTask& systemTask, NotificationManager& notificationManager)
- : characteristicDefinition {{.uuid = (ble_uuid_t*) &ansCharUuid,
- .access_cb = AlertNotificationCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE},
- {.uuid = (ble_uuid_t*) &notificationEventUuid,
+ : characteristicDefinition {{.uuid = &ansCharUuid.u, .access_cb = AlertNotificationCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE},
+ {.uuid = &notificationEventUuid.u,
.access_cb = AlertNotificationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_NOTIFY,
@@ -39,7 +36,7 @@ AlertNotificationService::AlertNotificationService(System::SystemTask& systemTas
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &ansUuid,
+ .uuid = &ansUuid.u,
.characteristics = characteristicDefinition},
{0},
},
@@ -123,4 +120,4 @@ void AlertNotificationService::MuteIncomingCall() {
}
ble_gattc_notify_custom(connectionHandle, eventHandle, om);
-} \ No newline at end of file
+}
diff --git a/src/components/ble/BatteryInformationService.cpp b/src/components/ble/BatteryInformationService.cpp
index 7f17690..2917866 100644
--- a/src/components/ble/BatteryInformationService.cpp
+++ b/src/components/ble/BatteryInformationService.cpp
@@ -14,7 +14,7 @@ int BatteryInformationServiceCallback(uint16_t conn_handle, uint16_t attr_handle
BatteryInformationService::BatteryInformationService(Controllers::Battery& batteryController)
: batteryController {batteryController},
- characteristicDefinition {{.uuid = (ble_uuid_t*) &batteryLevelUuid,
+ characteristicDefinition {{.uuid = &batteryLevelUuid.u,
.access_cb = BatteryInformationServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
@@ -23,7 +23,7 @@ BatteryInformationService::BatteryInformationService(Controllers::Battery& batte
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &batteryInformationServiceUuid,
+ .uuid = &batteryInformationServiceUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
@@ -43,7 +43,7 @@ int BatteryInformationService::OnBatteryServiceRequested(uint16_t connectionHand
ble_gatt_access_ctxt* context) {
if (attributeHandle == batteryLevelHandle) {
NRF_LOG_INFO("BATTERY : handle = %d", batteryLevelHandle);
- static uint8_t batteryValue = batteryController.PercentRemaining();
+ uint8_t batteryValue = batteryController.PercentRemaining();
int res = os_mbuf_append(context->om, &batteryValue, 1);
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
diff --git a/src/components/ble/CurrentTimeClient.cpp b/src/components/ble/CurrentTimeClient.cpp
index c6e6831..90d1f0c 100644
--- a/src/components/ble/CurrentTimeClient.cpp
+++ b/src/components/ble/CurrentTimeClient.cpp
@@ -47,7 +47,7 @@ bool CurrentTimeClient::OnDiscoveryEvent(uint16_t connectionHandle, const ble_ga
return true;
}
- if (service != nullptr && ble_uuid_cmp(((ble_uuid_t*) &ctsServiceUuid), &service->uuid.u) == 0) {
+ if (service != nullptr && ble_uuid_cmp(&ctsServiceUuid.u, &service->uuid.u) == 0) {
NRF_LOG_INFO("CTS discovered : 0x%x - 0x%x", service->start_handle, service->end_handle);
isDiscovered = true;
ctsStartHandle = service->start_handle;
@@ -72,7 +72,7 @@ int CurrentTimeClient::OnCharacteristicDiscoveryEvent(uint16_t conn_handle,
return 0;
}
- if (characteristic != nullptr && ble_uuid_cmp(((ble_uuid_t*) &currentTimeCharacteristicUuid), &characteristic->uuid.u) == 0) {
+ if (characteristic != nullptr && ble_uuid_cmp(&currentTimeCharacteristicUuid.u, &characteristic->uuid.u) == 0) {
NRF_LOG_INFO("CTS Characteristic discovered : 0x%x", characteristic->val_handle);
isCharacteristicDiscovered = true;
currentTimeHandle = characteristic->val_handle;
diff --git a/src/components/ble/CurrentTimeService.cpp b/src/components/ble/CurrentTimeService.cpp
index b49be39..eefb7ec 100644
--- a/src/components/ble/CurrentTimeService.cpp
+++ b/src/components/ble/CurrentTimeService.cpp
@@ -53,7 +53,7 @@ int CurrentTimeService::OnTimeAccessed(uint16_t conn_handle, uint16_t attr_handl
}
CurrentTimeService::CurrentTimeService(DateTime& dateTimeController)
- : characteristicDefinition {{.uuid = (ble_uuid_t*) &ctChrUuid,
+ : characteristicDefinition {{.uuid = &ctChrUuid.u,
.access_cb = CTSCallback,
.arg = this,
@@ -62,7 +62,7 @@ CurrentTimeService::CurrentTimeService(DateTime& dateTimeController)
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &ctsUuid,
+ .uuid = &ctsUuid.u,
.characteristics = characteristicDefinition},
{0},
},
diff --git a/src/components/ble/DeviceInformationService.cpp b/src/components/ble/DeviceInformationService.cpp
index cf48207..778d6e3 100644
--- a/src/components/ble/DeviceInformationService.cpp
+++ b/src/components/ble/DeviceInformationService.cpp
@@ -56,37 +56,37 @@ int DeviceInformationService::OnDeviceInfoRequested(uint16_t conn_handle, uint16
DeviceInformationService::DeviceInformationService()
: characteristicDefinition {{
- .uuid = (ble_uuid_t*) &manufacturerNameUuid,
+ .uuid = &manufacturerNameUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
},
{
- .uuid = (ble_uuid_t*) &modelNumberUuid,
+ .uuid = &modelNumberUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
},
{
- .uuid = (ble_uuid_t*) &serialNumberUuid,
+ .uuid = &serialNumberUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
},
{
- .uuid = (ble_uuid_t*) &fwRevisionUuid,
+ .uuid = &fwRevisionUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
},
{
- .uuid = (ble_uuid_t*) &hwRevisionUuid,
+ .uuid = &hwRevisionUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
},
{
- .uuid = (ble_uuid_t*) &swRevisionUuid,
+ .uuid = &swRevisionUuid.u,
.access_cb = DeviceInformationCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
@@ -95,7 +95,7 @@ DeviceInformationService::DeviceInformationService()
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &deviceInfoUuid,
+ .uuid = &deviceInfoUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
diff --git a/src/components/ble/DfuService.cpp b/src/components/ble/DfuService.cpp
index 4179994..3d6416f 100644
--- a/src/components/ble/DfuService.cpp
+++ b/src/components/ble/DfuService.cpp
@@ -33,21 +33,21 @@ DfuService::DfuService(Pinetime::System::SystemTask& systemTask,
bleController {bleController},
dfuImage {spiNorFlash},
characteristicDefinition {{
- .uuid = (ble_uuid_t*) &packetCharacteristicUuid,
+ .uuid = &packetCharacteristicUuid.u,
.access_cb = DfuServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
.val_handle = nullptr,
},
{
- .uuid = (ble_uuid_t*) &controlPointCharacteristicUuid,
+ .uuid = &controlPointCharacteristicUuid.u,
.access_cb = DfuServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY,
.val_handle = nullptr,
},
{
- .uuid = (ble_uuid_t*) &revisionCharacteristicUuid,
+ .uuid = &revisionCharacteristicUuid.u,
.access_cb = DfuServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ,
@@ -60,7 +60,7 @@ DfuService::DfuService(Pinetime::System::SystemTask& systemTask,
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &serviceUuid,
+ .uuid = &serviceUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
@@ -81,9 +81,9 @@ int DfuService::OnServiceData(uint16_t connectionHandle, uint16_t attributeHandl
xTimerStart(timeoutTimer, 0);
}
- ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &packetCharacteristicUuid, nullptr, &packetCharacteristicHandle);
- ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &controlPointCharacteristicUuid, nullptr, &controlPointCharacteristicHandle);
- ble_gatts_find_chr((ble_uuid_t*) &serviceUuid, (ble_uuid_t*) &revisionCharacteristicUuid, nullptr, &revisionCharacteristicHandle);
+ ble_gatts_find_chr(&serviceUuid.u, &packetCharacteristicUuid.u, nullptr, &packetCharacteristicHandle);
+ ble_gatts_find_chr(&serviceUuid.u, &controlPointCharacteristicUuid.u, nullptr, &controlPointCharacteristicHandle);
+ ble_gatts_find_chr(&serviceUuid.u, &revisionCharacteristicUuid.u, nullptr, &revisionCharacteristicHandle);
if (attributeHandle == packetCharacteristicHandle) {
if (context->op == BLE_GATT_ACCESS_OP_WRITE_CHR)
@@ -164,10 +164,10 @@ int DfuService::WritePacketHandler(uint16_t connectionHandle, os_mbuf* om) {
if ((nbPacketReceived % nbPacketsToNotify) == 0 && bytesReceived != applicationSize) {
uint8_t data[5] {static_cast<uint8_t>(Opcodes::PacketReceiptNotification),
- (uint8_t) (bytesReceived & 0x000000FFu),
- (uint8_t) (bytesReceived >> 8u),
- (uint8_t) (bytesReceived >> 16u),
- (uint8_t) (bytesReceived >> 24u)};
+ (uint8_t)(bytesReceived & 0x000000FFu),
+ (uint8_t)(bytesReceived >> 8u),
+ (uint8_t)(bytesReceived >> 16u),
+ (uint8_t)(bytesReceived >> 24u)};
NRF_LOG_INFO("[DFU] -> Send packet notification: %d bytes received", bytesReceived);
notificationManager.Send(connectionHandle, controlPointCharacteristicHandle, data, 5);
}
@@ -422,9 +422,9 @@ uint16_t DfuService::DfuImage::ComputeCrc(uint8_t const* p_data, uint32_t size,
uint16_t crc = (p_crc == NULL) ? 0xFFFF : *p_crc;
for (uint32_t i = 0; i < size; i++) {
- crc = (uint8_t) (crc >> 8) | (crc << 8);
+ crc = (uint8_t)(crc >> 8) | (crc << 8);
crc ^= p_data[i];
- crc ^= (uint8_t) (crc & 0xFF) >> 4;
+ crc ^= (uint8_t)(crc & 0xFF) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xFF) << 4) << 1;
}
diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp
index c556566..75a038a 100644
--- a/src/components/ble/HeartRateService.cpp
+++ b/src/components/ble/HeartRateService.cpp
@@ -8,7 +8,7 @@ constexpr ble_uuid16_t HeartRateService::heartRateServiceUuid;
constexpr ble_uuid16_t HeartRateService::heartRateMeasurementUuid;
namespace {
- int HeartRateServiceServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
+ int HeartRateServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
auto* heartRateService = static_cast<HeartRateService*>(arg);
return heartRateService->OnHeartRateRequested(conn_handle, attr_handle, ctxt);
}
@@ -18,8 +18,8 @@ namespace {
HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController)
: system {system},
heartRateController {heartRateController},
- characteristicDefinition {{.uuid = (ble_uuid_t*) &heartRateMeasurementUuid,
- .access_cb = HeartRateServiceServiceCallback,
+ characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u,
+ .access_cb = HeartRateServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &heartRateMeasurementHandle},
@@ -27,7 +27,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &heartRateServiceUuid,
+ .uuid = &heartRateServiceUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
@@ -56,6 +56,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a
}
void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
+ if(!heartRateMeasurementNotificationEnable) return;
+
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
auto* om = ble_hs_mbuf_from_flat(buffer, 2);
@@ -67,3 +69,13 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
ble_gattc_notify_custom(connectionHandle, heartRateMeasurementHandle, om);
}
+
+void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
+ if(attributeHandle == heartRateMeasurementHandle)
+ heartRateMeasurementNotificationEnable = true;
+}
+
+void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
+ if(attributeHandle == heartRateMeasurementHandle)
+ heartRateMeasurementNotificationEnable = false;
+} \ No newline at end of file
diff --git a/src/components/ble/HeartRateService.h b/src/components/ble/HeartRateService.h
index 0b16703..4e4a5a4 100644
--- a/src/components/ble/HeartRateService.h
+++ b/src/components/ble/HeartRateService.h
@@ -2,6 +2,7 @@
#define min // workaround: nimble's min/max macros conflict with libstdc++
#define max
#include <host/ble_gap.h>
+#include <atomic>
#undef max
#undef min
@@ -18,6 +19,9 @@ namespace Pinetime {
int OnHeartRateRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewHeartRateValue(uint8_t hearRateValue);
+ void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
+ void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
+
private:
Pinetime::System::SystemTask& system;
Controllers::HeartRateController& heartRateController;
@@ -28,10 +32,11 @@ namespace Pinetime {
static constexpr ble_uuid16_t heartRateMeasurementUuid {.u {.type = BLE_UUID_TYPE_16}, .value = heartRateMeasurementId};
- struct ble_gatt_chr_def characteristicDefinition[3];
+ struct ble_gatt_chr_def characteristicDefinition[2];
struct ble_gatt_svc_def serviceDefinition[2];
uint16_t heartRateMeasurementHandle;
+ std::atomic_bool heartRateMeasurementNotificationEnable {false};
};
}
}
diff --git a/src/components/ble/ImmediateAlertService.cpp b/src/components/ble/ImmediateAlertService.cpp
index 820d3b6..17ed1a9 100644
--- a/src/components/ble/ImmediateAlertService.cpp
+++ b/src/components/ble/ImmediateAlertService.cpp
@@ -32,7 +32,7 @@ ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask& syste
Pinetime::Controllers::NotificationManager& notificationManager)
: systemTask {systemTask},
notificationManager {notificationManager},
- characteristicDefinition {{.uuid = (ble_uuid_t*) &alertLevelUuid,
+ characteristicDefinition {{.uuid = &alertLevelUuid.u,
.access_cb = AlertLevelCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
@@ -41,7 +41,7 @@ ImmediateAlertService::ImmediateAlertService(Pinetime::System::SystemTask& syste
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &immediateAlertServiceUuid,
+ .uuid = &immediateAlertServiceUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
@@ -72,4 +72,4 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t connectionHandle, uint16
}
return 0;
-} \ No newline at end of file
+}
diff --git a/src/components/ble/MotionService.cpp b/src/components/ble/MotionService.cpp
new file mode 100644
index 0000000..b4786ab
--- /dev/null
+++ b/src/components/ble/MotionService.cpp
@@ -0,0 +1,124 @@
+#include "MotionService.h"
+#include "components/motion//MotionController.h"
+#include "systemtask/SystemTask.h"
+
+using namespace Pinetime::Controllers;
+
+namespace {
+ // 0002yyxx-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
+ return ble_uuid128_t{
+ .u = {.type = BLE_UUID_TYPE_128},
+ .value = { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x03, 0x00 }
+ };
+ }
+
+ // 00020000-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t BaseUuid() {
+ return CharUuid(0x00, 0x00);
+ }
+
+ constexpr ble_uuid128_t motionServiceUuid {BaseUuid()};
+ constexpr ble_uuid128_t stepCountCharUuid {CharUuid(0x01, 0x00)};
+ constexpr ble_uuid128_t motionValuesCharUuid {CharUuid(0x02, 0x00)};
+
+ int MotionServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
+ auto* motionService = static_cast<MotionService*>(arg);
+ return motionService->OnStepCountRequested(conn_handle, attr_handle, ctxt);
+ }
+}
+
+// TODO Refactoring - remove dependency to SystemTask
+MotionService::MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController)
+ : system {system},
+ motionController {motionController},
+ characteristicDefinition {{.uuid = &stepCountCharUuid.u,
+ .access_cb = MotionServiceCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &stepCountHandle},
+ {.uuid = &motionValuesCharUuid.u,
+ .access_cb = MotionServiceCallback,
+ .arg = this,
+ .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
+ .val_handle = &motionValuesHandle},
+ {0}},
+ serviceDefinition {
+ {
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = &motionServiceUuid.u,
+ .characteristics = characteristicDefinition
+ },
+ {0},
+ } {
+ // TODO refactor to prevent this loop dependency (service depends on controller and controller depends on service)
+ motionController.SetService(this);
+}
+
+void MotionService::Init() {
+ int res = 0;
+ res = ble_gatts_count_cfg(serviceDefinition);
+ ASSERT(res == 0);
+
+ res = ble_gatts_add_svcs(serviceDefinition);
+ ASSERT(res == 0);
+}
+
+int MotionService::OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
+ if (attributeHandle == stepCountHandle) {
+ NRF_LOG_INFO("Motion-stepcount : handle = %d", stepCountHandle);
+ uint32_t buffer = motionController.NbSteps();
+
+ int res = os_mbuf_append(context->om, &buffer, 4);
+ return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ } else if(attributeHandle == motionValuesHandle) {
+ int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
+
+ int res = os_mbuf_append(context->om, buffer, 3 * sizeof(int16_t));
+ return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+ return 0;
+}
+
+void MotionService::OnNewStepCountValue(uint32_t stepCount) {
+ if(!stepCountNoficationEnabled) return;
+
+ uint32_t buffer = stepCount;
+ auto* om = ble_hs_mbuf_from_flat(&buffer, 4);
+
+ uint16_t connectionHandle = system.nimble().connHandle();
+
+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
+ return;
+ }
+
+ ble_gattc_notify_custom(connectionHandle, stepCountHandle, om);
+}
+void MotionService::OnNewMotionValues(int16_t x, int16_t y, int16_t z) {
+ if(!motionValuesNoficationEnabled) return;
+
+ int16_t buffer[3] = { motionController.X(), motionController.Y(), motionController.Z() };
+ auto* om = ble_hs_mbuf_from_flat(buffer, 3 * sizeof(int16_t));
+
+ uint16_t connectionHandle = system.nimble().connHandle();
+
+ if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
+ return;
+ }
+
+ ble_gattc_notify_custom(connectionHandle, motionValuesHandle, om);
+}
+
+void MotionService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
+ if(attributeHandle == stepCountHandle)
+ stepCountNoficationEnabled = true;
+ else if(attributeHandle == motionValuesHandle)
+ motionValuesNoficationEnabled = true;
+}
+
+void MotionService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) {
+ if(attributeHandle == stepCountHandle)
+ stepCountNoficationEnabled = false;
+ else if(attributeHandle == motionValuesHandle)
+ motionValuesNoficationEnabled = false;
+}
diff --git a/src/components/ble/MotionService.h b/src/components/ble/MotionService.h
new file mode 100644
index 0000000..1b4ac0a
--- /dev/null
+++ b/src/components/ble/MotionService.h
@@ -0,0 +1,39 @@
+#pragma once
+#define min // workaround: nimble's min/max macros conflict with libstdc++
+#define max
+#include <host/ble_gap.h>
+#include <atomic>
+#undef max
+#undef min
+
+namespace Pinetime {
+ namespace System {
+ class SystemTask;
+ }
+ namespace Controllers {
+ class MotionController;
+ class MotionService {
+ public:
+ MotionService(Pinetime::System::SystemTask& system, Controllers::MotionController& motionController);
+ void Init();
+ int OnStepCountRequested(uint16_t connectionHandle, uint16_t attributeHandle, ble_gatt_access_ctxt* context);
+ void OnNewStepCountValue(uint32_t stepCount);
+ void OnNewMotionValues(int16_t x, int16_t y, int16_t z);
+
+ void SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
+ void UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle);
+
+ private:
+ Pinetime::System::SystemTask& system;
+ Controllers::MotionController& motionController;
+
+ struct ble_gatt_chr_def characteristicDefinition[3];
+ struct ble_gatt_svc_def serviceDefinition[2];
+
+ uint16_t stepCountHandle;
+ uint16_t motionValuesHandle;
+ std::atomic_bool stepCountNoficationEnabled {false};
+ std::atomic_bool motionValuesNoficationEnabled {false};
+ };
+ }
+}
diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp
index e1c20bf..b49148d 100644
--- a/src/components/ble/NavigationService.cpp
+++ b/src/components/ble/NavigationService.cpp
@@ -20,54 +20,45 @@
#include "systemtask/SystemTask.h"
-int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
- auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
- return navService->OnCommand(conn_handle, attr_handle, ctxt);
-}
-
-Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) {
- navUuid.value[14] = navId[0];
- navUuid.value[15] = navId[1];
+namespace {
+ // 0001yyxx-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
+ return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
+ .value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x01, 0x00}};
+ }
- navFlagCharUuid.value[12] = navFlagCharId[0];
- navFlagCharUuid.value[13] = navFlagCharId[1];
- navFlagCharUuid.value[14] = navId[0];
- navFlagCharUuid.value[15] = navId[1];
+ // 00010000-78fc-48fe-8e23-433b3a1942d0
+ constexpr ble_uuid128_t BaseUuid() {
+ return CharUuid(0x00, 0x00);
+ }
- navNarrativeCharUuid.value[12] = navNarrativeCharId[0];
- navNarrativeCharUuid.value[13] = navNarrativeCharId[1];
- navNarrativeCharUuid.value[14] = navId[0];
- navNarrativeCharUuid.value[15] = navId[1];
+ constexpr ble_uuid128_t navUuid {BaseUuid()};
- navManDistCharUuid.value[12] = navManDistCharId[0];
- navManDistCharUuid.value[13] = navManDistCharId[1];
- navManDistCharUuid.value[14] = navId[0];
- navManDistCharUuid.value[15] = navId[1];
+ constexpr ble_uuid128_t navFlagCharUuid {CharUuid(0x01, 0x00)};
+ constexpr ble_uuid128_t navNarrativeCharUuid {CharUuid(0x02, 0x00)};
+ constexpr ble_uuid128_t navManDistCharUuid {CharUuid(0x03, 0x00)};
+ constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};
- navProgressCharUuid.value[12] = navProgressCharId[0];
- navProgressCharUuid.value[13] = navProgressCharId[1];
- navProgressCharUuid.value[14] = navId[0];
- navProgressCharUuid.value[15] = navId[1];
+ int NAVCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
+ auto navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
+ return navService->OnCommand(conn_handle, attr_handle, ctxt);
+ }
+} // namespace
+Pinetime::Controllers::NavigationService::NavigationService(Pinetime::System::SystemTask& system) : m_system(system) {
characteristicDefinition[0] = {
- .uuid = (ble_uuid_t*) (&navFlagCharUuid), .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
-
- characteristicDefinition[1] = {.uuid = (ble_uuid_t*) (&navNarrativeCharUuid),
- .access_cb = NAVCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[2] = {.uuid = (ble_uuid_t*) (&navManDistCharUuid),
- .access_cb = NAVCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
- characteristicDefinition[3] = {.uuid = (ble_uuid_t*) (&navProgressCharUuid),
- .access_cb = NAVCallback,
- .arg = this,
- .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ .uuid = &navFlagCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+
+ characteristicDefinition[1] = {
+ .uuid = &navNarrativeCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[2] = {
+ .uuid = &navManDistCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
+ characteristicDefinition[3] = {
+ .uuid = &navProgressCharUuid.u, .access_cb = NAVCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ};
characteristicDefinition[4] = {0};
- serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = (ble_uuid_t*) &navUuid, .characteristics = characteristicDefinition};
+ serviceDefinition[0] = {.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &navUuid.u, .characteristics = characteristicDefinition};
serviceDefinition[1] = {0};
m_progress = 0;
@@ -90,13 +81,13 @@ int Pinetime::Controllers::NavigationService::OnCommand(uint16_t conn_handle, ui
data[notifSize] = '\0';
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
char* s = (char*) &data[0];
- if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navFlagCharUuid) == 0) {
+ if (ble_uuid_cmp(ctxt->chr->uuid, &navFlagCharUuid.u) == 0) {
m_flag = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navNarrativeCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &navNarrativeCharUuid.u) == 0) {
m_narrative = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navManDistCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &navManDistCharUuid.u) == 0) {
m_manDist = s;
- } else if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &navProgressCharUuid) == 0) {
+ } else if (ble_uuid_cmp(ctxt->chr->uuid, &navProgressCharUuid.u) == 0) {
m_progress = data[0];
}
}
diff --git a/src/components/ble/NavigationService.h b/src/components/ble/NavigationService.h
index 5aab263..c0c77f3 100644
--- a/src/components/ble/NavigationService.h
+++ b/src/components/ble/NavigationService.h
@@ -26,10 +26,6 @@
#undef max
#undef min
-// c7e60000-78fc-48fe-8e23-433b3a1942d0
-#define NAVIGATION_SERVICE_UUID_BASE \
- { 0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, 0x00, 0x00, 0x00, 0x00 }
-
namespace Pinetime {
namespace System {
class SystemTask;
@@ -53,19 +49,6 @@ namespace Pinetime {
int getProgress();
private:
- static constexpr uint8_t navId[2] = {0x01, 0x00};
- static constexpr uint8_t navFlagCharId[2] = {0x01, 0x00};
- static constexpr uint8_t navNarrativeCharId[2] = {0x02, 0x00};
- static constexpr uint8_t navManDistCharId[2] = {0x03, 0x00};
- static constexpr uint8_t navProgressCharId[2] = {0x04, 0x00};
-
- ble_uuid128_t navUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
-
- ble_uuid128_t navFlagCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
- ble_uuid128_t navNarrativeCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
- ble_uuid128_t navManDistCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
- ble_uuid128_t navProgressCharUuid {.u = {.type = BLE_UUID_TYPE_128}, .value = NAVIGATION_SERVICE_UUID_BASE};
-
struct ble_gatt_chr_def characteristicDefinition[5];
struct ble_gatt_svc_def serviceDefinition[2];
diff --git a/src/components/ble/NimbleController.cpp b/src/components/ble/NimbleController.cpp
index 879421e..1bcae1b 100644
--- a/src/components/ble/NimbleController.cpp
+++ b/src/components/ble/NimbleController.cpp
@@ -23,7 +23,8 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
Pinetime::Controllers::NotificationManager& notificationManager,
Controllers::Battery& batteryController,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
- Controllers::HeartRateController& heartRateController)
+ Controllers::HeartRateController& heartRateController,
+ Controllers::MotionController& motionController)
: systemTask {systemTask},
bleController {bleController},
dateTimeController {dateTimeController},
@@ -39,6 +40,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
heartRateService {systemTask, heartRateController},
+ motionService{systemTask, motionController},
serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
}
@@ -81,6 +83,7 @@ void NimbleController::Init() {
batteryInformationService.Init();
immediateAlertService.Init();
heartRateService.Init();
+ motionService.Init();
int rc;
rc = ble_hs_util_ensure_addr(0);
@@ -215,6 +218,19 @@ int NimbleController::OnGAPEvent(ble_gap_event* event) {
event->subscribe.prev_notify,
event->subscribe.cur_notify,
event->subscribe.prev_indicate);
+
+ if(event->subscribe.reason == BLE_GAP_SUBSCRIBE_REASON_TERM) {
+ heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ }
+ else if(event->subscribe.prev_notify == 0 && event->subscribe.cur_notify == 1) {
+ heartRateService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ motionService.SubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ }
+ else if(event->subscribe.prev_notify == 1 && event->subscribe.cur_notify == 0) {
+ heartRateService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ motionService.UnsubscribeNotification(event->subscribe.conn_handle, event->subscribe.attr_handle);
+ }
break;
case BLE_GAP_EVENT_MTU:
diff --git a/src/components/ble/NimbleController.h b/src/components/ble/NimbleController.h
index 473bb1a..76f89ba 100644
--- a/src/components/ble/NimbleController.h
+++ b/src/components/ble/NimbleController.h
@@ -19,6 +19,7 @@
#include "NavigationService.h"
#include "ServiceDiscovery.h"
#include "HeartRateService.h"
+#include "MotionService.h"
namespace Pinetime {
namespace Drivers {
@@ -43,7 +44,8 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager,
Controllers::Battery& batteryController,
Pinetime::Drivers::SpiNorFlash& spiNorFlash,
- Controllers::HeartRateController& heartRateController);
+ Controllers::HeartRateController& heartRateController,
+ Controllers::MotionController& motionController);
void Init();
void StartAdvertising();
int OnGAPEvent(ble_gap_event* event);
@@ -95,6 +97,7 @@ namespace Pinetime {
BatteryInformationService batteryInformationService;
ImmediateAlertService immediateAlertService;
HeartRateService heartRateService;
+ MotionService motionService;
uint8_t addrType; // 1 = Random, 0 = PUBLIC
uint16_t connectionHandle = BLE_HS_CONN_HANDLE_NONE;
diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp
index 0756d38..e9c5d87 100644
--- a/src/components/datetime/DateTimeController.cpp
+++ b/src/components/datetime/DateTimeController.cpp
@@ -5,6 +5,12 @@
using namespace Pinetime::Controllers;
+namespace {
+ char const* DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
+ char const* MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
+ char const* MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+}
+
void DateTime::SetCurrentTime(std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> t) {
this->currentDateTime = t;
UpdateTime(previousSystickCounter); // Update internal state without updating the time
@@ -80,48 +86,18 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
}
const char* DateTime::MonthShortToString() {
- return DateTime::MonthsString[static_cast<uint8_t>(month)];
-}
-
-const char* DateTime::MonthShortToStringLow() {
- return DateTime::MonthsStringLow[static_cast<uint8_t>(month)];
-}
-
-const char* DateTime::MonthsToStringLow() {
- return DateTime::MonthsLow[static_cast<uint8_t>(month)];
-}
-
-const char* DateTime::DayOfWeekToString() {
- return DateTime::DaysString[static_cast<uint8_t>(dayOfWeek)];
+ return MonthsString[static_cast<uint8_t>(month)];
}
const char* DateTime::DayOfWeekShortToString() {
- return DateTime::DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
+ return DaysStringShort[static_cast<uint8_t>(dayOfWeek)];
}
-const char* DateTime::DayOfWeekToStringLow() {
- return DateTime::DaysStringLow[static_cast<uint8_t>(dayOfWeek)];
-}
-
-const char* DateTime::DayOfWeekShortToStringLow() {
- return DateTime::DaysStringShortLow[static_cast<uint8_t>(dayOfWeek)];
+const char* DateTime::MonthShortToStringLow(Months month) {
+ return MonthsStringLow[static_cast<uint8_t>(month)];
}
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
this->systemTask = systemTask;
}
-char const* DateTime::DaysStringLow[] = {"--", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
-
-char const* DateTime::DaysStringShortLow[] = {"--", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
-
-char const* DateTime::DaysStringShort[] = {"--", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
-
-char const* DateTime::DaysString[] = {"--", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"};
-
-char const* DateTime::MonthsString[] = {"--", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"};
-
-char const* DateTime::MonthsStringLow[] = {"--", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
-char const* DateTime::MonthsLow[] = {
- "--", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; \ No newline at end of file
diff --git a/src/components/datetime/DateTimeController.h b/src/components/datetime/DateTimeController.h
index 061c303..77ed68e 100644
--- a/src/components/datetime/DateTimeController.h
+++ b/src/components/datetime/DateTimeController.h
@@ -59,12 +59,8 @@ namespace Pinetime {
}
const char* MonthShortToString();
- const char* MonthShortToStringLow();
- const char* MonthsToStringLow();
- const char* DayOfWeekToString();
const char* DayOfWeekShortToString();
- const char* DayOfWeekToStringLow();
- const char* DayOfWeekShortToStringLow();
+ static const char* MonthShortToStringLow(Months month);
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> CurrentDateTime() const {
return currentDateTime;
@@ -91,14 +87,6 @@ namespace Pinetime {
bool isMidnightAlreadyNotified = false;
System::SystemTask* systemTask = nullptr;
-
- static char const* DaysString[];
- static char const* DaysStringShort[];
- static char const* DaysStringLow[];
- static char const* DaysStringShortLow[];
- static char const* MonthsString[];
- static char const* MonthsStringLow[];
- static char const* MonthsLow[];
};
}
-} \ No newline at end of file
+}
diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h
index 1f2eb7e..75ba16c 100644
--- a/src/components/fs/FS.h
+++ b/src/components/fs/FS.h
@@ -53,7 +53,7 @@ namespace Pinetime {
*
*/
static constexpr size_t startAddress = 0x0B4000;
- static constexpr size_t size = 0x3C0000;
+ static constexpr size_t size = 0x34C000;
static constexpr size_t blockSize = 4096;
bool resourcesValid = false;
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index b0dbada..a2384d7 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -3,6 +3,14 @@
using namespace Pinetime::Controllers;
void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) {
+ if (this->nbSteps != nbSteps && service != nullptr) {
+ service->OnNewStepCountValue(nbSteps);
+ }
+
+ if(service != nullptr && (this->x != x || this->y != y || this->z != z)) {
+ service->OnNewMotionValues(x, y, z);
+ }
+
this->x = x;
this->y = y;
this->z = z;
@@ -41,3 +49,6 @@ void MotionController::Init(Pinetime::Drivers::Bma421::DeviceTypes types) {
default: this->deviceType = DeviceTypes::Unknown; break;
}
}
+void MotionController::SetService(Pinetime::Controllers::MotionService* service) {
+ this->service = service;
+}
diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h
index ff71509..c72d8a4 100644
--- a/src/components/motion/MotionController.h
+++ b/src/components/motion/MotionController.h
@@ -2,6 +2,7 @@
#include <cstdint>
#include <drivers/Bma421.h>
+#include <components/ble/MotionService.h>
namespace Pinetime {
namespace Controllers {
@@ -39,6 +40,7 @@ namespace Pinetime {
}
void Init(Pinetime::Drivers::Bma421::DeviceTypes types);
+ void SetService(Pinetime::Controllers::MotionService* service);
private:
uint32_t nbSteps;
@@ -48,6 +50,7 @@ namespace Pinetime {
int16_t lastYForWakeUp = 0;
bool isSensorOk = false;
DeviceTypes deviceType = DeviceTypes::Unknown;
+ Pinetime::Controllers::MotionService* service = nullptr;
};
}
} \ No newline at end of file