Skip to content
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
6 changes: 3 additions & 3 deletions src/components/ble/HeartRateService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ void HeartRateService::Init() {
int HeartRateService::OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context) {
if (attributeHandle == heartRateMeasurementHandle) {
NRF_LOG_INFO("HEARTRATE : handle = %d", heartRateMeasurementHandle);
uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value
uint8_t buffer[2] = {0, heartRateController.HeartRate().value_or(0)}; // [0] = flags, [1] = hr value

int res = os_mbuf_append(context->om, buffer, 2);
return (res == 0) ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
return 0;
}

void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
void HeartRateService::OnNewHeartRateValue(std::optional<uint8_t> heartRateValue) {
if (!heartRateMeasurementNotificationEnable)
return;

uint8_t buffer[2] = {0, heartRateValue}; // [0] = flags, [1] = hr value
uint8_t buffer[2] = {0, heartRateValue.value_or(0)}; // [0] = flags, [1] = hr value
auto* om = ble_hs_mbuf_from_flat(buffer, 2);

uint16_t connectionHandle = nimble.connHandle();
Expand Down
3 changes: 2 additions & 1 deletion src/components/ble/HeartRateService.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#undef max
#undef min
#include <atomic>
#include <optional>

namespace Pinetime {
namespace Controllers {
Expand All @@ -16,7 +17,7 @@ namespace Pinetime {
HeartRateService(NimbleController& nimble, Controllers::HeartRateController& heartRateController);
void Init();
int OnHeartRateRequested(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void OnNewHeartRateValue(uint8_t hearRateValue);
void OnNewHeartRateValue(std::optional<uint8_t> hearRateValue);

void SubscribeNotification(uint16_t attributeHandle);
void UnsubscribeNotification(uint16_t attributeHandle);
Expand Down
3 changes: 2 additions & 1 deletion src/components/heartrate/HeartRateController.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "components/heartrate/HeartRateController.h"
#include <heartratetask/HeartRateTask.h>
#include <systemtask/SystemTask.h>
#include <optional>

using namespace Pinetime::Controllers;

void HeartRateController::Update(HeartRateController::States newState, uint8_t heartRate) {
void HeartRateController::Update(HeartRateController::States newState, std::optional<uint8_t> heartRate) {
this->state = newState;
if (this->heartRate != heartRate) {
this->heartRate = heartRate;
Expand Down
9 changes: 5 additions & 4 deletions src/components/heartrate/HeartRateController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cstdint>
#include <components/ble/HeartRateService.h>
#include <optional>

namespace Pinetime {
namespace Applications {
Expand All @@ -20,15 +21,15 @@ namespace Pinetime {
HeartRateController() = default;
void Start();
void Stop();
void Update(States newState, uint8_t heartRate);
void Update(States newState, std::optional<uint8_t> heartRate);

void SetHeartRateTask(Applications::HeartRateTask* task);

States State() const {
return state;
}

uint8_t HeartRate() const {
std::optional<uint8_t> HeartRate() const {
return heartRate;
}

Expand All @@ -37,8 +38,8 @@ namespace Pinetime {
private:
Applications::HeartRateTask* task = nullptr;
States state = States::Stopped;
uint8_t heartRate = 0;
std::optional<uint8_t> heartRate = std::nullopt;
Pinetime::Controllers::HeartRateService* service = nullptr;
};
}
}
}
5 changes: 3 additions & 2 deletions src/displayapp/screens/HeartRate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ void HeartRate::Refresh() {
lv_label_set_text_static(label_hr, "---");
break;
default:
if (heartRateController.HeartRate() == 0) {
auto hb = heartRateController.HeartRate();
if (!hb) {
lv_label_set_text_static(label_hr, "---");
} else {
lv_label_set_text_fmt(label_hr, "%03d", heartRateController.HeartRate());
lv_label_set_text_fmt(label_hr, "%03d", hb.value());
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/displayapp/screens/WatchFaceCasioStyleG7710.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,12 @@ void WatchFaceCasioStyleG7710::Refresh() {
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
if (heartbeatRunning.Get()) {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, color_text);
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
auto hb = heartbeat.Get();
if (hb.has_value()) {
lv_label_set_text_fmt(heartbeatValue, "%d", hb.value());
} else {
lv_label_set_text_static(heartbeatValue, "-");
}
} else {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
lv_label_set_text_static(heartbeatValue, "");
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFaceCasioStyleG7710.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Pinetime {
Utility::DirtyValue<bool> bleRadioEnabled {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
Utility::DirtyValue<uint32_t> stepCount {};
Utility::DirtyValue<uint8_t> heartbeat {};
Utility::DirtyValue<std::optional<uint8_t>> heartbeat {};
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
Expand Down
7 changes: 6 additions & 1 deletion src/displayapp/screens/WatchFaceDigital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ void WatchFaceDigital::Refresh() {
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
if (heartbeatRunning.Get()) {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xCE1B1B));
lv_label_set_text_fmt(heartbeatValue, "%d", heartbeat.Get());
auto hb = heartbeat.Get();
if (hb.has_value()) {
lv_label_set_text_fmt(heartbeatValue, "%d", hb.value());
} else {
lv_label_set_text_static(heartbeatValue, "-");
}
} else {
lv_obj_set_style_local_text_color(heartbeatIcon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x1B1B1B));
lv_label_set_text_static(heartbeatValue, "");
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFaceDigital.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace Pinetime {

Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::minutes>> currentDateTime {};
Utility::DirtyValue<uint32_t> stepCount {};
Utility::DirtyValue<uint8_t> heartbeat {};
Utility::DirtyValue<std::optional<uint8_t>> heartbeat {};
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {};
Utility::DirtyValue<std::optional<Pinetime::Controllers::SimpleWeatherService::CurrentWeather>> currentWeather {};
Expand Down
5 changes: 3 additions & 2 deletions src/displayapp/screens/WatchFaceTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ void WatchFaceTerminal::Refresh() {
heartbeat = heartRateController.HeartRate();
heartbeatRunning = heartRateController.State() != Controllers::HeartRateController::States::Stopped;
if (heartbeat.IsUpdated() || heartbeatRunning.IsUpdated()) {
if (heartbeatRunning.Get()) {
lv_label_set_text_fmt(heartbeatValue, "[L_HR]#ee3311 %d bpm#", heartbeat.Get());
auto hb = heartbeat.Get();
if (hb.has_value()) {
lv_label_set_text_fmt(heartbeatValue, "[L_HR]#ee3311 %d bpm#", hb.value());
} else {
lv_label_set_text_static(heartbeatValue, "[L_HR]#ee3311 ---#");
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/WatchFaceTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace Pinetime {
Utility::DirtyValue<bool> bleRadioEnabled {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>> currentDateTime {};
Utility::DirtyValue<uint32_t> stepCount {};
Utility::DirtyValue<uint8_t> heartbeat {};
Utility::DirtyValue<std::optional<uint8_t>> heartbeat {};
Utility::DirtyValue<bool> heartbeatRunning {};
Utility::DirtyValue<bool> notificationState {};
Utility::DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::days>> currentDate;
Expand Down
11 changes: 6 additions & 5 deletions src/heartratetask/HeartRateTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <drivers/Hrs3300.h>
#include <components/heartrate/HeartRateController.h>
#include <nrf_log.h>
#include <optional>

using namespace Pinetime::Applications;

Expand All @@ -24,7 +25,7 @@ void HeartRateTask::Process(void* instance) {
}

void HeartRateTask::Work() {
int lastBpm = 0;
std::optional<uint8_t> lastBpm = std::nullopt;
while (true) {
Messages msg;
uint32_t delay;
Expand All @@ -47,15 +48,15 @@ void HeartRateTask::Work() {
case Messages::WakeUp:
state = States::Running;
if (measurementStarted) {
lastBpm = 0;
lastBpm = std::nullopt;
StartMeasurement();
}
break;
case Messages::StartMeasurement:
if (measurementStarted) {
break;
}
lastBpm = 0;
lastBpm = std::nullopt;
StartMeasurement();
measurementStarted = true;
break;
Expand All @@ -79,7 +80,7 @@ void HeartRateTask::Work() {
// Reset all DAQ buffers
ppg.Reset(true);
// Force state to NotEnoughData (below)
lastBpm = 0;
lastBpm = std::nullopt;
bpm = 0;
} else if (bpm < 0) {
// Reset all DAQ buffers except HRS buffer
Expand All @@ -94,7 +95,7 @@ void HeartRateTask::Work() {
}

if (bpm != 0) {
lastBpm = bpm;
lastBpm = std::make_optional(bpm);
controller.Update(Controllers::HeartRateController::States::Running, lastBpm);
}
}
Expand Down
Loading