Skip to content

Commit cfac07c

Browse files
committed
Wrap pulsein when maxlen is exceeded
1 parent 3401449 commit cfac07c

File tree

1 file changed

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

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,16 @@ void common_hal_pulseio_pulsein_interrupt() {
141141
}
142142
// ignore pulses that are too short
143143
if (result <= MAX_PULSE && result > MIN_PULSE) {
144-
self->buffer[buf_index] = (uint16_t) result;
145-
buf_index++;
146-
self->len++;
144+
self->buffer[buf_index] = (uint16_t) result;
145+
if (self->len < self->maxlen) {
146+
self->len++;
147+
}
148+
if (buf_index < self->maxlen) {
149+
buf_index++;
150+
} else {
151+
self->start = 0;
152+
buf_index = 0;
153+
}
147154
}
148155
}
149156
}

0 commit comments

Comments
 (0)