thermferm/devices.c

changeset 657
38162f374842
parent 656
ca47c742a25d
child 658
b10d0f6337a3
equal deleted inserted replaced
656:ca47c742a25d 657:38162f374842
833 } 833 }
834 } 834 }
835 free(addr); 835 free(addr);
836 addr = NULL; 836 addr = NULL;
837 } /* if temperature sensor */ 837 } /* if temperature sensor */
838 /*
839 * DS2413 Dual channel addressable switch
840 */
841 if (strncmp(device->address, (char *)"3a", 2) == 0) {
842 addr = xstrcpy((char *)"/sys/bus/w1/devices/");
843 addr = xstrcat(addr, device->address);
844 addr = xstrcat(addr, (char *)"/state");
845
846 if ((access(addr, R_OK)) == 0) {
847 if (device->present != DEVPRESENT_YES) {
848 syslog(LOG_NOTICE, "DS2413 %s is back", device->address);
849 pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
850 device->present = DEVPRESENT_YES;
851 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
852 }
853 /*
854 * First make sure that if this device is configured as input
855 * to drive the output high.
856 */
857 if (device->direction == DEVDIR_IN_BIN) {
858 uint8_t state, output;
859
860 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
861 state = (unsigned int)rc;
862 output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */
863 if (device->subdevice == 0) {
864 output = (output & 0xfe);
865 output |= 0x01;
866 } else if (device->subdevice == 1) {
867 output = (output & 0xfd);
868 output |= 0x02;
869 } else {
870 output = 0xff;
871 }
872 write_w1(device->address, (char *)"output", output);
873 }
874 }
875 if ((rc = read_w1(device->address, (char *)"state")) >= 0) {
876 pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
877 /*
878 * Read PIOA or PIOB pin state bits
879 */
880 if (device->subdevice == 0)
881 device->value = (rc & 0x01) ? 0 : 1;
882 else if (device->subdevice == 1)
883 device->value = (rc & 0x04) ? 0 : 1;
884 device->timestamp = time(NULL);
885 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
886 }
887 } else {
888 if (device->present != DEVPRESENT_NO) {
889 syslog(LOG_NOTICE, "DS2413 %s is missing", device->address);
890 pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
891 device->present = DEVPRESENT_NO;
892 pthread_mutex_unlock(&mutexes[LOCK_DEVICES]);
893 }
894 }
895 free(addr);
896 addr = NULL;
897 }
898 838
899 break; 839 break;
900 840
901 case DEVTYPE_DHT: 841 case DEVTYPE_DHT:
902 /* 842 /*

mercurial