summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-06-07 21:27:16 +0200
committerlonkaars <loek@pipeframe.xyz>2022-06-07 21:27:16 +0200
commit3e65c70da770fa31fc8acc6ab9374d908cf1ed17 (patch)
tree14f8d4c708faccc8b3f992a022f940c00ed694f9 /shared
parent8c8322a7a0c251d595a0df054324f82d41966e0a (diff)
implement orders
Diffstat (limited to 'shared')
-rw-r--r--shared/consts.h4
-rw-r--r--shared/util.c8
-rw-r--r--shared/util.h4
3 files changed, 16 insertions, 0 deletions
diff --git a/shared/consts.h b/shared/consts.h
index cd6dff1..11e6d14 100644
--- a/shared/consts.h
+++ b/shared/consts.h
@@ -35,6 +35,10 @@
/** max time between ping and answer */
#define W2_PING_TIMEOUT (5e3)
+/** default map width/height */
+#define W2_MAP_DEFAULT_HEIGHT 5
+#define W2_MAP_DEFAULT_WIDTH 5
+
/** front-facing distance sensor pinout */
#define W2_FRONT_SENSOR_PIN 5
/** battery voltage sensor pinout */
diff --git a/shared/util.c b/shared/util.c
index 68503e8..641b4d9 100644
--- a/shared/util.c
+++ b/shared/util.c
@@ -6,3 +6,11 @@ unsigned long w2_util_exp_mov_avg(unsigned long current_avg, unsigned long new_m
}
int w2_sign(int n) { return (n > 0) - (n < 0); }
+
+unsigned int w2_newline_count(char *str, unsigned int len) {
+ unsigned int newlines = 0;
+ for (unsigned int i = 0; i < len; i++)
+ if (str[i] == '\n') newlines++;
+ return newlines;
+}
+
diff --git a/shared/util.h b/shared/util.h
index 230c3e4..806af3a 100644
--- a/shared/util.h
+++ b/shared/util.h
@@ -6,5 +6,9 @@
#define W2_MAX(a, b) (((a) > (b)) ? (a) : (b))
#define W2_RANGE(min, val, max) W2_MIN(max, W2_MAX(val, min))
+/** calculate exponential moving average */
unsigned long w2_util_exp_mov_avg(unsigned long current_avg, unsigned long new_meas);
+/** return the sign of a number (-1 or 1) */
int w2_sign(int n);
+/** return amount of newline characters */
+unsigned int w2_newline_count(char *str, unsigned int len);