642 } |
642 } |
643 } |
643 } |
644 free(addr); |
644 free(addr); |
645 addr = NULL; |
645 addr = NULL; |
646 } |
646 } |
|
647 /* |
|
648 * DS2413 Dual channel addressable switch |
|
649 */ |
|
650 unsigned char state; |
|
651 |
|
652 if (strncmp(device->address, (char *)"3a", 2) == 0) { |
|
653 addr = xstrcpy((char *)"/sys/bus/w1/devices/"); |
|
654 addr = xstrcat(addr, device->address); |
|
655 addr = xstrcat(addr, (char *)"/state"); |
|
656 if ((fp = fopen(addr, "r"))) { |
|
657 if (device->present != DEVPRESENT_YES) { |
|
658 syslog(LOG_NOTICE, "DS2413 %s is back", device->address); |
|
659 #ifdef HAVE_WIRINGPI_H |
|
660 piLock(LOCK_DEVICES); |
|
661 #endif |
|
662 device->present = DEVPRESENT_YES; |
|
663 #ifdef HAVE_WIRINGPI_H |
|
664 piUnlock(LOCK_DEVICES); |
|
665 #endif |
|
666 } |
|
667 if ((fread(&state, 1, 1, fp)) == 1) { |
|
668 #ifdef HAVE_WIRINGPI_H |
|
669 piLock(LOCK_DEVICES); |
|
670 #endif |
|
671 /* |
|
672 * Read PIOA or PIOB pin state bits |
|
673 */ |
|
674 if (device->subdevice == 0) |
|
675 device->value = (state & 0x01) ? 0 : 1; |
|
676 else if (device->subdevice == 1) |
|
677 device->value = (state & 0x04) ? 0 : 1; |
|
678 device->timestamp = time(NULL); |
|
679 #ifdef HAVE_WIRINGPI_H |
|
680 piUnlock(LOCK_DEVICES); |
|
681 #endif |
|
682 } |
|
683 fclose(fp); |
|
684 } else { |
|
685 if (device->present != DEVPRESENT_NO) { |
|
686 syslog(LOG_NOTICE, "DS2413 %s is missing", device->address); |
|
687 #ifdef HAVE_WIRINGPI_H |
|
688 piLock(LOCK_DEVICES); |
|
689 #endif |
|
690 device->present = DEVPRESENT_NO; |
|
691 #ifdef HAVE_WIRINGPI_H |
|
692 piUnlock(LOCK_DEVICES); |
|
693 #endif |
|
694 } |
|
695 } |
|
696 free(addr); |
|
697 addr = NULL; |
|
698 } |
|
699 |
647 break; |
700 break; |
648 |
701 |
649 #ifdef HAVE_WIRINGPI_H |
702 #ifdef HAVE_WIRINGPI_H |
650 case DEVTYPE_DHT: |
703 case DEVTYPE_DHT: |
651 /* |
704 /* |