275 |
275 |
276 #endif |
276 #endif |
277 |
277 |
278 |
278 |
279 |
279 |
280 int read_sensor(char *address, int *val) |
|
281 { |
|
282 devices_list *device; |
|
283 int tmp; |
|
284 |
|
285 for (device = Config.devices; device; device = device->next) { |
|
286 if (strcmp(address, device->uuid) == 0) { |
|
287 #ifdef HAVE_WIRINGPI_H |
|
288 piLock(LOCK_DEVICES); |
|
289 #endif |
|
290 tmp = device->value + device->offset; |
|
291 #ifdef HAVE_WIRINGPI_H |
|
292 piUnlock(LOCK_DEVICES); |
|
293 #endif |
|
294 *val = tmp; |
|
295 return device->present; |
|
296 } |
|
297 } |
|
298 |
|
299 return DEVPRESENT_NO; |
|
300 } |
|
301 |
|
302 |
|
303 |
|
304 /* |
280 /* |
305 * Handle panel key events |
281 * Handle panel key events |
306 */ |
282 */ |
307 #ifdef HAVE_WIRINGPI_H |
283 #ifdef HAVE_WIRINGPI_H |
308 void panel_key_events(int key) |
284 void panel_key_events(int key) |
1001 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
977 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec); |
1002 piUnlock(LOCK_LCD); |
978 piUnlock(LOCK_LCD); |
1003 #endif |
979 #endif |
1004 |
980 |
1005 if (Config.temp_address) { |
981 if (Config.temp_address) { |
1006 rc = read_sensor(Config.temp_address, &temp); |
982 rc = device_in(Config.temp_address, &temp); |
1007 if (rc == DEVPRESENT_YES) { |
983 if (rc == DEVPRESENT_YES) { |
1008 Config.temp_value = temp; |
984 Config.temp_value = temp; |
1009 Config.temp_state = 0; |
985 Config.temp_state = 0; |
1010 #ifdef HAVE_WIRINGPI_H |
986 #ifdef HAVE_WIRINGPI_H |
1011 piLock(LOCK_LCD); |
987 piLock(LOCK_LCD); |
1018 Config.temp_state = 2; |
994 Config.temp_state = 2; |
1019 } |
995 } |
1020 } |
996 } |
1021 |
997 |
1022 if (Config.hum_address) { |
998 if (Config.hum_address) { |
1023 rc = read_sensor(Config.hum_address, &temp); |
999 rc = device_in(Config.hum_address, &temp); |
1024 if (rc == DEVPRESENT_YES) { |
1000 if (rc == DEVPRESENT_YES) { |
1025 Config.hum_value = temp; |
1001 Config.hum_value = temp; |
1026 Config.hum_state = 0; |
1002 Config.hum_state = 0; |
1027 #ifdef HAVE_WIRINGPI_H |
1003 #ifdef HAVE_WIRINGPI_H |
1028 piLock(LOCK_LCD); |
1004 piLock(LOCK_LCD); |
1043 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); |
1019 lcd_buf_write(row++, "Mode %s ", UNITMODE[unit->mode]); |
1044 piUnlock(LOCK_LCD); |
1020 piUnlock(LOCK_LCD); |
1045 #endif |
1021 #endif |
1046 |
1022 |
1047 if (unit->air_address) { |
1023 if (unit->air_address) { |
1048 rc = read_sensor(unit->air_address, &temp); |
1024 rc = device_in(unit->air_address, &temp); |
1049 if (rc == DEVPRESENT_YES) { |
1025 if (rc == DEVPRESENT_YES) { |
1050 /* |
1026 /* |
1051 * It is possible to have read errors or extreme values. |
1027 * It is possible to have read errors or extreme values. |
1052 * This can happen with bad connections so we compare the |
1028 * This can happen with bad connections so we compare the |
1053 * value with the previous one. If the difference is too |
1029 * value with the previous one. If the difference is too |
1077 unit->air_state = 2; |
1053 unit->air_state = 2; |
1078 } |
1054 } |
1079 } |
1055 } |
1080 |
1056 |
1081 if (unit->beer_address) { |
1057 if (unit->beer_address) { |
1082 rc = read_sensor(unit->beer_address, &temp); |
1058 rc = device_in(unit->beer_address, &temp); |
1083 if (rc == DEVPRESENT_YES) { |
1059 if (rc == DEVPRESENT_YES) { |
1084 deviation = 40000; |
1060 deviation = 40000; |
1085 if ((unit->beer_temperature == 0) || |
1061 if ((unit->beer_temperature == 0) || |
1086 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
1062 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
1087 unit->beer_temperature = temp; |
1063 unit->beer_temperature = temp; |
1103 unit->beer_state = 2; |
1079 unit->beer_state = 2; |
1104 } |
1080 } |
1105 } |
1081 } |
1106 |
1082 |
1107 if (unit->door_address) { |
1083 if (unit->door_address) { |
1108 rc = read_sensor(unit->door_address, &temp); |
1084 rc = device_in(unit->door_address, &temp); |
1109 if (rc == DEVPRESENT_YES) { |
1085 if (rc == DEVPRESENT_YES) { |
1110 if (temp) { |
1086 if (temp) { |
1111 if (unit->door_state == 0) { |
1087 if (unit->door_state == 0) { |
1112 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name); |
1088 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name); |
1113 unit->door_state = 1; |
1089 unit->door_state = 1; |
1127 */ |
1103 */ |
1128 unit->door_state = 1; |
1104 unit->door_state = 1; |
1129 } |
1105 } |
1130 |
1106 |
1131 if (unit->psu_address) { |
1107 if (unit->psu_address) { |
1132 rc = read_sensor(unit->psu_address, &temp); |
1108 rc = device_in(unit->psu_address, &temp); |
1133 if (rc == DEVPRESENT_YES) { |
1109 if (rc == DEVPRESENT_YES) { |
1134 if (temp) { |
1110 if (temp) { |
1135 if (unit->psu_state == 0) { |
1111 if (unit->psu_state == 0) { |
1136 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name); |
1112 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name); |
1137 unit->psu_state = 1; |
1113 unit->psu_state = 1; |