Skip to content

Commit d93a9a1

Browse files
authored
Merge pull request #4683 from DavePutz/issue_4661
Issue #4661 - Wrap pulsein values when maxlen is exceeded.
2 parents 0573c17 + 1ec59cd commit d93a9a1

File tree

1 file changed

+9
-2
lines changed
  • ports/raspberrypi/common-hal/pulseio

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,15 @@ void common_hal_pulseio_pulsein_interrupt() {
142142
// ignore pulses that are too short
143143
if (result <= MAX_PULSE && result > MIN_PULSE) {
144144
self->buffer[buf_index] = (uint16_t) result;
145-
buf_index++;
146-
self->len++;
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)