1231 } else { |
1231 } else { |
1232 unit->beer_state = 2; |
1232 unit->beer_state = 2; |
1233 } |
1233 } |
1234 } |
1234 } |
1235 |
1235 |
|
1236 /* |
|
1237 * Unit door state, default is closed. |
|
1238 */ |
|
1239 unit->door_state = 1; |
1236 if (unit->door_address) { |
1240 if (unit->door_address) { |
1237 rc = device_in(unit->door_address, &temp); |
1241 rc = device_in(unit->door_address, &temp); |
1238 if (rc == DEVPRESENT_YES) { |
1242 if (rc == DEVPRESENT_YES) { |
1239 if (temp) { |
1243 if (temp) { |
1240 if (unit->door_state == 0) { |
1244 if (unit->door_state == 0) { |
1245 if (unit->door_state) { |
1249 if (unit->door_state) { |
1246 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); |
1250 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); |
1247 unit->door_state = 0; |
1251 unit->door_state = 0; |
1248 } |
1252 } |
1249 } |
1253 } |
1250 } else { |
|
1251 unit->door_state = 1; |
|
1252 } |
1254 } |
1253 } else { |
|
1254 /* |
|
1255 * No door switch, say door is closed. |
|
1256 */ |
|
1257 unit->door_state = 1; |
|
1258 } |
1255 } |
1259 |
1256 |
|
1257 /* |
|
1258 * Unit PSU state, default power is ok |
|
1259 */ |
|
1260 unit->psu_state = 1; |
1260 if (unit->psu_address) { |
1261 if (unit->psu_address) { |
1261 rc = device_in(unit->psu_address, &temp); |
1262 rc = device_in(unit->psu_address, &temp); |
1262 if (rc == DEVPRESENT_YES) { |
1263 if (rc == DEVPRESENT_YES) { |
1263 if (temp) { |
1264 if (temp) { |
1264 if (unit->psu_state == 0) { |
1265 if (unit->psu_state == 0) { |
1649 } |
1646 } |
1650 if (debug) |
1647 if (debug) |
1651 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", |
1648 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n", |
1652 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); |
1649 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state); |
1653 |
1650 |
1654 if ((unit->heater_address || unit->cooler_address) && unit->fan_address) { |
1651 /* |
1655 /* |
1652 * If there is a fan, and the unit door is closed, and the unit should be doing |
1656 * If there is a heater or cooler and we have a fan, turn fan on if |
1653 * something, then turn on the global fan. |
1657 * cooling or heating. The Fan has a start/stop delay. |
1654 */ |
1658 */ |
1655 if (unit->fan_address) { |
1659 if ((unit->heater_address && unit->heater_state) || (unit->cooler_address && unit->cooler_state)) { |
1656 if (unit->door_state) { |
1660 if (unit->fan_wait < unit->fan_delay) { |
1657 if (unit->fan_wait < unit->fan_delay) { |
1661 unit->fan_wait++; |
1658 unit->fan_wait++; |
1662 } else { |
1659 } else { |
1663 if (! unit->fan_state) { |
1660 if (! unit->fan_state) { |
1664 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); |
1661 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name); |
1665 unit->fan_state = 100; |
1662 unit->fan_state = 100; |
1666 } |
1663 } |
1667 } |
1664 } |
1668 } else { |
1665 } else { |
1669 if (unit->fan_wait > 0) { |
1666 if (unit->fan_wait > 0) { |
1670 unit->fan_wait--; |
1667 unit->fan_wait--; |
1671 } else { |
1668 } else { |
1673 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name); |
1670 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name); |
1674 unit->fan_state = 0; |
1671 unit->fan_state = 0; |
1675 } |
1672 } |
1676 } |
1673 } |
1677 } |
1674 } |
1678 if (unit->door_state) |
1675 device_out(unit->fan_address, unit->fan_state); |
1679 device_out(unit->fan_address, unit->fan_state); |
|
1680 else |
|
1681 device_out(unit->fan_address, 0); |
|
1682 } |
1676 } |
|
1677 |
1683 } else { |
1678 } else { |
1684 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
1679 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
1685 } /* fridge beer or profile mode */ |
1680 } /* fridge beer or profile mode */ |
1686 |
1681 |
1687 /* |
1682 /* |
1714 } |
1709 } |
1715 } |
1710 } |
1716 #ifdef HAVE_WIRINGPI_H |
1711 #ifdef HAVE_WIRINGPI_H |
1717 piLock(LOCK_LCD); |
1712 piLock(LOCK_LCD); |
1718 #endif |
1713 #endif |
|
1714 /* |
|
1715 * Write 4 rows to the LCD to display the unit state |
|
1716 */ |
1719 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); |
1717 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); |
1720 lcd_buf_write(row++, "%s ", unit->name); |
1718 lcd_buf_write(row++, "%s ", unit->name); |
1721 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); |
1719 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); |
1722 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); |
1720 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); |
1723 #ifdef HAVE_WIRINGPI_H |
1721 #ifdef HAVE_WIRINGPI_H |