Wrap pulsein when maxlen is exceeded

This commit is contained in:
root 2021-04-28 11:20:13 -05:00
parent 34014495d2
commit cfac07c1cc

View File

@ -141,9 +141,16 @@ 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++;
self->buffer[buf_index] = (uint16_t) result;
if (self->len < self->maxlen) {
self->len++;
}
if (buf_index < self->maxlen) {
buf_index++;
} else {
self->start = 0;
buf_index = 0;
}
}
}
}