diff options
Diffstat (limited to 'shared')
| -rw-r--r-- | shared/consts.h | 4 | ||||
| -rw-r--r-- | shared/util.c | 8 | ||||
| -rw-r--r-- | shared/util.h | 4 | 
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); |