From afea7ca0d1d670bdee04cfe80a1d8c36efa4fca0 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Sun, 18 Dec 2022 19:14:36 +0200 Subject: Update clang-tidy configuration and fix some warnings (#1474) Don't enable coding conventions from unrelated projects. Only enable generic checks. --- src/components/heartrate/Ppg.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/components/heartrate/Ppg.cpp') 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(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(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(t2 * 4) / 3; + int t3 = (t2 * 4) / 3; t3 = Trough(data.data(), dataIndex, t3 - 4, t3 + 4); - if (t3 < 0) - return static_cast(60 * 24 * 3) / static_cast(t2); + if (t3 < 0) { + return (60 * 24 * 3) / t2; + } - return static_cast(60 * 24 * 4) / static_cast(t3); + return (60 * 24 * 4) / t3; } void Ppg::SetOffset(uint16_t offset) { -- cgit v1.2.3-70-g09d2