summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/components')
-rw-r--r--src/components/alarm/AlarmController.cpp2
-rw-r--r--src/components/battery/BatteryController.cpp10
-rw-r--r--src/components/ble/NavigationService.cpp2
-rw-r--r--src/components/heartrate/Ppg.cpp38
-rw-r--r--src/components/heartrate/Ppg.h6
-rw-r--r--src/components/heartrate/Ptagc.cpp8
-rw-r--r--src/components/motion/MotionController.cpp5
7 files changed, 39 insertions, 32 deletions
diff --git a/src/components/alarm/AlarmController.cpp b/src/components/alarm/AlarmController.cpp
index d97e1cff..88f65d9a 100644
--- a/src/components/alarm/AlarmController.cpp
+++ b/src/components/alarm/AlarmController.cpp
@@ -28,7 +28,7 @@ AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : da
namespace {
void SetOffAlarm(TimerHandle_t xTimer) {
- auto controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer));
+ auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(pvTimerGetTimerID(xTimer));
controller->SetOffAlarmNow();
}
}
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index b61f0ce3..dc15612e 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -16,8 +16,8 @@ Battery::Battery() {
}
void Battery::ReadPowerState() {
- isCharging = !nrf_gpio_pin_read(PinMap::Charging);
- isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
+ isCharging = (nrf_gpio_pin_read(PinMap::Charging) == 0);
+ isPowerPresent = (nrf_gpio_pin_read(PinMap::PowerPresent) == 0);
if (isPowerPresent && !isCharging) {
isFull = true;
@@ -81,10 +81,8 @@ 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;
- uint8_t newPercent;
- if (isFull) {
- newPercent = 100;
- } else {
+ uint8_t newPercent = 100;
+ if (!isFull) {
newPercent = std::min(aprox.GetValue(voltage), isCharging ? uint8_t {99} : uint8_t {100});
}
diff --git a/src/components/ble/NavigationService.cpp b/src/components/ble/NavigationService.cpp
index 76143686..ea8f3a4d 100644
--- a/src/components/ble/NavigationService.cpp
+++ b/src/components/ble/NavigationService.cpp
@@ -40,7 +40,7 @@ namespace {
constexpr ble_uuid128_t navProgressCharUuid {CharUuid(0x04, 0x00)};
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);
+ auto* navService = static_cast<Pinetime::Controllers::NavigationService*>(arg);
return navService->OnCommand(conn_handle, attr_handle, ctxt);
}
} // namespace
diff --git a/src/components/heartrate/Ppg.cpp b/src/components/heartrate/Ppg.cpp
index a5d83696..900b1c22 100644
--- a/src/components/heartrate/Ppg.cpp
+++ b/src/components/heartrate/Ppg.cpp
@@ -29,8 +29,9 @@ namespace {
auto z1 = CompareShift(d, mn - 1, size);
for (int i = mn; i < mx + 1; i++) {
auto z = CompareShift(d, i, size);
- if (z2 > z1 && z1 < z)
+ if (z2 > z1 && z1 < z) {
return i;
+ }
z2 = z1;
z1 = z;
}
@@ -52,41 +53,48 @@ int8_t Ppg::Preprocess(float spl) {
auto spl_int = static_cast<int8_t>(spl);
- if (dataIndex < 200)
+ if (dataIndex < 200) {
data[dataIndex++] = spl_int;
+ }
return spl_int;
}
-float Ppg::HeartRate() {
- if (dataIndex < 200)
+int Ppg::HeartRate() {
+ if (dataIndex < 200) {
return 0;
+ }
NRF_LOG_INFO("PREPROCESS, offset = %d", offset);
auto hr = ProcessHeartRate();
dataIndex = 0;
return hr;
}
-float Ppg::ProcessHeartRate() {
- auto t0 = Trough(data.data(), dataIndex, 7, 48);
- if (t0 < 0)
+
+int Ppg::ProcessHeartRate() {
+ int t0 = Trough(data.data(), dataIndex, 7, 48);
+ if (t0 < 0) {
return 0;
+ }
- float t1 = t0 * 2;
+ int t1 = t0 * 2;
t1 = Trough(data.data(), dataIndex, t1 - 5, t1 + 5);
- if (t1 < 0)
+ if (t1 < 0) {
return 0;
+ }
- float t2 = static_cast<int>(t1 * 3) / 2;
+ int t2 = (t1 * 3) / 2;
t2 = Trough(data.data(), dataIndex, t2 - 5, t2 + 5);
- if (t2 < 0)
+ if (t2 < 0) {
return 0;
+ }
- float t3 = static_cast<int>(t2 * 4) / 3;
+ int t3 = (t2 * 4) / 3;
t3 = Trough(data.data(), dataIndex, t3 - 4, t3 + 4);
- if (t3 < 0)
- return static_cast<int>(60 * 24 * 3) / static_cast<int>(t2);
+ if (t3 < 0) {
+ return (60 * 24 * 3) / t2;
+ }
- return static_cast<int>(60 * 24 * 4) / static_cast<int>(t3);
+ return (60 * 24 * 4) / t3;
}
void Ppg::SetOffset(uint16_t offset) {
diff --git a/src/components/heartrate/Ppg.h b/src/components/heartrate/Ppg.h
index 7000c871..1f709bab 100644
--- a/src/components/heartrate/Ppg.h
+++ b/src/components/heartrate/Ppg.h
@@ -12,9 +12,9 @@ namespace Pinetime {
public:
Ppg();
int8_t Preprocess(float spl);
- float HeartRate();
+ int HeartRate();
- void SetOffset(uint16_t i);
+ void SetOffset(uint16_t offset);
void Reset();
private:
@@ -25,7 +25,7 @@ namespace Pinetime {
Ptagc agc;
Biquad lpf;
- float ProcessHeartRate();
+ int ProcessHeartRate();
};
}
}
diff --git a/src/components/heartrate/Ptagc.cpp b/src/components/heartrate/Ptagc.cpp
index 1c60bc23..221be460 100644
--- a/src/components/heartrate/Ptagc.cpp
+++ b/src/components/heartrate/Ptagc.cpp
@@ -14,13 +14,15 @@ Ptagc::Ptagc(float start, float decay, float threshold) : peak {start}, decay {d
}
float Ptagc::Step(float spl) {
- if (std::abs(spl) > peak)
+ if (std::abs(spl) > peak) {
peak *= boost;
- else
+ } else {
peak *= decay;
+ }
- if ((spl > (peak * threshold)) || (spl < (peak * -threshold)))
+ if ((spl > (peak * threshold)) || (spl < (peak * -threshold))) {
return 0.0f;
+ }
spl = 100.0f * spl / (2.0f * peak);
return spl;
diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp
index 7dd32127..d93d769b 100644
--- a/src/components/motion/MotionController.cpp
+++ b/src/components/motion/MotionController.cpp
@@ -26,10 +26,9 @@ bool MotionController::Should_RaiseWake(bool isSleeping) {
if (not isSleeping) {
if (y <= 0) {
return false;
- } else {
- lastYForWakeUp = 0;
- return false;
}
+ lastYForWakeUp = 0;
+ return false;
}
if (y >= 0) {