1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/sfr04: Fixed int overflow for AVR (arduino board)

This commit is contained in:
Gilles Diribarne 2020-11-22 22:58:51 +01:00
parent 979eeed81a
commit caa1ad822d
2 changed files with 6 additions and 4 deletions

View File

@ -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;

View File

@ -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);
}