185 |
188 |
186 while (retries--) { |
189 while (retries--) { |
187 if ((read(fn, &val, 1)) == 1) { |
190 if ((read(fn, &val, 1)) == 1) { |
188 rc = (int)val; |
191 rc = (int)val; |
189 goto leave; |
192 goto leave; |
190 // } else { |
|
191 // syslog(LOG_NOTICE, "read_w1() read %s try=%d: %s", addr, retries, strerror(errno)); |
|
192 } |
193 } |
193 } |
194 } |
194 syslog(LOG_NOTICE, "read_w1() read %s fatal: %s", addr, strerror(errno)); |
195 syslog(LOG_NOTICE, "read_w1() read %s fatal: %s", addr, strerror(errno)); |
195 |
196 |
196 } else { |
197 } else { |
384 piUnlock(LOCK_DEVICES); |
388 piUnlock(LOCK_DEVICES); |
385 #endif |
389 #endif |
386 |
390 |
387 return 0; |
391 return 0; |
388 } |
392 } |
|
393 |
|
394 |
|
395 /* |
|
396 * Returns 0 if failed. |
|
397 * Returns 1 if success, value contains new value. |
|
398 */ |
|
399 int device_in(char *uuid, int *value) |
|
400 { |
|
401 devices_list *device; |
|
402 |
|
403 if (uuid == NULL) |
|
404 return 0; |
|
405 |
|
406 #ifdef HAVE_WIRINGPI_H |
|
407 piLock(LOCK_DEVICES); |
|
408 #endif |
|
409 |
|
410 for (device = Config.devices; device; device = device->next) { |
|
411 if (! strcmp(uuid, device->uuid)) { |
|
412 |
|
413 } |
|
414 } |
|
415 |
|
416 #ifdef HAVE_WIRINGPI_H |
|
417 piUnlock(LOCK_DEVICES); |
|
418 #endif |
|
419 |
|
420 return 0; |
|
421 } |
|
422 |
389 |
423 |
390 |
424 |
391 |
425 |
392 /* |
426 /* |
393 * Auto detect hotplugged or known to be present devices |
427 * Auto detect hotplugged or known to be present devices |
519 ndev->uuid = malloc(37); |
553 ndev->uuid = malloc(37); |
520 uuid_generate(uu); |
554 uuid_generate(uu); |
521 uuid_unparse(uu, ndev->uuid); |
555 uuid_unparse(uu, ndev->uuid); |
522 ndev->type = DEVTYPE_GPIO; |
556 ndev->type = DEVTYPE_GPIO; |
523 ndev->value = digitalRead(pin); |
557 ndev->value = digitalRead(pin); |
|
558 ndev->offset = 0; |
524 ndev->present = DEVPRESENT_YES; |
559 ndev->present = DEVPRESENT_YES; |
525 ndev->address = xstrcpy((char *)"GPIO"); |
560 ndev->address = xstrcpy((char *)"GPIO"); |
526 snprintf(buf, 39, "Raspberry GPIO %d", i); |
561 snprintf(buf, 39, "Raspberry GPIO %d", i); |
527 ndev->description = xstrcpy(buf); |
562 ndev->description = xstrcpy(buf); |
528 ndev->subdevice = i; |
563 ndev->subdevice = i; |
876 device->present = DEVPRESENT_ERROR; |
911 device->present = DEVPRESENT_ERROR; |
877 } |
912 } |
878 piUnlock(LOCK_DEVICES); |
913 piUnlock(LOCK_DEVICES); |
879 } |
914 } |
880 break; |
915 break; |
|
916 |
|
917 case DEVTYPE_GPIO: |
|
918 if (device->direction == DEVDIR_IN_BIN) { |
|
919 piLock(LOCK_DEVICES); |
|
920 device->value = digitalRead(device->gpiopin); |
|
921 device->offset = 0; |
|
922 device->timestamp = time(NULL); |
|
923 piUnlock(LOCK_DEVICES); |
|
924 } |
|
925 break; |
|
926 |
881 #endif |
927 #endif |
882 #ifdef USE_SIMULATOR |
928 #ifdef USE_SIMULATOR |
883 case DEVTYPE_SIM: |
929 case DEVTYPE_SIM: |
884 #ifdef HAVE_WIRINGPI_H |
930 #ifdef HAVE_WIRINGPI_H |
885 piLock(LOCK_DEVICES); |
931 piLock(LOCK_DEVICES); |