From b5bde5c30766cf406728c5de2a216eb856da3542 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 20 Sep 2021 12:39:41 -0700 Subject: [PATCH] Turbo sensor (#3245) * outputs rpm * no msg param necessary * new sensor type * happy test --- .../sensors/converters/turbocharger_speed_converter.h | 8 +++++--- firmware/controllers/sensors/frequency_sensor.cpp | 4 ++-- firmware/controllers/sensors/frequency_sensor.h | 2 +- firmware/controllers/sensors/sensor.cpp | 2 ++ firmware/controllers/sensors/sensor_type.h | 4 +++- firmware/init/sensor/init_flex.cpp | 2 +- firmware/init/sensor/init_turbocharger_speed_sensor.cpp | 4 ++-- firmware/init/sensor/init_vehicle_speed_sensor.cpp | 3 +-- unit_tests/tests/sensor/test_frequency_sensor.cpp | 2 +- .../tests/sensor/test_turbocharger_speed_converter.cpp | 2 +- 10 files changed, 19 insertions(+), 14 deletions(-) diff --git a/firmware/controllers/sensors/converters/turbocharger_speed_converter.h b/firmware/controllers/sensors/converters/turbocharger_speed_converter.h index 5753a82d76..b6f07165f0 100644 --- a/firmware/controllers/sensors/converters/turbocharger_speed_converter.h +++ b/firmware/controllers/sensors/converters/turbocharger_speed_converter.h @@ -10,8 +10,10 @@ public: DECLARE_ENGINE_PTR; SensorResult convert(float frequency) const override { - auto speed = frequency * engineConfiguration->turboSpeedSensorMultiplier; - return speed; + auto hz = frequency * engineConfiguration->turboSpeedSensorMultiplier; + + auto rpm = hz * 60; + + return rpm; } }; - diff --git a/firmware/controllers/sensors/frequency_sensor.cpp b/firmware/controllers/sensors/frequency_sensor.cpp index 77869b0770..016102c4b5 100644 --- a/firmware/controllers/sensors/frequency_sensor.cpp +++ b/firmware/controllers/sensors/frequency_sensor.cpp @@ -14,12 +14,12 @@ static void freqSensorExtiCallback(void* arg) { inst->onEdge(getTimeNowNt()); } -void FrequencySensor::init(brain_pin_e pin, const char* const msg) { +void FrequencySensor::init(brain_pin_e pin) { m_pin = pin; #if EFI_PROD_CODE // todo: refactor https://github.com/rusefi/rusefi/issues/2123 - efiExtiEnablePin(msg, pin, + efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_FALLING_EDGE, freqSensorExtiCallback, reinterpret_cast(this)); #endif // EFI_PROD_CODE diff --git a/firmware/controllers/sensors/frequency_sensor.h b/firmware/controllers/sensors/frequency_sensor.h index e78803179f..3179778ddd 100644 --- a/firmware/controllers/sensors/frequency_sensor.h +++ b/firmware/controllers/sensors/frequency_sensor.h @@ -6,7 +6,7 @@ public: FrequencySensor(SensorType type, efitick_t timeoutPeriod) : FunctionalSensor(type, timeoutPeriod) { } - void init(brain_pin_e pin, const char* const msg); + void init(brain_pin_e pin); void deInit(); void onEdge(efitick_t nowNt); diff --git a/firmware/controllers/sensors/sensor.cpp b/firmware/controllers/sensors/sensor.cpp index 438f8373fc..cdd2960a14 100644 --- a/firmware/controllers/sensors/sensor.cpp +++ b/firmware/controllers/sensors/sensor.cpp @@ -51,6 +51,8 @@ static const char* const s_sensorNames[] = { "Aux 4", "Vehicle speed", + + "Turbo speed", }; // This struct represents one sensor in the registry. diff --git a/firmware/controllers/sensors/sensor_type.h b/firmware/controllers/sensors/sensor_type.h index 4e22eddfb4..073dd77176 100644 --- a/firmware/controllers/sensors/sensor_type.h +++ b/firmware/controllers/sensors/sensor_type.h @@ -75,6 +75,8 @@ enum class SensorType : unsigned char { VehicleSpeed = 34, + TurbochargerSpeed = 35, + // Leave me at the end! - PlaceholderLast = 35, + PlaceholderLast = 36, }; diff --git a/firmware/init/sensor/init_flex.cpp b/firmware/init/sensor/init_flex.cpp index 8a3a047bba..4fb7a89179 100644 --- a/firmware/init/sensor/init_flex.cpp +++ b/firmware/init/sensor/init_flex.cpp @@ -18,7 +18,7 @@ void initFlexSensor(DECLARE_CONFIG_PARAMETER_SIGNATURE) { } flexSensor.setFunction(converter); - flexSensor.init(pin, "flex"); + flexSensor.init(pin); flexSensor.Register(); } diff --git a/firmware/init/sensor/init_turbocharger_speed_sensor.cpp b/firmware/init/sensor/init_turbocharger_speed_sensor.cpp index 22306a9e30..6344d17714 100644 --- a/firmware/init/sensor/init_turbocharger_speed_sensor.cpp +++ b/firmware/init/sensor/init_turbocharger_speed_sensor.cpp @@ -4,7 +4,7 @@ #include "frequency_sensor.h" #include "turbocharger_speed_converter.h" -static FrequencySensor turbochargerSpeedSensor(SensorType::VehicleSpeed, MS2NT(500)); +static FrequencySensor turbochargerSpeedSensor(SensorType::TurbochargerSpeed, MS2NT(500)); static TurbochargerSpeedConverter turbochargerSpeedConverter; @@ -19,7 +19,7 @@ void initTurbochargerSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } turbochargerSpeedSensor.setFunction(turbochargerSpeedConverter); - turbochargerSpeedSensor.init(pin, "tcss"); + turbochargerSpeedSensor.init(pin); turbochargerSpeedSensor.Register(); } diff --git a/firmware/init/sensor/init_vehicle_speed_sensor.cpp b/firmware/init/sensor/init_vehicle_speed_sensor.cpp index 309a7f9319..43b2897f4d 100644 --- a/firmware/init/sensor/init_vehicle_speed_sensor.cpp +++ b/firmware/init/sensor/init_vehicle_speed_sensor.cpp @@ -7,7 +7,6 @@ static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500)); static VehicleSpeedConverter vehicleSpeedConverter; - void initVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { INJECT_ENGINE_REFERENCE(&vehicleSpeedConverter); @@ -19,7 +18,7 @@ void initVehicleSpeedSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } vehicleSpeedSensor.setFunction(vehicleSpeedConverter); - vehicleSpeedSensor.init(pin, "vss"); + vehicleSpeedSensor.init(pin); vehicleSpeedSensor.Register(); } diff --git a/unit_tests/tests/sensor/test_frequency_sensor.cpp b/unit_tests/tests/sensor/test_frequency_sensor.cpp index 3e4b044cc4..aa9942fc88 100644 --- a/unit_tests/tests/sensor/test_frequency_sensor.cpp +++ b/unit_tests/tests/sensor/test_frequency_sensor.cpp @@ -22,7 +22,7 @@ public: void SetUp() override { // If somehow prodcode will be unwrapped for test it MAYBE! will fire with error. // At least we must init FlexSensor somehow - dut.init(GPIO_INVALID, "Test"); + dut.init(GPIO_INVALID); dut.setFunction(identityFunc); } diff --git a/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp b/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp index 482eb54eaa..af82e97565 100644 --- a/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp +++ b/unit_tests/tests/sensor/test_turbocharger_speed_converter.cpp @@ -22,7 +22,7 @@ public: } float GetFrequencyBySpeedAndCoef(float speed, float coef) { - return (speed / coef); + return (speed / coef) / 60; } void TestForSpeedWithCoef(float expectedSpeed, float coef)