Skip to content

Commit 3db0fec

Browse files
committed
Added check for maxlen
1 parent a4dda3a commit 3db0fec

File tree

1 file changed

+3
-4
lines changed
  • ports/raspberrypi/common-hal/pulseio

1 file changed

+3
-4
lines changed

ports/raspberrypi/common-hal/pulseio/PulseIn.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,19 @@ void common_hal_pulseio_pulsein_interrupt() {
152152
last_level = level;
153153
level_count = 1;
154154
// ignore pulses that are too long and too short
155-
if (result < 2000 && result > 10) {
155+
if (result < 4000 && result > 10) {
156156
self->buffer[buf_index] = result;
157157
buf_index++;
158158
self->len++;
159159
}
160160
}
161161
}
162-
gpio_put(pin_GPIO15.number, true);
163162
// clear interrupt
164163
irq_clear(self->pio_interrupt);
165164
hw_clear_bits(&self->state_machine.pio->inte0, 1u << self->state_machine.state_machine);
166165
self->state_machine.pio->irq = 1u << self->state_machine.state_machine;
167-
// check for a pulse thats too long (2000 us) and reset
168-
if ( level_count > 2000 ) {
166+
// check for a pulse thats too long (2000 us) or maxlen reached, and reset
167+
if (( level_count > 4000 ) || (buf_index >= self->maxlen)) {
169168
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false);
170169
pio_sm_init(self->state_machine.pio, self->state_machine.state_machine, self->state_machine.offset, &self->state_machine.sm_config);
171170
pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine);

0 commit comments

Comments
 (0)