diff options
Diffstat (limited to 'shared')
-rw-r--r-- | shared/consts.h | 2 | ||||
-rw-r--r-- | shared/errors.h | 2 | ||||
-rw-r--r-- | shared/util.h | 4 |
3 files changed, 8 insertions, 0 deletions
diff --git a/shared/consts.h b/shared/consts.h index f9d4c11..25ca94f 100644 --- a/shared/consts.h +++ b/shared/consts.h @@ -17,3 +17,5 @@ #define W2_SERIAL_READ_BUFFER_SIZE (255) /** exponential moving average new measurement weight (double 0-1) */ #define W2_EMA_WEIGHT (0.10) +/** size of mode history buffer */ +#define W2_MODE_HISTORY_BUFFER_SIZE (4) diff --git a/shared/errors.h b/shared/errors.h index 44b29a0..ac8e95f 100644 --- a/shared/errors.h +++ b/shared/errors.h @@ -47,6 +47,8 @@ typedef enum { W2_E_WARN_SERIAL_TIMEOUT = 0x08 | W2_E_TYPE_WARN, /** unknown message encountered (noisy channel?) */ W2_E_WARN_SERIAL_NOISY = 0x09 | W2_E_TYPE_WARN, + /** mode history index out of bounds */ + W2_E_WARN_MODE_HISTORY_BUFFER_IOB = 0x0a | W2_E_TYPE_WARN, } w2_e_errorcode; /** diff --git a/shared/util.h b/shared/util.h index 95f4c68..9e4d8ac 100644 --- a/shared/util.h +++ b/shared/util.h @@ -1,3 +1,7 @@ #pragma once +#define W2_MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define W2_MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define W2_RANGE(min, val, max) W2_MIN(max, W2_MAX(val, min)) + unsigned long w2_util_exp_mov_avg(unsigned long current_avg, unsigned long new_meas); |