# HG changeset patch # User Michiel Broek # Date 1444051306 -7200 # Node ID ec507c1f1df7d45c9d88e3cf56c7b10e56ad36c7 # Parent ee8f851b4d93f57fac7d32044a25ca9bd9ba4614 Make sure that a DS2413 device used as input has the output latch turned off. diff -r ee8f851b4d93 -r ec507c1f1df7 thermferm/devices.c --- a/thermferm/devices.c Fri Sep 18 12:55:49 2015 +0200 +++ b/thermferm/devices.c Mon Oct 05 15:21:46 2015 +0200 @@ -820,6 +820,28 @@ piUnlock(LOCK_DEVICES); #endif } + /* + * First make sure that if this device is configured as input + * to drive the output high. + */ + if (device->direction == DEVDIR_IN_BIN) { + uint8_t state, output; + + if ((rc = read_w1(device->address, (char *)"state")) >= 0) { + state = (unsigned int)rc; + output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */ + if (device->subdevice == 0) { + output = (output & 0xfe); + output |= 0x01; + } else if (device->subdevice == 1) { + output = (output & 0xfd); + output |= 0x02; + } else { + output = 0xff; + } + write_w1(device->address, (char *)"output", output); + } + } if ((rc = read_w1(device->address, (char *)"state")) >= 0) { #ifdef HAVE_WIRINGPI_H piLock(LOCK_DEVICES);