From 1a582815ba218d2a9047abae92b9f33a3301ffd5 Mon Sep 17 00:00:00 2001 From: Jean-François Milants Date: Sun, 10 Jan 2021 17:57:26 +0100 Subject: First implementation of the HR sensor using 100% foss code (ported from waspos) --- src/components/heartrate/Ptagc.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/components/heartrate/Ptagc.cpp (limited to 'src/components/heartrate/Ptagc.cpp') 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 +#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; +} -- cgit v1.2.3