fix getTick() polling call to avoid ghost ticks

pull/7/head
midilab 4 years ago
parent 5eb220db81
commit 8f40365a13
  1. 9
      src/uClock.cpp

@ -219,7 +219,6 @@ void uClockClass::setSlaveDrift(uint8_t value)
ATOMIC(slave_drift = value) ATOMIC(slave_drift = value)
} }
uint8_t uClockClass::getDrift() uint8_t uClockClass::getDrift()
{ {
return drift; return drift;
@ -235,11 +234,17 @@ uint16_t uClockClass::getInterval()
// Main poolling tick call // Main poolling tick call
uint8_t uClockClass::getTick(uint32_t * tick) 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) { if (*tick != last_tick) {
*tick = last_tick; *tick = last_tick;
return 1; return 1;
} }
if (last_tick - *tick > 1) {
*tick++;
return 1;
}
return 0; return 0;
} }

Loading…
Cancel
Save