From c7f558138210d77bee038f33afcd649f222a2606 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 13 Jan 2019 23:20:19 -0500 Subject: [PATCH] enjoying C++11 --- firmware/controllers/trigger/rpm_calculator.cpp | 9 ++------- firmware/controllers/trigger/rpm_calculator.h | 14 +++++++------- firmware/controllers/trigger/trigger_decoder.cpp | 2 -- firmware/controllers/trigger/trigger_decoder.h | 4 ++-- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index dd8bd4d49c..173dc1fac5 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -54,16 +54,11 @@ RpmCalculator::RpmCalculator() { mockRpm = MOCK_UNDEFINED; #endif /* EFI_PROD_CODE */ // todo: reuse assignRpmValue() method which needs PASS_ENGINE_PARAMETER_SUFFIX - // which we cannot provide inside this parameter-less consutructor. need a solution for this minor mess - previousRpmValue = rpmValue = 0; - oneDegreeUs = NAN; - state = STOPPED; - isSpinning = false; + // which we cannot provide inside this parameter-less constructor. need a solution for this minor mess // we need this initial to have not_running at first invocation lastRpmEventTimeNt = (efitime_t) -10 * US2NT(US_PER_SECOND_LL); - revolutionCounterSinceStart = 0; - revolutionCounterSinceBootForUnitTest = revolutionCounterSinceBoot = 0; + revolutionCounterSinceBootForUnitTest = 0; lastRpmEventTimeNt = 0; oneDegreeUs = NAN; diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 23929cd85c..5d9a422d6a 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -121,16 +121,16 @@ public: * This is public because sometimes we cannot afford to call isRunning() and the value is good enough * Zero if engine is not running */ - volatile int rpmValue; + volatile int rpmValue = 0; /** * this is RPM on previous engine cycle. */ - int previousRpmValue; + int previousRpmValue = 0; /** * This is a performance optimization: let's pre-calculate this each time RPM changes * NaN while engine is not spinning */ - volatile floatus_t oneDegreeUs; + volatile floatus_t oneDegreeUs = NAN; volatile efitime_t lastRpmEventTimeNt; private: /** @@ -142,19 +142,19 @@ private: * This counter is incremented with each revolution of one of the shafts. Could be * crankshaft could be camshaft. */ - volatile uint32_t revolutionCounterSinceBoot; + volatile uint32_t revolutionCounterSinceBoot = 0; /** * Same as the above, but since the engine started spinning */ - volatile uint32_t revolutionCounterSinceStart; + volatile uint32_t revolutionCounterSinceStart = 0; - spinning_state_e state; + spinning_state_e state = STOPPED; /** * True if the engine is spinning (regardless of its state), i.e. if shaft position changes. * Needed by spinning-up logic. */ - bool isSpinning; + bool isSpinning = false; }; /** diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 5a699633fc..2b384c804a 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -126,8 +126,6 @@ int TriggerState::getTotalRevolutionCounter() { } TriggerStateWithRunningStatistics::TriggerStateWithRunningStatistics() { - instantRpm = 0; - prevInstantRpmValue = 0; // avoid ill-defined instant RPM when the data is not gathered yet efitime_t nowNt = getTimeNowNt(); for (int i = 0; i < PWM_PHASE_MAX_COUNT; i++) { diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 97b911e538..34db4c155e 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -122,7 +122,7 @@ private: class TriggerStateWithRunningStatistics : public TriggerState { public: TriggerStateWithRunningStatistics(); - float instantRpm; + float instantRpm = 0; /** * timestamp of each trigger wheel tooth */ @@ -134,7 +134,7 @@ public: /** * Stores last non-zero instant RPM value to fix early instability */ - float prevInstantRpmValue; + float prevInstantRpmValue = 0; float calculateInstantRpm(int *prevIndex, efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX); virtual void runtimeStatistics(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX); /**