From ddc9971a2a410fae954c505988fc37ea6f06d5b6 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 29 Nov 2022 20:11:29 -0500 Subject: [PATCH] refactoring: extracting method --- firmware/controllers/actuators/electronic_throttle.cpp | 2 +- firmware/controllers/sensors/tps.cpp | 4 ++++ firmware/controllers/sensors/tps.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/actuators/electronic_throttle.cpp b/firmware/controllers/actuators/electronic_throttle.cpp index df43913724..be3a38a7b1 100644 --- a/firmware/controllers/actuators/electronic_throttle.cpp +++ b/firmware/controllers/actuators/electronic_throttle.cpp @@ -525,7 +525,7 @@ expected EtbController::getClosedLoop(percent_t target, percent_t obs prevOutput = output; // seems good enough to simply check for both TPS sensors - bool isInputError = !Sensor::get(SensorType::Tps1).Valid || isTps2Error() || isPedalError(); + bool isInputError = isTps1Error() || isTps2Error() || isPedalError(); // current basic implementation is to check for input error counter only while engine is not running // we can make this logic smarter one day later if (Sensor::getOrZero(SensorType::Rpm) == 0 && wasInputError != isInputError) { diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 50116f8820..4764ff2c84 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -34,6 +34,10 @@ void grabPedalIsWideOpen() { engine->outputChannels.calibrationValue2 = Sensor::getRaw(SensorType::AcceleratorPedalSecondary); } +bool isTps1Error() { + return !Sensor::get(SensorType::Tps1).Valid; +} + bool isTps2Error() { return !Sensor::get(SensorType::Tps2).Valid && Sensor::hasSensor(SensorType::Tps2Primary); } diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index f3cdc9781a..98fd2b26cc 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -24,5 +24,6 @@ void grabTPSIsWideOpen(); void grabPedalIsUp(); void grabPedalIsWideOpen(); +bool isTps1Error(); bool isTps2Error(); bool isPedalError();