Skip to content

Commit a78a4c9

Browse files
committed
extmod/pupdevices/UltrasonicSensor: bind to 2000
Although higher values appear theoretically possible, they are not very accurate so we limit values to 2000 mm.
1 parent fda2d14 commit a78a4c9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

extmod/modpupdevices.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ STATIC mp_obj_t pupdevices_UltrasonicSensor_distance(mp_obj_t self_in) {
370370
pupdevices_UltrasonicSensor_obj_t *self = MP_OBJ_TO_PTR(self_in);
371371
int32_t distance;
372372
pbdevice_get_values(self->pbdev, PBIO_IODEV_MODE_PUP_ULTRASONIC_SENSOR__DISTL, &distance);
373-
return mp_obj_new_int(distance < 0 ? 3000 : distance);
373+
return mp_obj_new_int(distance < 0 || distance >= 2000 ? 2000 : distance);
374374
}
375375
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pupdevices_UltrasonicSensor_distance_obj, pupdevices_UltrasonicSensor_distance);
376376

0 commit comments

Comments
 (0)