Files
2023-09-11 18:04:36 +02:00

82 lines
1.7 KiB
Arduino

#define VALVEDEBUG 0
PAR_LONG boostdelay = 1000; // msec (0: always boost)
PAR_LONG heFeedback = 0;
PAR_LONG n2Feedback = 0;
long boosttime;
boolean boosting = false;
byte valveState[2] = {0,0};
enum {valve_n2, valve_he};
//Timer boostTimer;
void ValveInit() {
pinMode(io_valve_boost, OUTPUT);
pinMode(io_n2_valve, OUTPUT);
pinMode(io_he_valve, OUTPUT);
//TimerInit(&boostTimer, ValveBoostOff, 0, 0);
}
void ValvePars() {
ParFixed("bdl", boostdelay, 3);
ParFixed("hfb", heFeedback, 0);
ParFixed("nfb", n2Feedback, 0);
}
void ValveSet(byte pin, byte high) {
byte i;
if (pin == io_n2_valve) {
i = valve_n2;
} else if (pin == io_he_valve) {
i = valve_he;
} else {
Serial.print(F("bad valve pin\n"));
return;
}
if (high) {
digitalWrite(io_valve_boost, HIGH);
if (VALVEDEBUG) {
Serial.print(pin, DEC);
Serial.println(" VALVE ON\n");
}
boosttime = now;
boosting = true;
//TimerStart(&boostTimer, now + boostdelay);
} else {
if (VALVEDEBUG) {
Serial.print(pin, DEC);
Serial.println(" VALVE OFF\n");
}
}
digitalWrite(pin, high);
ARRAY(valveState,i) = high;
}
void ValveFastHandler() {
if (boosting && boostdelay != 0 && time_ge(now, boosttime + boostdelay)) {
digitalWrite(io_valve_boost, LOW);
if (VALVEDEBUG) Serial.println("VALVE BOOST OFF\n");
boosting = false;
}
}
void ValveHandler() {
if (!valveState[valve_n2]) {
ParSet(n2Feedback, aRead(a_ln2_feedback));
if (n2Feedback < 100) {
N2ValveState(false);
} else {
N2ValveState(true);
}
}
if (!valveState[valve_he]) {
ParSet(heFeedback, aRead(a_lhe_feedback));
if (heFeedback < 100) {
HeValveState(false);
} else {
HeValveState(true);
}
}
}