From 5f3324cd6bc5bb8a29a8d070d5e634321434bb63 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 20 Jan 2022 23:32:59 -0500 Subject: [PATCH] migrating to SensorType::Rpm API --- firmware/controllers/algo/wall_fuel.cpp | 2 +- firmware/controllers/can/obd2.cpp | 2 +- firmware/controllers/engine_cycle/main_trigger_callback.cpp | 4 ++-- firmware/controllers/engine_cycle/map_averaging.cpp | 4 ++-- firmware/controllers/engine_cycle/rpm_calculator.cpp | 2 +- firmware/controllers/engine_cycle/spark_logic.cpp | 2 +- firmware/controllers/trigger/trigger_decoder.cpp | 2 +- unit_tests/engine_test_helper.cpp | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/algo/wall_fuel.cpp b/firmware/controllers/algo/wall_fuel.cpp index 1bf29aaeb9..97ab08f838 100644 --- a/firmware/controllers/algo/wall_fuel.cpp +++ b/firmware/controllers/algo/wall_fuel.cpp @@ -68,7 +68,7 @@ float WallFuel::adjust(float desiredMassGrams) { } // Ignore really slow RPM - int rpm = GET_RPM(); + int rpm = Sensor::getOrZero(SensorType::Rpm); if (rpm < 100) { return desiredMassGrams; } diff --git a/firmware/controllers/can/obd2.cpp b/firmware/controllers/can/obd2.cpp index 67644244e6..658442fc51 100644 --- a/firmware/controllers/can/obd2.cpp +++ b/firmware/controllers/can/obd2.cpp @@ -132,7 +132,7 @@ static void handleGetDataRequest(const CANRxFrame& rx) { obdSendValue(_1_MODE, pid, 1, Sensor::getOrZero(SensorType::Map)); break; case PID_RPM: - obdSendValue(_1_MODE, pid, 2, GET_RPM() * ODB_RPM_MULT); // rotation/min. (A*256+B)/4 + obdSendValue(_1_MODE, pid, 2, Sensor::getOrZero(SensorType::Rpm) * ODB_RPM_MULT); // rotation/min. (A*256+B)/4 break; case PID_SPEED: obdSendValue(_1_MODE, pid, 1, Sensor::getOrZero(SensorType::VehicleSpeed)); diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 048ab9fdf9..68e60bf14b 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -235,7 +235,7 @@ void InjectionEvent::onTriggerTooth(size_t trgEventIndex, int rpm, efitick_t now if (printFuelDebug) { InjectorOutputPin *output = outputs[0]; printf("handleFuelInjectionEvent fuelout %s injection_duration %dus engineCycleDuration=%.1fms\t\n", output->name, (int)durationUs, - (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM())) / 1000.0); + (int)MS2US(getCrankshaftRevolutionTimeMs(Sensor::getOrZero(SensorType::Rpm))) / 1000.0); } #endif /*EFI_PRINTF_FUEL_DETAILS */ @@ -550,7 +550,7 @@ void updatePrimeInjectionPulseState() { static void showMainInfo(Engine *engine) { #if EFI_PROD_CODE - int rpm = GET_RPM(); + int rpm = Sensor::getOrZero(SensorType::Rpm); float el = getFuelingLoad(); efiPrintf("rpm %d engine_load %.2f", rpm, el); efiPrintf("fuel %.2fms timing %.2f", engine->injectionDuration, engine->engineState.timingAdvance[0]); diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index 0f076f1dd7..416290f03d 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -172,7 +172,7 @@ void postMapState(TunerStudioOutputChannels *tsOutputChannels) { #endif /* EFI_TUNER_STUDIO */ void refreshMapAveragingPreCalc() { - int rpm = GET_RPM(); + int rpm = Sensor::getOrZero(SensorType::Rpm); if (isValidRpm(rpm)) { MAP_sensor_config_s * c = &engineConfiguration->map; angle_t start = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle); @@ -211,7 +211,7 @@ void mapAveragingTriggerCallback( if (index != (uint32_t)engineConfiguration->mapAveragingSchedulingAtIndex) return; - int rpm = GET_RPM(); + int rpm = Sensor::getOrZero(SensorType::Rpm); if (!isValidRpm(rpm)) { return; } diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 45487e514e..4f9338bf63 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -326,7 +326,7 @@ static void onTdcCallback(void *) { } #endif /* EFI_UNIT_TEST */ - itoa10(rpmBuffer, GET_RPM()); + itoa10(rpmBuffer, Sensor::getOrZero(SensorType::Rpm)); #if EFI_ENGINE_SNIFFER waveChart.startDataCollection(); #endif diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 1f0925e2ff..1576f05302 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -230,7 +230,7 @@ static void startDwellByTurningSparkPinHigh(IgnitionEvent *event, IgnitionOutput // todo: no reason for this to be disabled in unit_test mode?! #if ! EFI_UNIT_TEST - if (GET_RPM() > 2 * engineConfiguration->cranking.rpm) { + if (Sensor::getOrZero(SensorType::Rpm) > 2 * engineConfiguration->cranking.rpm) { const char *outputName = output->getName(); if (prevSparkName == outputName && getCurrentIgnitionMode() != IM_ONE_COIL) { warning(CUSTOM_OBD_SKIPPED_SPARK, "looks like skipped spark event %d %s", getRevolutionCounter(), outputName); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 346ce7ce71..28a990300b 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -606,7 +606,7 @@ void TriggerState::decodeTriggerEvent( } else { efiPrintf("%srpm=%d time=%d eventIndex=%d gapIndex=%d: gap=%.3f expected from %.3f to %.3f error=%s", triggerConfiguration.PrintPrefix, - GET_RPM(), + (int)Sensor::getOrZero(SensorType::Rpm), /* cast is needed to make sure we do not put 64 bit value to stack*/ (int)getTimeNowSeconds(), currentCycle.current_index, i, diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index b0bae5a851..ff6f90f48d 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -344,7 +344,7 @@ void EngineTestHelper::applyTriggerWaveform() { void EngineTestHelper::assertRpm(int expectedRpm, const char *msg) { Engine *engine = &this->engine; - EXPECT_EQ(expectedRpm, GET_RPM()) << msg; + EXPECT_EQ(expectedRpm, Sensor::getOrZero(SensorType::Rpm)) << msg; } void setupSimpleTestEngineWithMaf(EngineTestHelper *eth, injection_mode_e injectionMode,