Possible part of DS2408 code added.

Fri, 20 Mar 2015 22:49:22 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 20 Mar 2015 22:49:22 +0100
changeset 341
cfc952a68d4a
parent 340
5b49416eb116
child 342
3bbc8f42adc0

Possible part of DS2408 code added.

thermferm/devices.c file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Fri Mar 20 22:22:18 2015 +0100
+++ b/thermferm/devices.c	Fri Mar 20 22:49:22 2015 +0100
@@ -603,6 +603,46 @@
 			    }
 			    free(addr);
 			    addr = NULL;
+			} /* if temperature sensor */
+			/*
+			 * DS2408 8 Channel addressable switch
+			 */
+			if (strncmp(device->address, (char *)"29", 2) == 0) {
+			    /*
+			     * Always read current state and set these bits
+			     * in the subdevices value. We do this even with
+			     * the output bits, they should match.
+			     */
+			    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, "DS2408 %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
+				}
+
+				fclose(fp);
+			    } else {
+				if (device->present != DEVPRESENT_NO) {
+				    syslog(LOG_NOTICE, "DS2408 %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;
 

mercurial