# HG changeset patch # User Michiel Broek # Date 1442330786 -7200 # Node ID e32e8355096327809affca190941131affa97334 # Parent 14231379bec2efddee1b7f70dddf48f1582f5f5c Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip. diff -r 14231379bec2 -r e32e83550963 thermferm/devices.c --- 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) { diff -r 14231379bec2 -r e32e83550963 thermferm/thermferm.c --- a/thermferm/thermferm.c Tue Sep 15 15:37:39 2015 +0200 +++ b/thermferm/thermferm.c Tue Sep 15 17:26:26 2015 +0200 @@ -277,30 +277,6 @@ -int read_sensor(char *address, int *val) -{ - devices_list *device; - int tmp; - - for (device = Config.devices; device; device = device->next) { - if (strcmp(address, device->uuid) == 0) { -#ifdef HAVE_WIRINGPI_H - piLock(LOCK_DEVICES); -#endif - tmp = device->value + device->offset; -#ifdef HAVE_WIRINGPI_H - piUnlock(LOCK_DEVICES); -#endif - *val = tmp; - return device->present; - } - } - - return DEVPRESENT_NO; -} - - - /* * Handle panel key events */ @@ -1003,7 +979,7 @@ #endif if (Config.temp_address) { - rc = read_sensor(Config.temp_address, &temp); + rc = device_in(Config.temp_address, &temp); if (rc == DEVPRESENT_YES) { Config.temp_value = temp; Config.temp_state = 0; @@ -1020,7 +996,7 @@ } if (Config.hum_address) { - rc = read_sensor(Config.hum_address, &temp); + rc = device_in(Config.hum_address, &temp); if (rc == DEVPRESENT_YES) { Config.hum_value = temp; Config.hum_state = 0; @@ -1045,7 +1021,7 @@ #endif if (unit->air_address) { - rc = read_sensor(unit->air_address, &temp); + rc = device_in(unit->air_address, &temp); if (rc == DEVPRESENT_YES) { /* * It is possible to have read errors or extreme values. @@ -1079,7 +1055,7 @@ } if (unit->beer_address) { - rc = read_sensor(unit->beer_address, &temp); + rc = device_in(unit->beer_address, &temp); if (rc == DEVPRESENT_YES) { deviation = 40000; if ((unit->beer_temperature == 0) || @@ -1105,7 +1081,7 @@ } if (unit->door_address) { - rc = read_sensor(unit->door_address, &temp); + rc = device_in(unit->door_address, &temp); if (rc == DEVPRESENT_YES) { if (temp) { if (unit->door_state == 0) { @@ -1129,7 +1105,7 @@ } if (unit->psu_address) { - rc = read_sensor(unit->psu_address, &temp); + rc = device_in(unit->psu_address, &temp); if (rc == DEVPRESENT_YES) { if (temp) { if (unit->psu_state == 0) {