File indexing completed on 2024-04-14 05:46:48
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 */ 0004 0005 #include "rsitimercounter.h" 0006 0007 #include <algorithm> 0008 0009 int RSITimerCounter::tick(const int idleTime) 0010 { 0011 m_counter++; 0012 0013 // Not idle for too long, time for a break. 0014 if (m_counter >= m_delayTicks) { 0015 reset(); 0016 return m_breakLength; 0017 } 0018 0019 // Idle for enough to consider the break has happened. 0020 if (idleTime >= m_resetThreshold) { 0021 reset(); 0022 return 0; 0023 } 0024 0025 // In-flight, not time for a break yet. 0026 return 0; 0027 } 0028 0029 bool RSITimerCounter::isReset() 0030 { 0031 return m_counter == 0; 0032 } 0033 0034 void RSITimerCounter::reset() 0035 { 0036 m_counter = 0; 0037 } 0038 0039 void RSITimerCounter::postpone(int ticks) 0040 { 0041 m_counter = std::max(0, m_delayTicks - ticks); 0042 } 0043 0044 int RSITimerCounter::counterLeft() const 0045 { 0046 return m_delayTicks - m_counter; 0047 } 0048 0049 int RSITimerCounter::getDelayTicks() const 0050 { 0051 return m_delayTicks; 0052 }