summaryrefslogtreecommitdiff
path: root/src/components/heartrate/Ptagc.cpp
diff options
context:
space:
mode:
authorJF002 <JF002@users.noreply.github.com>2021-01-20 20:11:56 (GMT)
committerGitHub <noreply@github.com>2021-01-20 20:11:56 (GMT)
commita0f2fa8469f3a2c0f5f2f914ad174029da321cc0 (patch)
tree4ac5f59cd088aea9af51d2d183376de279808e63 /src/components/heartrate/Ptagc.cpp
parent35d4f6d4875b68ff8fdecb436e3bc0a6f91099f3 (diff)
parent68674cec53e2e2add1c0a0b109e5a0e7d9ed5479 (diff)
Merge pull request #169 from JF002/heartRateSensor
Heart rate sensor
Diffstat (limited to 'src/components/heartrate/Ptagc.cpp')
-rw-r--r--src/components/heartrate/Ptagc.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/components/heartrate/Ptagc.cpp b/src/components/heartrate/Ptagc.cpp
new file mode 100644
index 0000000..dd7c441
--- /dev/null
+++ b/src/components/heartrate/Ptagc.cpp
@@ -0,0 +1,28 @@
+/*
+ SPDX-License-Identifier: LGPL-3.0-or-later
+ Original work Copyright (C) 2020 Daniel Thompson
+ C++ port Copyright (C) 2021 Jean-François Milants
+*/
+
+#include <cmath>
+#include "Ptagc.h"
+
+using namespace Pinetime::Controllers;
+
+/** Original implementation from wasp-os : https://github.com/daniel-thompson/wasp-os/blob/master/wasp/ppg.py */
+Ptagc::Ptagc(float start, float decay, float threshold) : peak{start}, decay{decay}, boost{1.0f/decay}, threshold{threshold} {
+
+}
+
+float Ptagc::Step(float spl) {
+ if(std::abs(spl) > peak)
+ peak *= boost;
+ else
+ peak *= decay;
+
+ if((spl > (peak * threshold)) || (spl < (peak * -threshold)))
+ return 0.0f;
+
+ spl = 100.0f * spl / (2.0f * peak);
+ return spl;
+}