Sensor reconfiguration while running (#1131)

* reconfigure sensors

* docs

* doc
This commit is contained in:
Matthew Kennedy 2020-02-08 01:22:23 -08:00 committed by GitHub
parent 5c4329dbf2
commit 52f565f874
5 changed files with 56 additions and 23 deletions

View File

@ -94,6 +94,7 @@
#endif
#if EFI_PROD_CODE
#include "init.h"
#include "hardware.h"
#include "board.h"
#endif /* EFI_PROD_CODE */
@ -179,6 +180,7 @@ void incrementGlobalConfigurationVersion(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
*/
#if EFI_PROD_CODE
applyNewHardwareSettings();
reconfigureSensors();
#endif /* EFI_PROD_CODE */
engine->preCalculate(PASS_ENGINE_PARAMETER_SIGNATURE);
#if EFI_ALTERNATOR_CONTROL

View File

@ -4,4 +4,11 @@
#pragma once
// Call this once at startup to initialize, configure, and subscribe sensors
void initSensors();
// Call this whenever the configuration may have changed, so any sensors
// can be reconfigured with the new settings.
// Note: this may not be necessarily possible for all sensors, so some may
// do nothing when this is called.
void reconfigureSensors();

View File

@ -13,6 +13,19 @@ EXTERN_ENGINE;
LinearFunc oilpSensorFunc;
FunctionalSensor oilpSensor(SensorType::OilPressure, /* timeout = */ MS2NT(50));
void configureOilPressure(LinearFunc func, const oil_pressure_config_s& cfg)
{
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
oilpSensorFunc.configure(cfg.v1, val1, cfg.v2, val2, /*minOutput*/ -5, greaterOutput);
}
void initOilPressure() {
// Only register if we have a sensor
auto channel = engineConfiguration->oilPressure.hwChannel;
@ -20,17 +33,7 @@ void initOilPressure() {
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
oilpSensorFunc.configure(sensorCfg->v1, val1, sensorCfg->v2, val2, /*minOutput*/ -5, greaterOutput);
configureOilPressure(oilpSensorFunc, CONFIG(oilPressure));
oilpSensor.setFunction(oilpSensorFunc);
// Subscribe the sensor to the ADC
@ -40,3 +43,7 @@ void initOilPressure() {
warning(OBD_Oil_Pressure_Sensor_Malfunction, "Duplicate oilp sensor registration, ignoring");
}
}
void reconfigureOilPressure() {
configureOilPressure(oilpSensorFunc, CONFIG(oilPressure));
}

View File

@ -6,23 +6,31 @@
#include "init.h"
#include "sensor.h"
static void initSensorCli();
// Sensor init/config
void initTps();
void initOilPressure();
void initSensorCli();
void initSensors() {
// TPS
initTps();
// aux sensors
initOilPressure();
// Init CLI functionality for sensors (mocking)
initSensorCli();
}
void initSensorCli() {
// Sensor reconfiguration
void reconfigureTps();
void reconfigureOilPressure();
void reconfigureSensors() {
reconfigureTps();
reconfigureOilPressure();
}
// Mocking/testing helpers
static void initSensorCli() {
addConsoleActionIF("set_sensor_mock", Sensor::setMockValue);
addConsoleAction("reset_sensor_mocks", Sensor::resetAllMocks);
}

View File

@ -18,18 +18,22 @@ FunctionalSensor tpsSens1p(SensorType::Tps1, MS2NT(10));
FunctionalSensor tpsSens2p(SensorType::Tps2, MS2NT(10));
//FunctionalSensor tpsSens2s(SensorType::Tps2Secondary, MS2NT(10));
static void initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open) {
// Only register if we have a sensor
if (channel == EFI_ADC_NONE) {
return;
}
static void configureTps(LinearFunc& func, float closed, float open) {
func.configure(
closed / TPS_TS_CONVERSION, 0,
open / TPS_TS_CONVERSION, 100,
CONFIG(tpsErrorDetectionTooLow),
CONFIG(tpsErrorDetectionTooHigh)
);
}
static void initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open) {
// Only register if we have a sensor
if (channel == EFI_ADC_NONE) {
return;
}
configureTps(func, closed, open);
sensor.setFunction(func);
@ -44,3 +48,8 @@ void initTps() {
initTpsFunc(tpsFunc1p, tpsSens1p, CONFIG(tps1_1AdcChannel), CONFIG(tpsMin), CONFIG(tpsMax));
initTpsFunc(tpsFunc2p, tpsSens2p, CONFIG(tps2_1AdcChannel), CONFIG(tps2Min), CONFIG(tps2Max));
}
void reconfigureTps() {
configureTps(tpsFunc1p, CONFIG(tpsMin), CONFIG(tpsMax));
configureTps(tpsFunc2p, CONFIG(tps2Min), CONFIG(tps2Max));
}