From caa1ad822db9c028283fb9d9176204fe5fbd9797 Mon Sep 17 00:00:00 2001 From: Gilles Diribarne Date: Sun, 22 Nov 2020 22:58:51 +0100 Subject: [PATCH] drivers/sfr04: Fixed int overflow for AVR (arduino board) --- drivers/include/srf04.h | 2 +- drivers/srf04/srf04.c | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/include/srf04.h b/drivers/include/srf04.h index 3856b34f0f..6e985e9851 100644 --- a/drivers/include/srf04.h +++ b/drivers/include/srf04.h @@ -54,7 +54,7 @@ typedef struct { */ typedef struct { srf04_params_t p; /**< GPIO Ports of device */ - int distance; /**< raw time of flight distance */ + int32_t distance; /**< raw time of flight distance */ uint32_t time; /**< timestamp of trigger or echo */ } srf04_t; diff --git a/drivers/srf04/srf04.c b/drivers/srf04/srf04.c index ae8f36615d..560e1e647e 100644 --- a/drivers/srf04/srf04.c +++ b/drivers/srf04/srf04.c @@ -83,11 +83,13 @@ int srf04_read(const srf04_t* dev) int srf04_get_distance(const srf04_t* dev) { - /* trigger new reading */ + /* Trigger new reading */ srf04_trigger(dev); - /* give the sensor the required time for sampling */ + + /* Give the sensor the required time for sampling */ xtimer_usleep(SRF04_SAMPLE_PERIOD); - /* get the result */ + + /* Get the result */ if (dev->distance >= SRF04_OK) { return ((dev->distance * 100) / SRF04_DISTANCE); }