2019-09-21 11:33:38 -07:00
|
|
|
#include "adc_subscription.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "error_handling.h"
|
|
|
|
#include "global.h"
|
2019-09-24 18:11:41 -07:00
|
|
|
#include "functional_sensor.h"
|
|
|
|
#include "linear_func.h"
|
2019-11-07 12:22:17 -08:00
|
|
|
#if EFI_TUNER_STUDIO
|
2019-09-21 11:33:38 -07:00
|
|
|
#include "tunerstudio_configuration.h"
|
2019-11-06 17:33:40 -08:00
|
|
|
#endif
|
2019-09-21 11:33:38 -07:00
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
2019-09-25 04:26:56 -07:00
|
|
|
LinearFunc oilpSensorFunc;
|
|
|
|
FunctionalSensor oilpSensor(SensorType::OilPressure);
|
2019-09-21 11:33:38 -07:00
|
|
|
|
|
|
|
void initOilPressure() {
|
|
|
|
// Only register if we have a sensor
|
|
|
|
auto channel = engineConfiguration->oilPressure.hwChannel;
|
|
|
|
if (channel == EFI_ADC_NONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
oil_pressure_config_s *sensorCfg = &CONFIG(oilPressure);
|
|
|
|
|
|
|
|
float val1 = sensorCfg->value1;
|
|
|
|
float val2 = sensorCfg->value2;
|
|
|
|
|
|
|
|
// Limit to max given pressure - val1 or val2 could be larger
|
|
|
|
// (sensor may be backwards, high voltage = low pressure)
|
|
|
|
float greaterOutput = val1 > val2 ? val1 : val2;
|
|
|
|
|
|
|
|
// Allow slightly negative output (-5kpa) so as to not fail the sensor when engine is off
|
2019-09-25 04:26:56 -07:00
|
|
|
oilpSensorFunc.configure(sensorCfg->v1, val1, sensorCfg->v2, val2, /*minOutput*/ -5, greaterOutput);
|
|
|
|
oilpSensor.setFunction(oilpSensorFunc);
|
2019-09-21 11:33:38 -07:00
|
|
|
|
|
|
|
// Subscribe the sensor to the ADC
|
|
|
|
AdcSubscription::SubscribeSensor(oilpSensor, channel);
|
|
|
|
|
|
|
|
if (!oilpSensor.Register()) {
|
|
|
|
warning(OBD_Oil_Pressure_Sensor_Malfunction, "Duplicate oilp sensor registration, ignoring");
|
|
|
|
}
|
|
|
|
}
|