fome-fw/firmware/controllers/trigger/aux_valves.cpp

94 lines
2.6 KiB
C++
Raw Normal View History

2017-11-25 22:17:37 -08:00
/*
* aux_valves.cpp
*
2017-11-27 18:49:58 -08:00
*
* Here we have two auxilary digital on/off outputs which would open once per each 360 degrees of engine crank revolution.
* The second valve is 180 degrees after the first one.
*
* Valve open and close angles are taken from fsioCurve1 and fsioCurve2 tables respectively, the position depend on TPS input.
*
* https://github.com/rusefi/rusefi/issues/490
*
2017-11-25 22:17:37 -08:00
* @date Nov 25, 2017
* @author Andrey Belomutskiy, (c) 2012-2017
*/
#include "aux_valves.h"
2017-11-26 19:30:37 -08:00
#include "allsensors.h"
#include "trigger_central.h"
2017-12-01 20:25:30 -08:00
#include "engine_math.h"
2017-11-26 19:30:37 -08:00
EXTERN_ENGINE
;
2017-11-26 21:06:43 -08:00
static scheduling_s turnOnEvent[AUX_DIGITAL_VALVE_COUNT][2];
static scheduling_s turnOffEvent[AUX_DIGITAL_VALVE_COUNT][2];
2017-11-27 18:49:58 -08:00
static void turnOn(NamedOutputPin *output) {
output->setHigh();
}
2017-11-26 21:06:43 -08:00
2017-11-27 18:49:58 -08:00
static void turnOff(NamedOutputPin *output) {
output->setLow();
2017-11-26 21:06:43 -08:00
}
2017-11-27 18:49:58 -08:00
2017-11-26 19:30:37 -08:00
static void auxValveTriggerCallback(trigger_event_e ckpSignalType,
uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX) {
2017-11-26 21:06:43 -08:00
#if EFI_PROD_CODE || EFI_SIMULATOR || defined(__DOXYGEN__)
if (index != 2) {
return;
}
int rpm = ENGINE(rpmCalculator.rpmValue);
2017-11-27 18:49:58 -08:00
if (!isValidRpm(rpm)) {
return;
}
for (int valveIndex = 0; valveIndex < AUX_DIGITAL_VALVE_COUNT;
valveIndex++) {
NamedOutputPin *output = &enginePins.auxValve[valveIndex];
for (int phaseIndex = 0; phaseIndex < 2; phaseIndex++) {
2017-12-01 20:25:30 -08:00
angle_t extra = phaseIndex * 360 + valveIndex * 180;
angle_t onTime = extra + engine->engineState.auxValveStart;
fixAngle(onTime, "onTime");
2017-11-27 18:49:58 -08:00
scheduleByAngle(rpm, &turnOnEvent[valveIndex][phaseIndex],
2017-12-01 20:25:30 -08:00
onTime,
2017-11-27 18:49:58 -08:00
(schfunc_t) &turnOn, output, &engine->rpmCalculator);
2017-12-01 20:25:30 -08:00
angle_t offTime = extra + engine->engineState.auxValveEnd;
fixAngle(offTime, "offTime");
2017-11-27 18:49:58 -08:00
scheduleByAngle(rpm, &turnOffEvent[valveIndex][phaseIndex],
2017-12-01 20:25:30 -08:00
offTime,
2017-11-27 18:49:58 -08:00
(schfunc_t) &turnOff, output, &engine->rpmCalculator);
}
}
2017-11-26 19:30:37 -08:00
2017-11-26 21:06:43 -08:00
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
2017-11-26 19:30:37 -08:00
}
2017-11-25 22:17:37 -08:00
void initAuxValves(Logging *sharedLogger) {
2017-11-26 19:30:37 -08:00
#if EFI_PROD_CODE || EFI_SIMULATOR || defined(__DOXYGEN__)
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
return;
}
addTriggerEventListener(auxValveTriggerCallback, "tach", engine);
2017-11-26 21:06:43 -08:00
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
2017-11-26 19:30:37 -08:00
}
void updateAuxValves(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (engineConfiguration->auxValves[0] == GPIO_UNASSIGNED) {
return;
}
float x = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE);
2017-11-27 18:49:58 -08:00
engine->engineState.auxValveStart = interpolate2d("aux", x,
engineConfiguration->fsioCurve1Bins,
2017-11-26 19:30:37 -08:00
engineConfiguration->fsioCurve1, FSIO_CURVE_16);
2017-11-25 22:17:37 -08:00
2017-11-27 18:49:58 -08:00
engine->engineState.auxValveEnd = interpolate2d("aux", x,
engineConfiguration->fsioCurve2Bins,
2017-11-26 19:30:37 -08:00
engineConfiguration->fsioCurve2, FSIO_CURVE_16);
2017-11-25 22:17:37 -08:00
}