2020-04-05 06:10:08 -07:00
|
|
|
#include "init.h"
|
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
|
2020-05-25 10:02:05 -07:00
|
|
|
#include "tunerstudio_outputs.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;
|
2020-01-12 00:25:23 -08:00
|
|
|
FunctionalSensor oilpSensor(SensorType::OilPressure, /* timeout = */ MS2NT(50));
|
2019-09-21 11:33:38 -07:00
|
|
|
|
2020-04-06 06:00:26 -07:00
|
|
|
void configureOilPressure(LinearFunc& func, const oil_pressure_config_s& cfg) {
|
2020-02-08 01:22:23 -08:00
|
|
|
float val1 = cfg.value1;
|
|
|
|
float val2 = cfg.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
|
2020-03-03 05:37:02 -08:00
|
|
|
func.configure(cfg.v1, val1, cfg.v2, val2, /*minOutput*/ -5, greaterOutput);
|
2020-02-08 01:22:23 -08:00
|
|
|
}
|
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
void initOilPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2019-09-21 11:33:38 -07:00
|
|
|
// Only register if we have a sensor
|
2020-04-05 06:10:08 -07:00
|
|
|
auto channel = CONFIG(oilPressure.hwChannel);
|
2019-09-21 11:33:38 -07:00
|
|
|
if (channel == EFI_ADC_NONE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-08 01:22:23 -08:00
|
|
|
configureOilPressure(oilpSensorFunc, CONFIG(oilPressure));
|
2019-09-25 04:26:56 -07:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2020-02-08 01:22:23 -08:00
|
|
|
|
2020-04-05 06:10:08 -07:00
|
|
|
void reconfigureOilPressure(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2020-02-08 01:22:23 -08:00
|
|
|
configureOilPressure(oilpSensorFunc, CONFIG(oilPressure));
|
|
|
|
}
|