From 8f40365a13fb62654f3d3494d35878cb7b00406a Mon Sep 17 00:00:00 2001 From: midilab Date: Thu, 5 Nov 2020 10:15:04 -0500 Subject: [PATCH] fix getTick() polling call to avoid ghost ticks --- src/uClock.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/uClock.cpp b/src/uClock.cpp index 9a1f419..8a2909d 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -219,7 +219,6 @@ void uClockClass::setSlaveDrift(uint8_t value) ATOMIC(slave_drift = value) } - uint8_t uClockClass::getDrift() { return drift; @@ -235,11 +234,17 @@ uint16_t uClockClass::getInterval() // Main poolling tick call uint8_t uClockClass::getTick(uint32_t * tick) { - ATOMIC(uint32_t last_tick = internal_tick) + ATOMIC( + uint32_t last_tick = internal_tick; + ) if (*tick != last_tick) { *tick = last_tick; return 1; } + if (last_tick - *tick > 1) { + *tick++; + return 1; + } return 0; } @@ -293,7 +298,7 @@ void uClockClass::handleExternalClock() last_clock = _clock; // accumulate interval incomming ticks data for getTempo() smooth reads on slave mode - ext_interval_buffer[ext_interval_idx++ % EXT_INTERVAL_BUFFER_SIZE] = last_interval; + ext_interval_buffer[ext_interval_idx++ % EXT_INTERVAL_BUFFER_SIZE] = last_interval; // slave tick me! external_tick++;