rusEFI
The most advanced open source ECU
peak_detect.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "rusefi_types.h"
4 
5 /**
6  * Stores the recent peak value, preventing loss of intermittent peaks in a signal.
7  */
8 template <typename TValue, efidur_t TTimeoutPeriod>
9 class PeakDetect {
10 public:
11  TValue detect(TValue currentValue, efitick_t nowNt) {
12  if ((nowNt > m_lastPeakTime + TTimeoutPeriod) || // if timed out
13  (currentValue > m_peak)) { // or current is higher than the previous peak
14  // store new peak and time
15  m_peak = currentValue;
16  m_lastPeakTime = nowNt;
17  }
18 
19  return m_peak;
20  }
21 
22 private:
23  TValue m_peak = std::numeric_limits<TValue>::min();
24  efitick_t m_lastPeakTime = std::numeric_limits<efitick_t>::min();
25 };
efitick_t m_lastPeakTime
Definition: peak_detect.h:24
TValue detect(TValue currentValue, efitick_t nowNt)
Definition: peak_detect.h:11
TValue m_peak
Definition: peak_detect.h:23