thermferm/one-wire.c

changeset 671
b2e2cbb13cb3
parent 670
6c62e99ade00
child 672
0c2c66920d79
equal deleted inserted replaced
670:6c62e99ade00 671:b2e2cbb13cb3
158 } 158 }
159 } 159 }
160 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); 160 pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
161 } 161 }
162 } else if (strcmp(w1type, (char *)"00")) { 162 } else if (strcmp(w1type, (char *)"00")) {
163 syslog(LOG_NOTICE, "One-wire device %d %s unknown", strlen(buffer), buffer); 163 syslog(LOG_NOTICE, "One-wire device %ld %s unknown", strlen(buffer), buffer);
164 } 164 }
165 } 165 }
166 fclose(fp); 166 fclose(fp);
167 SM_PROCEED(ScanDel); 167 SM_PROCEED(ScanDel);
168 168
253 device->value = (state & 0x04) ? 0 : 1; 253 device->value = (state & 0x04) ? 0 : 1;
254 device->timestamp = time(NULL); 254 device->timestamp = time(NULL);
255 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); 255 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
256 } 256 }
257 mDelay(20); 257 mDelay(20);
258 } else if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_OUT_BIN)) {
259 /*
260 * Sync output state
261 */
262 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
263 state = (unsigned int)rc;
264 newval = output = (state & 0x01) + ((state & 0x04) >> 1);
265
266 if (device->subdevice == 0) {
267 newval = (newval & 0xfe);
268 newval |= (device->value) ? 0x00 : 0x01;
269 } else if (device->subdevice == 1) {
270 newval = (newval & 0xfd);
271 newval |= (device->value) ? 0x00 : 0x02;
272 }
273
274 if (output != newval) {
275 if ((rc = write_w1(dev_w1->address, (char *)"output", newval)) == 0) {
276 syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, newval);
277 dev_w1->value = newval;
278 } else {
279 syslog(LOG_NOTICE, "One-wire device %s-%d write output rc=%d", dev_w1->address, i, rc);
280 }
281 }
282 } else {
283 syslog(LOG_NOTICE, "One-wire device %s-%d read state rc=%d", dev_w1->address, i, rc);
284 }
258 } 285 }
259 } /* for (device = Config.devices; ... */ 286 } /* for (device = Config.devices; ... */
260 } 287 }
261 } 288 }
262 } 289 }

mercurial