summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <siehputz@gmail.com>2021-03-08 23:20:57 -0600
committerroot <siehputz@gmail.com>2021-03-08 23:20:57 -0600
commit3db0fec267902cddb4d88aaca55e7ae7f59dc9a8 (patch)
tree0debf2611a25dbb9a443d7a0f7847952dd92b8c3
parenta4dda3a5ba4176f8175b96f3c6daf7626f7a65d6 (diff)
Added check for maxlen
-rw-r--r--ports/raspberrypi/common-hal/pulseio/PulseIn.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c
index 7053b5524..b9052f3c6 100644
--- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c
+++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c
@@ -152,20 +152,19 @@ void common_hal_pulseio_pulsein_interrupt() {
last_level = level;
level_count = 1;
// ignore pulses that are too long and too short
- if (result < 2000 && result > 10) {
+ if (result < 4000 && result > 10) {
self->buffer[buf_index] = result;
buf_index++;
self->len++;
}
}
}
- gpio_put(pin_GPIO15.number, true);
// clear interrupt
irq_clear(self->pio_interrupt);
hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine);
self->state_machine.pio->irq = 1u << self->state_machine.state_machine;
-// check for a pulse thats too long (2000 us) and reset
- if ( level_count > 2000 ) {
+// check for a pulse thats too long (2000 us) or maxlen reached, and reset
+ if (( level_count > 4000 ) || (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);