From f7282966d2f39a4693821ecd58746bc5604a792a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 7 Feb 2020 01:05:16 -0800 Subject: [PATCH] Consume new tps in status_loop.cpp, settings.cpp (#1129) * new tps * more * settings.cpp too * more * comment --- firmware/console/status_loop.cpp | 20 ++++++++++++-------- firmware/controllers/sensors/sensor.h | 5 +++++ firmware/controllers/settings.cpp | 15 +++++++-------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 7b4e4b037c..2c4d452e26 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -209,8 +209,10 @@ static void printSensors(Logging *log) { if (hasCltSensor()) { reportSensorF(log, "CLT", "C", getCoolantTemperature(), 2); // log column #4 } - if (hasTpsSensor()) { - reportSensorF(log, "TPS", "%", getTPS(PASS_ENGINE_PARAMETER_SIGNATURE), 2); // log column #5 + + SensorResult tps = Sensor::get(SensorType::Tps1); + if (tps) { + reportSensorF(log, "TPS", "%", tps.Value, 2); // log column #5 } if (hasIatSensor()) { @@ -704,7 +706,6 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ executorStatistics(); #endif /* EFI_PROD_CODE */ - float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); float coolant = getCoolantTemperature(); float intake = getIntakeAirTemperature(); @@ -719,8 +720,12 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->coolantTemperature = coolant; // offset 8 tsOutputChannels->intakeAirTemperature = intake; - // offset 12 - tsOutputChannels->throttlePosition = tps; + + SensorResult tps = Sensor::get(SensorType::Tps1); + tsOutputChannels->throttlePosition = tps.Value; + tsOutputChannels->isTpsError = !tps.Valid; + tsOutputChannels->tpsADC = convertVoltageTo10bitADC(Sensor::getRaw(SensorType::Tps1)); + // offset 16 tsOutputChannels->massAirFlowVoltage = hasMafSensor() ? getMafVoltage(PASS_ENGINE_PARAMETER_SIGNATURE) : 0; @@ -734,8 +739,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ // offset 28 tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE); } - // offset 32 - tsOutputChannels->tpsADC = getTPS10bitAdc(0 PASS_ENGINE_PARAMETER_SUFFIX); + // offset 36 #if EFI_ANALOG_SENSORS tsOutputChannels->baroPressure = hasBaroSensor() ? getBaroPressure() : 0; @@ -992,7 +996,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ #endif /* EFI_CAN_SUPPORT */ case DBG_ANALOG_INPUTS: tsOutputChannels->debugFloatField1 = (engineConfiguration->vbattAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("vbatt", engineConfiguration->vbattAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f; - tsOutputChannels->debugFloatField2 = (engineConfiguration->tps1_1AdcChannel != EFI_ADC_NONE) ? getVoltageDivided("tps", engineConfiguration->tps1_1AdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f; + tsOutputChannels->debugFloatField2 = Sensor::getRaw(SensorType::Tps1); tsOutputChannels->debugFloatField3 = (engineConfiguration->mafAdcChannel != EFI_ADC_NONE) ? getVoltageDivided("maf", engineConfiguration->mafAdcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f; tsOutputChannels->debugFloatField4 = (engineConfiguration->map.sensor.hwChannel != EFI_ADC_NONE) ? getVoltageDivided("map", engineConfiguration->map.sensor.hwChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f; tsOutputChannels->debugFloatField5 = (engineConfiguration->clt.adcChannel != EFI_ADC_NONE) ? getVoltageDivided("clt", engineConfiguration->clt.adcChannel PASS_ENGINE_PARAMETER_SUFFIX) : 0.0f; diff --git a/firmware/controllers/sensors/sensor.h b/firmware/controllers/sensors/sensor.h index 9a3caf232c..fac4229b33 100644 --- a/firmware/controllers/sensors/sensor.h +++ b/firmware/controllers/sensors/sensor.h @@ -54,6 +54,11 @@ struct SensorResult { const bool Valid; const float Value; + + // Implicit conversion operator to bool, so you can do things like if (myResult) { ... } + constexpr explicit operator bool() const { + return Valid; + } }; // Fwd declare - nobody outside of Sensor.cpp needs to see inside this type diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 2fa359dcc4..d9dc83d556 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -16,7 +16,6 @@ #include "thermistors.h" #include "adc_inputs.h" #include "interpolation.h" -#include "tps.h" #include "map.h" #include "trigger_decoder.h" #include "console_io.h" @@ -27,6 +26,7 @@ #include "allsensors.h" #include "alternator_controller.h" #include "trigger_emulator.h" +#include "sensor.h" #if EFI_PROD_CODE #include "vehicle_speed.h" @@ -408,15 +408,17 @@ static void printThermistor(const char *msg, ThermistorConf *config, ThermistorM } void printTPSInfo(void) { -#if EFI_PROD_CODE && HAL_USE_ADC - if (!hasTpsSensor()) { + auto tps = Sensor::get(SensorType::Tps1); + auto raw = Sensor::getRaw(SensorType::Tps1); + + if (!tps.Valid) { scheduleMsg(&logger, "NO TPS SENSOR"); return; } static char pinNameBuffer[16]; scheduleMsg(&logger, "tps min (closed) %d/max (full) %d v=%.2f @%s", engineConfiguration->tpsMin, engineConfiguration->tpsMax, - getTPSVoltage(PASS_ENGINE_PARAMETER_SIGNATURE), getPinNameByAdcChannel("tps", engineConfiguration->tps1_1AdcChannel, pinNameBuffer)); + raw, getPinNameByAdcChannel("tps", engineConfiguration->tps1_1AdcChannel, pinNameBuffer)); if (hasPedalPositionSensor()) { scheduleMsg(&logger, "pedal up %f / down %f", @@ -424,10 +426,7 @@ void printTPSInfo(void) { engineConfiguration->throttlePedalWOTVoltage); } - -#endif /* EFI_PROD_CODE */ - scheduleMsg(&logger, "current 10bit=%d value=%.2f rate=%.2f", (int)getTPS10bitAdc(0), getTPS(PASS_ENGINE_PARAMETER_SIGNATURE), - getTpsRateOfChange()); + scheduleMsg(&logger, "current 10bit=%d value=%.2f rate=%.2f", convertVoltageTo10bitADC(raw), tps.Value, getTpsRateOfChange()); } static void printTemperatureInfo(void) {