Only allow O2 sensor readings when they sensor type is not disabled

This commit is contained in:
Josh Stewart 2019-06-05 18:22:19 +10:00
parent e524e8636a
commit c18b29b7d2
2 changed files with 21 additions and 10 deletions

View File

@ -1286,7 +1286,7 @@ menuDialog = main
menu = "Tools"
subMenu = mapCal, "Calibrate Pressure Sensors"
subMenu = std_ms2gentherm, "Calibrate Temperature Sensors", 0
subMenu = std_ms2geno2, "Calibrate AFR Sensor", 0
subMenu = std_ms2geno2, "Calibrate AFR Sensor", { egoType > 0 }
subMenu = sensorFilters, "Set analog sensor filters"
menuDialog = main
@ -1714,6 +1714,7 @@ menuDialog = main
dialog = egoControl, ""
topicHelp = "http://speeduino.com/wiki/index.php/AFR/O2"
field = "Sensor Type", egoType
field = "#Please ensure you calibrate your O2 sensor in the Tools menu", { egoType }
field = "Algorithm", egoAlgorithm, { egoType }
field = "Ignition Events per Step", egoCount, { egoType && (egoAlgorithm < 3) }
field = "Controller Auth +/-", egoLimit, { egoType && (egoAlgorithm < 3) }

View File

@ -360,15 +360,25 @@ void readBaro()
void readO2()
{
unsigned int tempReading;
#if defined(ANALOG_ISR)
tempReading = fastMap1023toX(AnChannel[pinO2-A0], 511); //Get the current O2 value.
#else
tempReading = analogRead(pinO2);
tempReading = fastMap1023toX(analogRead(pinO2), 511); //Get the current O2 value.
#endif
currentStatus.O2ADC = ADC_FILTER(tempReading, configPage4.ADCFILTER_O2, currentStatus.O2ADC);
currentStatus.O2 = o2CalibrationTable[currentStatus.O2ADC];
//An O2 read is only performed if an O2 sensor type is selected. This is to prevent potentially dangerous use of the O2 readings prior to proper setup/calibration
if(configPage6.egoType > 0)
{
unsigned int tempReading;
#if defined(ANALOG_ISR)
tempReading = fastMap1023toX(AnChannel[pinO2-A0], 511); //Get the current O2 value.
#else
tempReading = analogRead(pinO2);
tempReading = fastMap1023toX(analogRead(pinO2), 511); //Get the current O2 value.
#endif
currentStatus.O2ADC = ADC_FILTER(tempReading, configPage4.ADCFILTER_O2, currentStatus.O2ADC);
currentStatus.O2 = o2CalibrationTable[currentStatus.O2ADC];
}
else
{
currentStatus.O2ADC = 0;
currentStatus.O2 = 0;
}
}
void readO2_2()