Added device read for the DS2413 dual channel PIO

Mon, 23 Mar 2015 20:34:47 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 23 Mar 2015 20:34:47 +0100
changeset 342
3bbc8f42adc0
parent 341
cfc952a68d4a
child 343
ba3a2d27d59e

Added device read for the DS2413 dual channel PIO

thermferm/devices.c file | annotate | diff | comparison | revisions
--- 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

mercurial