2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2020-10-23 04:31:47 -07:00
|
|
|
#include "init.h"
|
|
|
|
#include "adc_subscription.h"
|
|
|
|
#include "functional_sensor.h"
|
2020-10-23 12:46:16 -07:00
|
|
|
#include "proxy_sensor.h"
|
2020-10-23 04:31:47 -07:00
|
|
|
#include "linear_func.h"
|
|
|
|
|
|
|
|
static LinearFunc oilpSensorFunc;
|
|
|
|
static FunctionalSensor oilpSensor(SensorType::OilPressure, /* timeout = */ MS2NT(50));
|
|
|
|
|
|
|
|
static LinearFunc fuelPressureFuncLow;
|
|
|
|
static FunctionalSensor fuelPressureSensorLow(SensorType::FuelPressureLow, /* timeout = */ MS2NT(50));
|
|
|
|
|
|
|
|
static LinearFunc fuelPressureFuncHigh;
|
|
|
|
static FunctionalSensor fuelPressureSensorHigh(SensorType::FuelPressureHigh, /* timeout = */ MS2NT(50));
|
|
|
|
|
2020-10-23 12:46:16 -07:00
|
|
|
static ProxySensor injectorPressure(SensorType::FuelPressureInjector);
|
|
|
|
|
2024-06-17 05:08:12 -07:00
|
|
|
static LinearFunc acPressureFunc;
|
|
|
|
static FunctionalSensor acPressureSensor(SensorType::AcPressure, /* timeout = */ MS2NT(50));
|
|
|
|
|
2022-03-20 17:13:04 -07:00
|
|
|
static LinearFunc auxLinear1Func;
|
|
|
|
static FunctionalSensor auxLinear1Sensor(SensorType::AuxLinear1, /* timeout = */ MS2NT(50));
|
|
|
|
|
|
|
|
static LinearFunc auxLinear2Func;
|
|
|
|
static FunctionalSensor auxLinear2Sensor(SensorType::AuxLinear2, /* timeout = */ MS2NT(50));
|
|
|
|
|
2020-10-27 21:07:34 -07:00
|
|
|
/**
|
|
|
|
* @param bandwidth Hertz, used by low pass filter in to analog subscribers
|
|
|
|
*/
|
2020-10-23 04:31:47 -07:00
|
|
|
static void initFluidPressure(LinearFunc& func, FunctionalSensor& sensor, const linear_sensor_s& cfg, float bandwidth) {
|
|
|
|
auto channel = cfg.hwChannel;
|
|
|
|
|
|
|
|
// Only register if we have a sensor
|
2021-01-05 13:02:20 -08:00
|
|
|
if (!isAdcChannelValid(channel)) {
|
2020-10-23 04:31:47 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-30 16:58:01 -07: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
|
|
|
|
func.configure(cfg.v1, val1, cfg.v2, val2, /*minOutput*/ -5, greaterOutput);
|
|
|
|
|
2020-10-23 04:31:47 -07:00
|
|
|
sensor.setFunction(func);
|
|
|
|
|
|
|
|
AdcSubscription::SubscribeSensor(sensor, channel, bandwidth);
|
|
|
|
|
2020-12-06 12:00:30 -08:00
|
|
|
sensor.Register();
|
2020-10-23 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-12-26 21:13:13 -08:00
|
|
|
void initFluidPressure() {
|
2021-11-17 00:54:21 -08:00
|
|
|
initFluidPressure(oilpSensorFunc, oilpSensor, engineConfiguration->oilPressure, 10);
|
|
|
|
initFluidPressure(fuelPressureFuncLow, fuelPressureSensorLow, engineConfiguration->lowPressureFuel, 10);
|
2023-01-06 05:09:17 -08:00
|
|
|
initFluidPressure(fuelPressureFuncHigh, fuelPressureSensorHigh, engineConfiguration->highPressureFuel, 100);
|
2024-06-17 05:08:12 -07:00
|
|
|
initFluidPressure(acPressureFunc, acPressureSensor, engineConfiguration->acPressure, 10);
|
2022-03-20 17:13:04 -07:00
|
|
|
initFluidPressure(auxLinear1Func, auxLinear1Sensor, engineConfiguration->auxLinear1, 10);
|
|
|
|
initFluidPressure(auxLinear2Func, auxLinear2Sensor, engineConfiguration->auxLinear2, 10);
|
2020-10-23 12:46:16 -07:00
|
|
|
|
|
|
|
injectorPressure.setProxiedSensor(
|
2021-11-17 00:54:21 -08:00
|
|
|
engineConfiguration->injectorPressureType == IPT_High
|
2020-10-23 12:46:16 -07:00
|
|
|
? SensorType::FuelPressureHigh
|
|
|
|
: SensorType::FuelPressureLow
|
|
|
|
);
|
|
|
|
|
2020-12-06 12:00:30 -08:00
|
|
|
injectorPressure.Register();
|
2020-10-23 04:31:47 -07:00
|
|
|
}
|
|
|
|
|
2022-12-26 21:13:13 -08:00
|
|
|
void deinitFluidPressure() {
|
2023-01-06 05:09:17 -08:00
|
|
|
AdcSubscription::UnsubscribeSensor(oilpSensor, engineConfiguration->oilPressure.hwChannel);
|
|
|
|
AdcSubscription::UnsubscribeSensor(fuelPressureSensorLow, engineConfiguration->lowPressureFuel.hwChannel);
|
|
|
|
AdcSubscription::UnsubscribeSensor(fuelPressureSensorHigh, engineConfiguration->highPressureFuel.hwChannel);
|
|
|
|
AdcSubscription::UnsubscribeSensor(auxLinear1Sensor, engineConfiguration->auxLinear1.hwChannel);
|
|
|
|
AdcSubscription::UnsubscribeSensor(auxLinear2Sensor, engineConfiguration->auxLinear2.hwChannel);
|
2020-10-23 04:31:47 -07:00
|
|
|
}
|