# HG changeset patch # User Michiel Broek # Date 1427139287 -3600 # Node ID 3bbc8f42adc0588937a7f132a4f7b7df899beaea # Parent cfc952a68d4a99b45b71cfc87aa4061d66fa6126 Added device read for the DS2413 dual channel PIO diff -r cfc952a68d4a -r 3bbc8f42adc0 thermferm/devices.c --- a/thermferm/devices.c Fri Mar 20 22:49:22 2015 +0100 +++ b/thermferm/devices.c Mon Mar 23 20:34:47 2015 +0100 @@ -644,6 +644,59 @@ free(addr); addr = NULL; } + /* + * DS2413 Dual channel addressable switch + */ + unsigned char state; + + if (strncmp(device->address, (char *)"3a", 2) == 0) { + addr = xstrcpy((char *)"/sys/bus/w1/devices/"); + addr = xstrcat(addr, device->address); + addr = xstrcat(addr, (char *)"/state"); + if ((fp = fopen(addr, "r"))) { + if (device->present != DEVPRESENT_YES) { + syslog(LOG_NOTICE, "DS2413 %s is back", device->address); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_DEVICES); +#endif + device->present = DEVPRESENT_YES; +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif + } + if ((fread(&state, 1, 1, fp)) == 1) { +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_DEVICES); +#endif + /* + * Read PIOA or PIOB pin state bits + */ + if (device->subdevice == 0) + device->value = (state & 0x01) ? 0 : 1; + else if (device->subdevice == 1) + device->value = (state & 0x04) ? 0 : 1; + device->timestamp = time(NULL); +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif + } + fclose(fp); + } else { + if (device->present != DEVPRESENT_NO) { + syslog(LOG_NOTICE, "DS2413 %s is missing", device->address); +#ifdef HAVE_WIRINGPI_H + piLock(LOCK_DEVICES); +#endif + device->present = DEVPRESENT_NO; +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif + } + } + free(addr); + addr = NULL; + } + break; #ifdef HAVE_WIRINGPI_H