diff options
| author | Jean-François Milants <jf@codingfield.com> | 2021-01-10 16:57:26 (GMT) |
|---|---|---|
| committer | Jean-François Milants <jf@codingfield.com> | 2021-01-10 16:57:26 (GMT) |
| commit | 1a582815ba218d2a9047abae92b9f33a3301ffd5 (patch) | |
| tree | 18aa0aeba146d990a0302f4840e870cad1c4ad6f /src/components/heartrate/Ptagc.cpp | |
| parent | 50ae0ae5e073ac48652e6c26549f9b19655e8da3 (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.cpp | 21 |
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 0000000..9302af9 --- /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; +} |
