From 5bd1da21a29b4083cec50de08778aaa4b7c83456 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 25 Apr 2021 21:38:57 -0500 Subject: [PATCH] Increased possible pulsein length to 32 ms. --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 278c0cd662..0495cb1b1b 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -39,6 +39,8 @@ pulseio_pulsein_obj_t *save_self; #define NO_PIN 0xff +#define MAX_PULSE 32678 +#define MIN_PULSE 10 volatile bool last_level; volatile uint16_t level_count = 0; volatile uint16_t result = 0; @@ -139,15 +141,15 @@ void common_hal_pulseio_pulsein_interrupt() { last_level = level; level_count = 1; // ignore pulses that are too long and too short - if (result < 4000 && result > 10) { + if (result < MAX_PULSE && result > MIN_PULSE) { self->buffer[buf_index] = result; buf_index++; self->len++; } } } -// check for a pulse thats too long (4000 us) or maxlen reached, and reset - if ((level_count > 4000) || (buf_index >= self->maxlen)) { +// check for a pulse thats too long (MAX_PULSE us) or maxlen reached, and reset + if ((level_count > MAX_PULSE) || (buf_index >= self->maxlen)) { pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false); pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config); pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine); @@ -180,6 +182,7 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) { self->start = 0; self->len = 0; + buf_index = 0; } uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) {