| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /** | |||
| 2 | * instant_rpm_calculator.h | |||
| 3 | */ | |||
| 4 | ||||
| 5 | #pragma once | |||
| 6 | #include "trigger_structure.h" | |||
| 7 | ||||
| 8 | class InstantRpmCalculator { | |||
| 9 | public: | |||
| 10 | InstantRpmCalculator(); | |||
| 11 | 566956 | float getInstantRpm() const { | ||
| 12 | 566956 | return m_instantRpm; | ||
| 13 | } | |||
| 14 | ||||
| 15 | #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT | |||
| 16 | void updateInstantRpm( | |||
| 17 | uint32_t current_index, | |||
| 18 | TriggerWaveform const & triggerShape, TriggerFormDetails *triggerFormDetails, | |||
| 19 | uint32_t index, efitick_t nowNt); | |||
| 20 | #endif | |||
| 21 | /** | |||
| 22 | * Update timeOfLastEvent[] on every trigger event - even without synchronization | |||
| 23 | * Needed for early spin-up RPM detection. | |||
| 24 | */ | |||
| 25 | void setLastEventTimeForInstantRpm(efitick_t nowNt); | |||
| 26 | ||||
| 27 | void movePreSynchTimestamps(); | |||
| 28 | ||||
| 29 | 238 | void resetInstantRpm() { | ||
| 30 | 238 | setArrayValues(timeOfLastEvent, 0); | ||
| 31 | 238 | setArrayValues(spinningEvents, 0); | ||
| 32 | 238 | spinningEventIndex = 0; | ||
| 33 | 238 | prevInstantRpmValue = 0; | ||
| 34 | 238 | m_instantRpm = 0; | ||
| 35 | 238 | } | ||
| 36 | ||||
| 37 | /** | |||
| 38 | * timestamp of each trigger wheel tooth | |||
| 39 | */ | |||
| 40 | uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; | |||
| 41 | ||||
| 42 | size_t spinningEventIndex = 0; | |||
| 43 | ||||
| 44 | // we might need up to one full trigger cycle of events - which on 60-2 means storage for ~120 | |||
| 45 | // todo: change the implementation to reuse 'timeOfLastEvent' | |||
| 46 | uint32_t spinningEvents[120]; | |||
| 47 | /** | |||
| 48 | * instant RPM calculated at this trigger wheel tooth | |||
| 49 | */ | |||
| 50 | float instantRpmValue[PWM_PHASE_MAX_COUNT]; | |||
| 51 | /** | |||
| 52 | * Stores last non-zero instant RPM value to fix early instability | |||
| 53 | */ | |||
| 54 | float prevInstantRpmValue = 0; | |||
| 55 | ||||
| 56 | ||||
| 57 | float m_instantRpm = 0; | |||
| 58 | private: | |||
| 59 | float calculateInstantRpm( | |||
| 60 | TriggerWaveform const & triggerShape, TriggerFormDetails *triggerFormDetails, | |||
| 61 | uint32_t index, efitick_t nowNt); | |||
| 62 | ||||
| 63 | float m_instantRpmRatio = 0; | |||
| 64 | }; | |||
| 65 |