101 if (my_shutdown) |
101 if (my_shutdown) |
102 break; |
102 break; |
103 |
103 |
104 if (unit->air_address) { |
104 if (unit->air_address) { |
105 rc = read_w1_28(unit->air_address, &temp); |
105 rc = read_w1_28(unit->air_address, &temp); |
106 if (rc == 2) { |
106 if (rc == DEVPRESENT_YES) { |
107 /* |
107 /* |
108 * It is possible to have read errors or extreme values. |
108 * It is possible to have read errors or extreme values. |
109 * This can happen with bad connections so we compare the |
109 * This can happen with bad connections so we compare the |
110 * value with the previous one. If the difference is too |
110 * value with the previous one. If the difference is too |
111 * much, we don't send that value. That also means that if |
111 * much, we don't send that value. That also means that if |
121 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
121 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp); |
122 if (debug) { |
122 if (debug) { |
123 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
123 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp); |
124 } |
124 } |
125 } |
125 } |
126 } else if (rc == 3) { |
126 } else if (rc == DEVPRESENT_ERROR) { |
127 unit->air_state = 1; |
127 unit->air_state = 1; |
128 } else { |
128 } else { |
129 unit->air_state = 2; |
129 unit->air_state = 2; |
130 } |
130 } |
131 } |
131 } |
132 if (my_shutdown) |
132 if (my_shutdown) |
133 break; |
133 break; |
134 |
134 |
135 if (unit->beer_address) { |
135 if (unit->beer_address) { |
136 rc = read_w1_28(unit->beer_address, &temp); |
136 rc = read_w1_28(unit->beer_address, &temp); |
137 if (rc == 2) { |
137 if (rc == DEVPRESENT_YES) { |
138 deviation = 20000; |
138 deviation = 20000; |
139 if ((unit->beer_temperature == 0) || |
139 if ((unit->beer_temperature == 0) || |
140 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
140 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) { |
141 unit->beer_temperature = temp; |
141 unit->beer_temperature = temp; |
142 unit->beer_state = 0; |
142 unit->beer_state = 0; |
144 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
144 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp); |
145 if (debug) { |
145 if (debug) { |
146 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
146 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp); |
147 } |
147 } |
148 } |
148 } |
149 } else if (rc == 3) { |
149 } else if (rc == DEVPRESENT_ERROR) { |
150 unit->beer_state = 1; |
150 unit->beer_state = 1; |
151 } else { |
151 } else { |
152 unit->beer_state = 2; |
152 unit->beer_state = 2; |
153 } |
153 } |
154 } |
154 } |