diff -r 712984fdd26b -r 5cf6f099c897 thermferm/thermferm.c --- a/thermferm/thermferm.c Thu Mar 17 23:28:29 2016 +0100 +++ b/thermferm/thermferm.c Sat Mar 26 14:43:31 2016 +0100 @@ -1233,6 +1233,10 @@ } } + /* + * Unit door state, default is closed. + */ + unit->door_state = 1; if (unit->door_address) { rc = device_in(unit->door_address, &temp); if (rc == DEVPRESENT_YES) { @@ -1247,16 +1251,13 @@ unit->door_state = 0; } } - } else { - unit->door_state = 1; } - } else { - /* - * No door switch, say door is closed. - */ - unit->door_state = 1; } + /* + * Unit PSU state, default power is ok + */ + unit->psu_state = 1; if (unit->psu_address) { rc = device_in(unit->psu_address, &temp); if (rc == DEVPRESENT_YES) { @@ -1271,11 +1272,7 @@ unit->psu_state = 0; } } - } else { - unit->psu_state = 1; } - } else { - unit->psu_state = 1; } /* @@ -1651,19 +1648,19 @@ fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); - if ((unit->heater_address || unit->cooler_address) && unit->fan_address) { - /* - * If there is a heater or cooler and we have a fan, turn fan on if - * cooling or heating. The Fan has a start/stop delay. - */ - if ((unit->heater_address && unit->heater_state) || (unit->cooler_address && unit->cooler_state)) { + /* + * If there is a fan, and the unit door is closed, and the unit should be doing + * something, then turn on the global fan. + */ + if (unit->fan_address) { + if (unit->door_state) { if (unit->fan_wait < unit->fan_delay) { - unit->fan_wait++; + unit->fan_wait++; } else { - if (! unit->fan_state) { + if (! unit->fan_state) { syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); - unit->fan_state = 100; - } + unit->fan_state = 100; + } } } else { if (unit->fan_wait > 0) { @@ -1675,11 +1672,9 @@ } } } - if (unit->door_state) - device_out(unit->fan_address, unit->fan_state); - else - device_out(unit->fan_address, 0); + device_out(unit->fan_address, unit->fan_state); } + } else { unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; } /* fridge beer or profile mode */ @@ -1716,6 +1711,9 @@ #ifdef HAVE_WIRINGPI_H piLock(LOCK_LCD); #endif + /* + * Write 4 rows to the LCD to display the unit state + */ lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); lcd_buf_write(row++, "%s ", unit->name); lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair);