summaryrefslogtreecommitdiff
path: root/src/components/heartrate/Ptagc.cpp
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-01-10 17:57:26 +0100
committerJean-François Milants <jf@codingfield.com>2021-01-10 17:57:26 +0100
commit1a582815ba218d2a9047abae92b9f33a3301ffd5 (patch)
tree18aa0aeba146d990a0302f4840e870cad1c4ad6f /src/components/heartrate/Ptagc.cpp
parent50ae0ae5e073ac48652e6c26549f9b19655e8da3 (diff)
First implementation of the HR sensor using 100% foss code (ported from waspos)
Diffstat (limited to 'src/components/heartrate/Ptagc.cpp')
-rw-r--r--src/components/heartrate/Ptagc.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/components/heartrate/Ptagc.cpp b/src/components/heartrate/Ptagc.cpp
new file mode 100644
index 00000000..9302af97
--- /dev/null
+++ b/src/components/heartrate/Ptagc.cpp
@@ -0,0 +1,21 @@
+#include <cmath>
+#include "Ptagc.h"
+
+using namespace Pinetime::Controllers;
+
+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;
+}