957 #ifndef HAVE_WIRINGPI_H |
957 #ifndef HAVE_WIRINGPI_H |
958 long t = 0; |
958 long t = 0; |
959 #endif |
959 #endif |
960 int current_step, valid_step, time_until_now, previous_fridge_mode; |
960 int current_step, valid_step, time_until_now, previous_fridge_mode; |
961 float previous_target_lo, previous_target_hi; |
961 float previous_target_lo, previous_target_hi; |
|
962 float LCDair, LCDbeer, LCDspL, LCDspH; |
|
963 unsigned char LCDstatC, LCDstatH; |
|
964 int LCDunit; |
962 |
965 |
963 |
966 |
964 if (lockprog((char *)"thermferm")) { |
967 if (lockprog((char *)"thermferm")) { |
965 syslog(LOG_NOTICE, "Can't lock"); |
968 syslog(LOG_NOTICE, "Can't lock"); |
966 return 1; |
969 return 1; |
1120 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
1123 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
1121 #ifdef HAVE_WIRINGPI_H |
1124 #ifdef HAVE_WIRINGPI_H |
1122 piUnlock(LOCK_LCD); |
1125 piUnlock(LOCK_LCD); |
1123 #endif |
1126 #endif |
1124 |
1127 |
|
1128 #ifdef HAVE_WIRINGPI_H |
|
1129 piLock(LOCK_LCD); |
|
1130 #endif |
|
1131 lcd_buf_write(row, "Room temp N/A ", Config.temp_value / 1000.0, 0x01); |
|
1132 #ifdef HAVE_WIRINGPI_H |
|
1133 piUnlock(LOCK_LCD); |
|
1134 #endif |
1125 if (Config.temp_address) { |
1135 if (Config.temp_address) { |
1126 rc = device_in(Config.temp_address, &temp); |
1136 rc = device_in(Config.temp_address, &temp); |
1127 if (rc == DEVPRESENT_YES) { |
1137 if (rc == DEVPRESENT_YES) { |
1128 Config.temp_value = temp; |
1138 Config.temp_value = temp; |
1129 Config.temp_state = 0; |
1139 Config.temp_state = 0; |
1130 #ifdef HAVE_WIRINGPI_H |
1140 #ifdef HAVE_WIRINGPI_H |
1131 piLock(LOCK_LCD); |
1141 piLock(LOCK_LCD); |
1132 #endif |
1142 #endif |
1133 lcd_buf_write(row++, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); |
1143 lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01); |
1134 #ifdef HAVE_WIRINGPI_H |
1144 #ifdef HAVE_WIRINGPI_H |
1135 piUnlock(LOCK_LCD); |
1145 piUnlock(LOCK_LCD); |
1136 #endif |
1146 #endif |
1137 } else if (rc == DEVPRESENT_ERROR) { |
1147 } else if (rc == DEVPRESENT_ERROR) { |
1138 Config.temp_state = 1; |
1148 Config.temp_state = 1; |
1139 } else { |
1149 } else { |
1140 Config.temp_state = 2; |
1150 Config.temp_state = 2; |
1141 } |
1151 } |
1142 } |
1152 } |
|
1153 row++; |
|
1154 |
|
1155 #ifdef HAVE_WIRINGPI_H |
|
1156 piLock(LOCK_LCD); |
|
1157 #endif |
|
1158 lcd_buf_write(row, " Humidity N/A ", Config.hum_value / 1000.0); |
|
1159 #ifdef HAVE_WIRINGPI_H |
|
1160 piUnlock(LOCK_LCD); |
|
1161 #endif |
1143 |
1162 |
1144 if (Config.hum_address) { |
1163 if (Config.hum_address) { |
1145 rc = device_in(Config.hum_address, &temp); |
1164 rc = device_in(Config.hum_address, &temp); |
1146 if (rc == DEVPRESENT_YES) { |
1165 if (rc == DEVPRESENT_YES) { |
1147 Config.hum_value = temp; |
1166 Config.hum_value = temp; |
1148 Config.hum_state = 0; |
1167 Config.hum_state = 0; |
1149 #ifdef HAVE_WIRINGPI_H |
1168 #ifdef HAVE_WIRINGPI_H |
1150 piLock(LOCK_LCD); |
1169 piLock(LOCK_LCD); |
1151 #endif |
1170 #endif |
1152 lcd_buf_write(row++, " Humidity %.1f %% ", Config.hum_value / 1000.0, 0xdf); |
1171 lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0); |
1153 #ifdef HAVE_WIRINGPI_H |
1172 #ifdef HAVE_WIRINGPI_H |
1154 piUnlock(LOCK_LCD); |
1173 piUnlock(LOCK_LCD); |
1155 #endif |
1174 #endif |
1156 } else if (rc == DEVPRESENT_ERROR) { |
1175 } else if (rc == DEVPRESENT_ERROR) { |
1157 Config.hum_state = 1; |
1176 Config.hum_state = 1; |
1158 } else { |
1177 } else { |
1159 Config.hum_state = 2; |
1178 Config.hum_state = 2; |
1160 } |
1179 } |
1161 } |
1180 } |
1162 |
1181 row++; |
|
1182 |
|
1183 LCDunit = 0; |
1163 for (unit = Config.units; unit; unit = unit->next) { |
1184 for (unit = Config.units; unit; unit = unit->next) { |
1164 #ifdef HAVE_WIRINGPI_H |
1185 LCDunit++; |
1165 piLock(LOCK_LCD); |
|
1166 #endif |
|
1167 lcd_buf_write(row++, "Unit %s ", unit->name); |
|
1168 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); |
|
1169 #ifdef HAVE_WIRINGPI_H |
|
1170 piUnlock(LOCK_LCD); |
|
1171 #endif |
|
1172 |
|
1173 if (unit->air_address) { |
1186 if (unit->air_address) { |
1174 rc = device_in(unit->air_address, &temp); |
1187 rc = device_in(unit->air_address, &temp); |
1175 if (rc == DEVPRESENT_YES) { |
1188 if (rc == DEVPRESENT_YES) { |
1176 /* |
1189 /* |
1177 * It is possible to have read errors or extreme values. |
1190 * It is possible to have read errors or extreme values. |
1184 deviation = 40000; |
1197 deviation = 40000; |
1185 if ((unit->air_temperature == 0) || |
1198 if ((unit->air_temperature == 0) || |
1186 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { |
1199 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) { |
1187 unit->air_temperature = temp; |
1200 unit->air_temperature = temp; |
1188 unit->air_state = 0; |
1201 unit->air_state = 0; |
1189 #ifdef HAVE_WIRINGPI_H |
|
1190 piLock(LOCK_LCD); |
|
1191 #endif |
|
1192 lcd_buf_write(row++, " Air %.3f %cC ", unit->air_temperature / 1000.0, 0xdf); |
|
1193 #ifdef HAVE_WIRINGPI_H |
|
1194 piUnlock(LOCK_LCD); |
|
1195 #endif |
|
1196 } else { |
1202 } else { |
1197 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
1203 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
1198 if (debug) { |
1204 if (debug) { |
1199 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
1205 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
1200 } |
1206 } |
1212 deviation = 40000; |
1218 deviation = 40000; |
1213 if ((unit->beer_temperature == 0) || |
1219 if ((unit->beer_temperature == 0) || |
1214 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
1220 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
1215 unit->beer_temperature = temp; |
1221 unit->beer_temperature = temp; |
1216 unit->beer_state = 0; |
1222 unit->beer_state = 0; |
1217 #ifdef HAVE_WIRINGPI_H |
|
1218 piLock(LOCK_LCD); |
|
1219 #endif |
|
1220 lcd_buf_write(row++, "Beer %.3f %cC ", unit->beer_temperature / 1000.0, 0xdf); |
|
1221 #ifdef HAVE_WIRINGPI_H |
|
1222 piUnlock(LOCK_LCD); |
|
1223 #endif |
|
1224 } else { |
1223 } else { |
1225 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
1224 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
1226 if (debug) { |
1225 if (debug) { |
1227 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
1226 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
1228 } |
1227 } |
1485 if (unit->fan_address && unit->fan_state) |
1484 if (unit->fan_address && unit->fan_state) |
1486 unit->fan_usage++; |
1485 unit->fan_usage++; |
1487 if (unit->light_address && unit->light_state) |
1486 if (unit->light_address && unit->light_state) |
1488 unit->light_usage++; |
1487 unit->light_usage++; |
1489 |
1488 |
1490 if (unit->heater_address && unit->cooler_address) { |
|
1491 #ifdef HAVE_WIRINGPI_H |
|
1492 piLock(LOCK_LCD); |
|
1493 #endif |
|
1494 if (unit->heater_state) { |
|
1495 lcd_buf_write(row++, "Heater On "); |
|
1496 } else if (unit->cooler_state) { |
|
1497 lcd_buf_write(row++, "Cooler On "); |
|
1498 } else { |
|
1499 lcd_buf_write(row++, "Standby "); |
|
1500 } |
|
1501 #ifdef HAVE_WIRINGPI_H |
|
1502 piUnlock(LOCK_LCD); |
|
1503 piLock(LOCK_LCD); |
|
1504 #endif |
|
1505 switch (unit->mode) { |
|
1506 case UNITMODE_BEER: lcd_buf_write(row++, "Target %.1f %cC ", unit->beer_set, 0xdf); |
|
1507 break; |
|
1508 case UNITMODE_FRIDGE: lcd_buf_write(row++, "Target %.1f %cC ", unit->fridge_set, 0xdf); |
|
1509 break; |
|
1510 case UNITMODE_PROFILE: if (unit->prof_state != PROFILE_OFF) |
|
1511 lcd_buf_write(row++, "Tgt %.1f..%.1f %cC ", unit->prof_target_lo, unit->prof_target_hi, 0xdf); |
|
1512 else |
|
1513 lcd_buf_write(row++, "Target not set "); |
|
1514 break; |
|
1515 default: lcd_buf_write(row++, "Target not set "); |
|
1516 } |
|
1517 #ifdef HAVE_WIRINGPI_H |
|
1518 piUnlock(LOCK_LCD); |
|
1519 #endif |
|
1520 } else { |
|
1521 #ifdef HAVE_WIRINGPI_H |
|
1522 piLock(LOCK_LCD); |
|
1523 #endif |
|
1524 if (unit->heater_address) { |
|
1525 lcd_buf_write(row++, "Heat %s ", unit->heater_state ? "On ":"Off"); |
|
1526 } |
|
1527 if (unit->cooler_address) { |
|
1528 lcd_buf_write(row++, "Cool %s ", unit->cooler_state ? "On ":"Off"); |
|
1529 } |
|
1530 #ifdef HAVE_WIRINGPI_H |
|
1531 piUnlock(LOCK_LCD); |
|
1532 #endif |
|
1533 } |
|
1534 |
|
1535 /* |
1489 /* |
1536 * Interior lights |
1490 * Interior lights |
1537 */ |
1491 */ |
1538 if (unit->light_address) { |
1492 if (unit->light_address) { |
1539 if (unit->door_state && unit->light_state) { |
1493 if (unit->door_state && unit->light_state) { |
1707 device_out(unit->fan_address, 0); |
1661 device_out(unit->fan_address, 0); |
1708 } |
1662 } |
1709 } else { |
1663 } else { |
1710 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
1664 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE; |
1711 } /* fridge beer or profile mode */ |
1665 } /* fridge beer or profile mode */ |
|
1666 |
|
1667 /* |
|
1668 * Now everything is set and done, update the LCD display |
|
1669 */ |
|
1670 LCDair = unit->air_temperature / 1000.0; |
|
1671 LCDbeer = unit->beer_temperature / 1000.0; |
|
1672 LCDstatC = LCDstatH = 'x'; |
|
1673 if (unit->heater_address) { |
|
1674 if (unit->heater_state) |
|
1675 LCDstatH = '\5'; |
|
1676 else |
|
1677 LCDstatH = '\6'; |
|
1678 } |
|
1679 if (unit->cooler_address) { |
|
1680 if (unit->cooler_state) |
|
1681 LCDstatC = '\3'; |
|
1682 else |
|
1683 LCDstatC = '\4'; |
|
1684 } |
|
1685 LCDspH = LCDspL = 0.0; |
|
1686 if (unit->mode == UNITMODE_BEER) |
|
1687 LCDspH = LCDspL = unit->beer_set; |
|
1688 else if (unit->mode == UNITMODE_FRIDGE) |
|
1689 LCDspH = LCDspL = unit->fridge_set; |
|
1690 else if (unit->mode == UNITMODE_PROFILE) { |
|
1691 if (unit->prof_state != PROFILE_OFF) { |
|
1692 LCDspL = unit->prof_target_lo; |
|
1693 LCDspH = unit->prof_target_hi; |
|
1694 } |
|
1695 } |
|
1696 #ifdef HAVE_WIRINGPI_H |
|
1697 piLock(LOCK_LCD); |
|
1698 #endif |
|
1699 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]); |
|
1700 lcd_buf_write(row++, "%s ", unit->name); |
|
1701 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair); |
|
1702 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer); |
|
1703 #ifdef HAVE_WIRINGPI_H |
|
1704 piUnlock(LOCK_LCD); |
|
1705 #endif |
1712 } /* for units */ |
1706 } /* for units */ |
1713 |
1707 |
1714 #ifdef HAVE_WIRINGPI_H |
1708 #ifdef HAVE_WIRINGPI_H |
1715 piLock(LOCK_MENU); |
1709 piLock(LOCK_MENU); |
1716 #endif |
1710 #endif |