diff --git a/lambda/airgate.c b/lambda/airgate.c index d1f8dff..304119e 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -6,7 +6,6 @@ */ #include -#include #include #include #include @@ -17,10 +16,9 @@ // TODO pins -volatile static int8_t dir = 0; -volatile static uint16_t pos = 100 << 2; -volatile static uint16_t steps = 0; -volatile static uint16_t stepsDone = 0; +static int8_t dir = 0; +static uint16_t pos = 0; +static uint16_t steps = 0; static uint8_t speed = 255; static void start(void) { @@ -48,8 +46,6 @@ // stop timer2 TCCR2B = 0; // GTCCR |= (1 << PSRASY); - // step pin low - // PORTB &= ~(1 << PB7); } void makeSteps(void) { @@ -57,36 +53,25 @@ PORTB ^= (1 << PB7); pos += dir; steps--; - stepsDone++; } else { stop(); - // driver sleep mode - PORTC &= ~(1 << PC5); - - char buf[64]; - snprintf(buf, sizeof(buf), "stopp: pos: %d, steps: %d, done: %d\n", pos, steps, stepsDone); - printString(buf); - - stepsDone = 0; + if (pos == 0) { + // driver sleep mode + PORTC &= ~(1 << PC5); + } } } void setAirgate(uint8_t const position) { stop(); - - int16_t diff = (((int16_t)position) << 2) - pos; + int16_t diff = (((int16_t)position) << 1) - pos; if (diff != 0) { dir = MAX(-1, MIN(diff, 1)); steps = abs(diff); - - char buf[96]; - snprintf(buf, sizeof(buf), "start: pos: %d, steps: %d\n", pos, steps); - printString(buf); - start(); } } uint8_t getAirgate(void) { - return pos >> 2; + return pos >> 1; } diff --git a/lambda/lambda.c b/lambda/lambda.c index 84487ea..5c2db3b 100644 --- a/lambda/lambda.c +++ b/lambda/lambda.c @@ -59,7 +59,7 @@ // spend some time on being polite while (getTime() < 3) {} // TODO remember position before reset? - // setAirgate(100); + setAirgate(100); setHeaterState(heaterStateOn); uint32_t time = 0; diff --git a/lambda/rules.c b/lambda/rules.c index 976f293..03db316 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -146,7 +146,6 @@ if (! *fired && state == firing_up && meas.tempI > TEMP_FIRE_OUT && tempIMax >= TEMP_AIRGATE_50) { resetRules(false); - setAirgate(100); tempIMax = meas.tempI; if (getHeaterState() != heaterStateFault) { setHeaterState(heaterStateOn); @@ -194,6 +193,8 @@ /** * Switches the heater off if it is on for 30 mins or more and there does * not seem to be a fire, and notifies that the fire is out. + * TODO check this rule, simplify? + * TODO set motor driver sleep mode as well? */ static void heaterTimeout(bool* const fired, Measurement const meas) { if (getHeaterState() == heaterStateOff ||