Tweaks from jepler

This commit is contained in:
Scott Shawcroft 2020-04-14 17:09:48 -07:00
parent a6fb0beaa9
commit 7dfcae6067
No known key found for this signature in database
GPG Key ID: 9349BC7E64B1921E

View File

@ -79,12 +79,9 @@ static void pulsein_handler(uint8_t num) {
self->first_edge = false; self->first_edge = false;
} }
} else { } else {
uint32_t total_diff = current_count + 0xffff * (current_overflow - self->last_overflow) - self->last_count; uint32_t total_diff = current_count + 0x10000 * (current_overflow - self->last_overflow) - self->last_count;
// Cap duration at 16 bits. // Cap duration at 16 bits.
uint16_t duration = 0xffff; uint16_t duration = MIN(0xffff, total_diff);
if (total_diff < duration) {
duration = total_diff;
}
uint16_t i = (self->start + self->len) % self->maxlen; uint16_t i = (self->start + self->len) % self->maxlen;
self->buffer[i] = duration; self->buffer[i] = duration;