From ecfbb6af0496738c215d317b44267f736ef85af3 Mon Sep 17 00:00:00 2001 From: Pascal Lais Date: Mon, 3 Aug 2020 14:13:37 +0200 Subject: [PATCH] Update 'src/opst.cpp' --- src/opst.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/opst.cpp b/src/opst.cpp index c3ec669..d693652 100644 --- a/src/opst.cpp +++ b/src/opst.cpp @@ -84,15 +84,12 @@ void pwmInFallingEdgeISR() { mOpstFiFo.mData[mOpstFiFo.mIn].mFalling = micros(); mOpstFiFo.mIn++; + mOpstFiFo.mIn %= OPST_FIFO_SIZE; if(mOpstFiFo.mOut == mOpstFiFo.mIn) { mOpstFiFo.mOverrun = true; } - if(OPST_FIFO_SIZE <= mOpstFiFo.mIn) - { - mOpstFiFo.mIn = 0; - } attachInterrupt(digitalPinToInterrupt(mOpstPin), pwmInRisingEdgeISR, RISING); } @@ -131,14 +128,8 @@ void opstUpdate() uint32_t pulseInterval = 0; // time between rising edge of current pulse and rising edge of following pulse uint32_t pulseLen = 0; // time between rising edge of current pulse and falling edge of current pulse - if(OPST_FIFO_SIZE > (mOpstFiFo.mOut + 1)) - { - nextOut = mOpstFiFo.mOut + 1; - } - else - { - nextOut = 0; - } + nextOut = mOpstFiFo.mOut + 1; + nextOut %= OPST_FIFO_SIZE; pulseInterval = mOpstFiFo.mData[nextOut].mRising - mOpstFiFo.mData[mOpstFiFo.mOut].mRising; pulseLen = mOpstFiFo.mData[mOpstFiFo.mOut].mFalling - mOpstFiFo.mData[mOpstFiFo.mOut].mRising;