Merge pull request #4683 from DavePutz/issue_4661

Issue #4661 - Wrap pulsein values when maxlen is exceeded.
This commit is contained in:
Scott Shawcroft 2021-04-30 11:07:54 -07:00 committed by GitHub
commit d93a9a1dbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -142,8 +142,15 @@ void common_hal_pulseio_pulsein_interrupt() {
// ignore pulses that are too short
if (result <= MAX_PULSE && result > MIN_PULSE) {
self->buffer[buf_index] = (uint16_t) result;
buf_index++;
self->len++;
if (self->len < self->maxlen) {
self->len++;
}
if (buf_index < self->maxlen) {
buf_index++;
} else {
self->start = 0;
buf_index = 0;
}
}
}
}