rusefi/firmware/controllers/sensors/frequency_sensor.cpp

45 lines
954 B
C++
Raw Normal View History

/**
* @file frequency_sensor.cpp
*/
#include "pch.h"
#include "frequency_sensor.h"
#include "digital_input_exti.h"
// Callback adapter since we can't pass a member function to a callback
static void freqSensorExtiCallback(void* arg) {
auto inst = reinterpret_cast<FrequencySensor*>(arg);
inst->onEdge(getTimeNowNt());
}
Vehicle speed switching to frequency sensor #3106 (#3148) * Add vehicle_speed_converter.h with realization. * Add test_vehicle_speed_converter.cpp with realization. * Add test_vehicle_speed_converter.cpp to Makefile * Edit "VehicleSpeedSensor" from function pointer sensor to frequency sensor * Fix "VehicleSpeedSensor" init function args * Remove "VehicleSpeedConverter" empty constructor * Edit vehicle_speed_converter.h code style * Fix args and engine injection in "VehicleSpeedSensor" initialization procedure * Remove old "Vehicle Speed" module initialization * Revert "Remove old "Vehicle Speed" module initialization" This reverts commit 100b7caa8c615c20eed3d0c23a49824b4e556148. * Remove old "Vehicle Speed" module initialization pieces * Revert "Revert "Remove old "Vehicle Speed" module initialization"" This reverts commit f559a726f1f7f5a7acacd1b6517e571743e84327. * Debug changes * Revert "Debug changes" This reverts commit f7e2be1a8a46c6f3f93f14f002b2f2db539da8e2. * Another debug changes * More debug changes * And more debug changes. * Revert "Another debug changes" This reverts commit 914fbb1df42c37e4b5ecbb119bb45e7cffdf4064. * Revert "More debug changes" This reverts commit 0b2d96d461c3cd9b0f1ae97ed110b8effe6b0cc6. * Revert "And more debug changes." This reverts commit 06ae8daded0e6e1c025e4e5058b47283f4adfe92. * Add "Vehicle Speed" sensor reconfiguration * Revert "Add "Vehicle Speed" sensor reconfiguration" This reverts commit a089a6d563dd710004ce1a7da1744b0b4b90c3b1. * Revert "Revert "Add "Vehicle Speed" sensor reconfiguration"" This reverts commit 7b2bb8af4b3caa547236ca59e4c4bdb3ac1200cc. * Debug changes * Another debug changes * Fix another debug changes * Another debug changes 2 * Revert "Another debug changes 2" This reverts commit cfad55141eec125b2f1d35fb95d9f46b54f666b6. * Revert "Fix another debug changes" This reverts commit 9bc2c74a3be6fd896827ff48cf4580e7657529c0. * Revert "Another debug changes" This reverts commit 4337ed8cad8dff508d093944eb3f75e9a69e4a77. * Edit class FrequencySensor, make it more RAII * Debug changes * Debug changes 2 * Debug changes 3 * Revert "Debug changes 3" This reverts commit 52a7054c122b5157540fe45a055a84b57478d722. * Revert "Debug changes 2" This reverts commit dec79fb913344ccb4b8614910ad62e6c129a243e. * Revert "Debug changes" This reverts commit eb08d7a529b55ba397a7dd2c154b76eab42f212b. * Revert "Edit class FrequencySensor, make it more RAII" This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Citroen Berlingo" engine config. This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Dodge Neon" engine config Co-authored-by: alxrMironov <330OMcorporative>
2021-08-23 21:55:41 -07:00
void FrequencySensor::init(brain_pin_e pin, const char* const msg) {
m_pin = pin;
#if EFI_PROD_CODE
// todo: refactor https://github.com/rusefi/rusefi/issues/2123
Vehicle speed switching to frequency sensor #3106 (#3148) * Add vehicle_speed_converter.h with realization. * Add test_vehicle_speed_converter.cpp with realization. * Add test_vehicle_speed_converter.cpp to Makefile * Edit "VehicleSpeedSensor" from function pointer sensor to frequency sensor * Fix "VehicleSpeedSensor" init function args * Remove "VehicleSpeedConverter" empty constructor * Edit vehicle_speed_converter.h code style * Fix args and engine injection in "VehicleSpeedSensor" initialization procedure * Remove old "Vehicle Speed" module initialization * Revert "Remove old "Vehicle Speed" module initialization" This reverts commit 100b7caa8c615c20eed3d0c23a49824b4e556148. * Remove old "Vehicle Speed" module initialization pieces * Revert "Revert "Remove old "Vehicle Speed" module initialization"" This reverts commit f559a726f1f7f5a7acacd1b6517e571743e84327. * Debug changes * Revert "Debug changes" This reverts commit f7e2be1a8a46c6f3f93f14f002b2f2db539da8e2. * Another debug changes * More debug changes * And more debug changes. * Revert "Another debug changes" This reverts commit 914fbb1df42c37e4b5ecbb119bb45e7cffdf4064. * Revert "More debug changes" This reverts commit 0b2d96d461c3cd9b0f1ae97ed110b8effe6b0cc6. * Revert "And more debug changes." This reverts commit 06ae8daded0e6e1c025e4e5058b47283f4adfe92. * Add "Vehicle Speed" sensor reconfiguration * Revert "Add "Vehicle Speed" sensor reconfiguration" This reverts commit a089a6d563dd710004ce1a7da1744b0b4b90c3b1. * Revert "Revert "Add "Vehicle Speed" sensor reconfiguration"" This reverts commit 7b2bb8af4b3caa547236ca59e4c4bdb3ac1200cc. * Debug changes * Another debug changes * Fix another debug changes * Another debug changes 2 * Revert "Another debug changes 2" This reverts commit cfad55141eec125b2f1d35fb95d9f46b54f666b6. * Revert "Fix another debug changes" This reverts commit 9bc2c74a3be6fd896827ff48cf4580e7657529c0. * Revert "Another debug changes" This reverts commit 4337ed8cad8dff508d093944eb3f75e9a69e4a77. * Edit class FrequencySensor, make it more RAII * Debug changes * Debug changes 2 * Debug changes 3 * Revert "Debug changes 3" This reverts commit 52a7054c122b5157540fe45a055a84b57478d722. * Revert "Debug changes 2" This reverts commit dec79fb913344ccb4b8614910ad62e6c129a243e. * Revert "Debug changes" This reverts commit eb08d7a529b55ba397a7dd2c154b76eab42f212b. * Revert "Edit class FrequencySensor, make it more RAII" This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Citroen Berlingo" engine config. This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Dodge Neon" engine config Co-authored-by: alxrMironov <330OMcorporative>
2021-08-23 21:55:41 -07:00
efiExtiEnablePin(msg, pin,
PAL_EVENT_MODE_FALLING_EDGE,
freqSensorExtiCallback, reinterpret_cast<void*>(this));
#endif // EFI_PROD_CODE
}
void FrequencySensor::deInit() {
if (!isBrainPinValid(m_pin)) {
return;
}
#if EFI_PROD_CODE
efiExtiDisablePin(m_pin);
#endif
m_pin = GPIO_UNASSIGNED;
}
void FrequencySensor::onEdge(efitick_t nowNt) {
float frequency = 1 / m_edgeTimer.getElapsedSecondsAndReset(nowNt);
postRawValue(frequency, nowNt);
}