reducing code duplication
This commit is contained in:
parent
eac6683530
commit
536ccb4001
|
@ -13,6 +13,16 @@ static void freqSensorExtiCallback(void* arg, efitick_t nowNt) {
|
|||
reinterpret_cast<FrequencySensor*>(arg)->onEdge(nowNt);
|
||||
}
|
||||
|
||||
void FrequencySensor::initIfValid(brain_pin_e pin, SensorConverter &converter) {
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
setFunction(converter);
|
||||
init(pin);
|
||||
init(pin);
|
||||
Register();
|
||||
}
|
||||
|
||||
void FrequencySensor::init(brain_pin_e pin) {
|
||||
m_pin = pin;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ public:
|
|||
}
|
||||
|
||||
void init(brain_pin_e pin);
|
||||
void initIfValid(brain_pin_e pin, SensorConverter &converter);
|
||||
void deInit();
|
||||
|
||||
void onEdge(efitick_t nowNt);
|
||||
|
|
|
@ -11,16 +11,7 @@ static FlexConverter converter;
|
|||
// https://rusefi.com/forum/viewtopic.php?p=37452&sid=829804c90d5b2e1fecd1b900cf1b1811#p37452
|
||||
|
||||
void initFlexSensor() {
|
||||
auto pin = engineConfiguration->flexSensorPin;
|
||||
|
||||
// Nothing to do if no sensor configured
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
flexSensor.setFunction(converter);
|
||||
flexSensor.init(pin);
|
||||
flexSensor.Register();
|
||||
flexSensor.initIfValid(engineConfiguration->flexSensorPin, converter);
|
||||
}
|
||||
|
||||
void deInitFlexSensor() {
|
||||
|
|
|
@ -10,19 +10,9 @@ static TurbochargerSpeedConverter turbochargerSpeedConverter;
|
|||
|
||||
|
||||
void initTurbochargerSpeedSensor() {
|
||||
|
||||
auto pin = engineConfiguration->turboSpeedSensorInputPin;
|
||||
|
||||
// Nothing to do if no sensor configured
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
turbochargerSpeedSensor.setFunction(turbochargerSpeedConverter);
|
||||
turbochargerSpeedSensor.init(pin);
|
||||
turbochargerSpeedSensor.Register();
|
||||
turbochargerSpeedSensor.initIfValid(engineConfiguration->turboSpeedSensorInputPin, turbochargerSpeedConverter);
|
||||
}
|
||||
|
||||
void deinitTurbochargerSpeedSensor() {
|
||||
turbochargerSpeedSensor.deInit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,19 +9,9 @@ static FrequencySensor vehicleSpeedSensor(SensorType::VehicleSpeed, MS2NT(500),
|
|||
static VehicleSpeedConverter vehicleSpeedConverter;
|
||||
|
||||
void initVehicleSpeedSensor() {
|
||||
|
||||
auto pin = engineConfiguration->vehicleSpeedSensorInputPin;
|
||||
|
||||
// Nothing to do if no sensor configured
|
||||
if (!isBrainPinValid(pin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
vehicleSpeedSensor.setFunction(vehicleSpeedConverter);
|
||||
vehicleSpeedSensor.init(pin);
|
||||
vehicleSpeedSensor.Register();
|
||||
vehicleSpeedSensor.initIfValid(engineConfiguration->vehicleSpeedSensorInputPin, vehicleSpeedConverter);
|
||||
}
|
||||
|
||||
void deInitVehicleSpeedSensor() {
|
||||
vehicleSpeedSensor.deInit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue