234 |
234 |
235 int device_out(char *uuid, int value) |
235 int device_out(char *uuid, int value) |
236 { |
236 { |
237 devices_list *device; |
237 devices_list *device; |
238 time_t now, my_timestamp; |
238 time_t now, my_timestamp; |
239 int rc, my_value, test_value; |
239 int my_value, test_value; |
240 #ifdef HAVE_WIRINGPI_H |
240 #ifdef HAVE_WIRINGPI_H |
241 int i; |
241 int i; |
242 char buf[40]; |
242 char buf[40]; |
243 #endif |
243 #endif |
244 |
244 |
294 /* |
294 /* |
295 * DS2413. First read state so that we can preserve the state of |
295 * DS2413. First read state so that we can preserve the state of |
296 * the "other" PIO channel. To make things a bit more complicated |
296 * the "other" PIO channel. To make things a bit more complicated |
297 * the bits in the state register differ from the output register. |
297 * the bits in the state register differ from the output register. |
298 */ |
298 */ |
299 uint8_t state, output; |
299 // uint8_t state, output; |
300 |
300 |
301 if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
301 // if ((rc = read_w1(device->address, (char *)"state")) >= 0) { |
302 state = (unsigned int)rc; |
302 // state = (unsigned int)rc; |
303 output = (state & 0x01) + ((state & 0x04) >> 1); |
303 // output = (state & 0x01) + ((state & 0x04) >> 1); |
304 |
304 |
305 if (device->subdevice == 0) { |
305 // if (device->subdevice == 0) { |
306 output = (output & 0xfe); |
306 // output = (output & 0xfe); |
307 output |= (value == 0) ? 0x01 : 0x00; |
307 // output |= (value == 0) ? 0x01 : 0x00; |
308 } else if (device->subdevice == 1) { |
308 // } else if (device->subdevice == 1) { |
309 output = (output & 0xfd); |
309 // output = (output & 0xfd); |
310 output |= (value == 0) ? 0x02 : 0x00; |
310 // output |= (value == 0) ? 0x02 : 0x00; |
311 } else { |
311 // } else { |
312 output = 0xff; |
312 // output = 0xff; |
313 } |
313 // } |
314 |
314 |
315 if ((write_w1(device->address, (char *)"output", output)) == 0) { |
315 // if ((write_w1(device->address, (char *)"output", output)) == 0) { |
316 syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); |
316 syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); |
317 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
317 // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); |
318 device->value = (value == 0) ? 0 : 1; |
318 device->value = (value == 0) ? 0 : 1; |
319 device->timestamp = time(NULL); |
319 device->timestamp = time(NULL); |
320 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
320 // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); |
321 } |
321 // } |
322 } |
322 // } |
323 } |
323 } |
324 } |
324 } |
325 |
325 |
326 #ifdef USE_SIMULATOR |
326 #ifdef USE_SIMULATOR |
327 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { |
327 if ((device->type == DEVTYPE_SIM) && (device->direction == DEVDIR_OUT_BIN) && (device->present == DEVPRESENT_YES)) { |