From 605b9c6db70c931df4cf1dbd4f173ae06feb02d2 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Tue, 5 Mar 2024 23:39:55 +0300 Subject: [PATCH] hella_oil_level: check for errors, deInit() --- .../controllers/sensors/hella_oil_level.cpp | 23 +++++++++++++++---- .../controllers/sensors/hella_oil_level.h | 1 + 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/firmware/controllers/sensors/hella_oil_level.cpp b/firmware/controllers/sensors/hella_oil_level.cpp index 7496b2e222..dae77c6d63 100644 --- a/firmware/controllers/sensors/hella_oil_level.cpp +++ b/firmware/controllers/sensors/hella_oil_level.cpp @@ -15,17 +15,30 @@ void HellaOilLevelSensor::init(brain_pin_e pin) { return; } - m_pin = pin; - #if EFI_PROD_CODE - efiExtiEnablePin(getSensorName(), pin, - PAL_EVENT_MODE_BOTH_EDGES, - hellaSensorExtiCallback, reinterpret_cast(this)); + if (efiExtiEnablePin(getSensorName(), pin, PAL_EVENT_MODE_BOTH_EDGES, + hellaSensorExtiCallback, reinterpret_cast(this)) < 0) { + return; + } #endif // EFI_PROD_CODE + m_pin = pin; + Register(); } +void HellaOilLevelSensor::deInit() { + if (!isBrainPinValid(m_pin)) { + return; + } + +#if EFI_PROD_CODE + efiExtiDisablePin(m_pin); +#endif + + m_pin = Gpio::Unassigned; +} + void HellaOilLevelSensor::onEdge(efitick_t nowNt) { if (efiReadPin(m_pin)) { // Start pulse width timing at the rising edge diff --git a/firmware/controllers/sensors/hella_oil_level.h b/firmware/controllers/sensors/hella_oil_level.h index 0687f0f1f7..85c4fe942f 100644 --- a/firmware/controllers/sensors/hella_oil_level.h +++ b/firmware/controllers/sensors/hella_oil_level.h @@ -7,6 +7,7 @@ public: HellaOilLevelSensor(SensorType type) : StoredValueSensor(type, MS2NT(2000)) {} void init(brain_pin_e pin); + void deInit(); void onEdge(efitick_t nowNt);