diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index e0f015b9f4..cc5fb0fb68 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -676,8 +676,8 @@ enum class ObdCode : uint16_t { //P0639 Throttle Actuator Control Range/Performance (Bank 2) //P0640 Intake Air Heater Control Circuit //P0641 Sensor Reference Voltage “A” Circuit/Open - //P0642 Sensor Reference Voltage “A” Circuit Low - //P0643 Sensor Reference Voltage “A” Circuit High + Sensor5vSupplyLow = 642, + Sensor5vSupplyHigh = 643, //P0644 Driver Display Serial Communication Circuit //P0645 A/C Clutch Relay Control Circuit //P0646 A/C Clutch Relay Control Circuit Low diff --git a/firmware/controllers/sensors/sensor_checker.cpp b/firmware/controllers/sensors/sensor_checker.cpp index 047d5d00ab..e52f9bf49a 100644 --- a/firmware/controllers/sensors/sensor_checker.cpp +++ b/firmware/controllers/sensors/sensor_checker.cpp @@ -147,17 +147,30 @@ static ObdCode getCodeForIgnition(int idx, brain_pin_diag_e diag) { #endif // BOARD_EXT_GPIOCHIPS > 0 && EFI_PROD_CODE void SensorChecker::onSlowCallback() { - bool batteryVoltageSufficient = Sensor::getOrZero(SensorType::BatteryVoltage) > 7.0f; - - // Don't check when: - // - battery voltage is too low for sensors to work - // - the ignition is off - // - ignition was just turned on (let things stabilize first) - // TODO: also inhibit checking if we just did a flash burn, since that blocks the ECU for a few seconds. - bool shouldCheck = batteryVoltageSufficient && m_ignitionIsOn && m_timeSinceIgnOff.hasElapsedSec(5); - m_analogSensorsShouldWork = shouldCheck; - if (!shouldCheck) { - return; + if (Sensor::hasSensor(SensorType::Sensor5vVoltage)) { + float sensorSupply = Sensor::getOrZero(SensorType::Sensor5vVoltage); + + // Inhibit checking if the sensor supply isn't OK, but register a warning for that instead + if (sensorSupply > 5.25f) { + warning(ObdCode::Sensor5vSupplyHigh, "5V sensor supply high: %.2f", sensorSupply); + return; + } else if (sensorSupply < 4.75f) { + warning(ObdCode::Sensor5vSupplyLow, "5V sensor supply low: %.2f", sensorSupply); + return; + } + } else { + bool batteryVoltageSufficient = Sensor::getOrZero(SensorType::BatteryVoltage) > 7.0f; + + // Don't check when: + // - battery voltage is too low for sensors to work + // - the ignition is off + // - ignition was just turned on (let things stabilize first) + // TODO: also inhibit checking if we just did a flash burn, since that blocks the ECU for a few seconds. + bool shouldCheck = batteryVoltageSufficient && m_ignitionIsOn && m_timeSinceIgnOff.hasElapsedSec(5); + m_analogSensorsShouldWork = shouldCheck; + if (!shouldCheck) { + return; + } } // Check sensors diff --git a/firmware/controllers/sensors/sensor_type.h b/firmware/controllers/sensors/sensor_type.h index dae96d6497..c31c6932ee 100644 --- a/firmware/controllers/sensors/sensor_type.h +++ b/firmware/controllers/sensors/sensor_type.h @@ -71,6 +71,7 @@ enum class SensorType : unsigned char { BatteryVoltage, MainRelayVoltage, + Sensor5vVoltage, BarometricPressure,