aboutsummaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-05-26 12:42:34 +0200
committerlonkaars <loek@pipeframe.xyz>2022-05-26 12:42:34 +0200
commitf353e78916a57fe21084fe34fd80c13ae4844d32 (patch)
tree392a8d6bfccad7beb70e253ad7c1786934d5657b /shared
parent54b69efe150e1a102faafb4e214159c92abbb841 (diff)
implement info command
Diffstat (limited to 'shared')
-rw-r--r--shared/consts.h2
-rw-r--r--shared/util.c6
-rw-r--r--shared/util.h3
3 files changed, 11 insertions, 0 deletions
diff --git a/shared/consts.h b/shared/consts.h
index 70efcac..f9d4c11 100644
--- a/shared/consts.h
+++ b/shared/consts.h
@@ -15,3 +15,5 @@
#define W2_SERCOMM_BUFFER_SIZE (16)
/** size of input (receive) buffer (in bytes) */
#define W2_SERIAL_READ_BUFFER_SIZE (255)
+/** exponential moving average new measurement weight (double 0-1) */
+#define W2_EMA_WEIGHT (0.10)
diff --git a/shared/util.c b/shared/util.c
new file mode 100644
index 0000000..55f3491
--- /dev/null
+++ b/shared/util.c
@@ -0,0 +1,6 @@
+#include "consts.h"
+
+unsigned long w2_util_exp_mov_avg(unsigned long current_avg, unsigned long new_meas) {
+ return (unsigned long)((((double)(current_avg)) * ((double)(1.f - W2_EMA_WEIGHT))) +
+ (((double)(new_meas)) * ((double)(W2_EMA_WEIGHT))));
+}
diff --git a/shared/util.h b/shared/util.h
new file mode 100644
index 0000000..95f4c68
--- /dev/null
+++ b/shared/util.h
@@ -0,0 +1,3 @@
+#pragma once
+
+unsigned long w2_util_exp_mov_avg(unsigned long current_avg, unsigned long new_meas);