--- a/thermferm/devices.c Tue Sep 15 15:37:39 2015 +0200 +++ b/thermferm/devices.c Tue Sep 15 17:26:26 2015 +0200 @@ -236,8 +236,6 @@ if ((write(fn, &val, 1)) == 1) { rc = 0; goto leave; -// } else { -// syslog(LOG_NOTICE, "write_w1() write %s try=%d: %s", addr, retries, strerror(errno)); } } syslog(LOG_NOTICE, "write_w1() write %s fatal: %s", addr, strerror(errno)); @@ -393,12 +391,13 @@ /* - * Returns 0 if failed. - * Returns 1 if success, value contains new value. + * Returns DEVPRESENT_NO if failed. + * Returns DEVPRESENT_YES if success, value contains new value. */ int device_in(char *uuid, int *value) { devices_list *device; + int tmp, present; if (uuid == NULL) return 0; @@ -409,7 +408,17 @@ for (device = Config.devices; device; device = device->next) { if (! strcmp(uuid, device->uuid)) { - + present = device->present; + if (present == DEVPRESENT_YES) { + tmp = device->value + device->offset; + } else { + tmp = 0; + } +#ifdef HAVE_WIRINGPI_H + piUnlock(LOCK_DEVICES); +#endif + *value = tmp; + return present; } } @@ -417,7 +426,7 @@ piUnlock(LOCK_DEVICES); #endif - return 0; + return DEVPRESENT_NO; } @@ -480,9 +489,6 @@ } else if (strcmp(buf, (char *)"28") == 0) { ndev->direction = DEVDIR_IN_ANALOG; ndev->description = xstrcpy((char *)"DS18B20 Digital thermometer"); - } else if (strcmp(buf, (char *)"29") == 0) { - ndev->description = xstrcpy((char *)"DS2408 8 Channel addressable switch/LCD"); - ndev->direction = DEVDIR_IN_BIN; } else if (strcmp(buf, (char *)"3a") == 0) { ndev->description = xstrcpy((char *)"DS2413 Dual channel addressable switch"); ndev->direction = DEVDIR_IN_BIN; @@ -796,46 +802,6 @@ 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; - } - /* * DS2413 Dual channel addressable switch */ if (strncmp(device->address, (char *)"3a", 2) == 0) {