# HG changeset patch # User Michiel Broek # Date 1712154106 -7200 # Node ID 38162f3748423627b056ffdaca614a88257c4c25 # Parent ca47c742a25d7dc537e9b93590f03dbe41daeadf Read ds2413 moved to one-wire thread. Only reprogram if it is an input and programmed as output. diff -r ca47c742a25d -r 38162f374842 thermferm/devices.c --- a/thermferm/devices.c Wed Apr 03 12:14:45 2024 +0200 +++ b/thermferm/devices.c Wed Apr 03 16:21:46 2024 +0200 @@ -835,66 +835,6 @@ free(addr); addr = NULL; } /* if temperature sensor */ - /* - * DS2413 Dual channel addressable switch - */ - 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 ((access(addr, R_OK)) == 0) { - if (device->present != DEVPRESENT_YES) { - syslog(LOG_NOTICE, "DS2413 %s is back", device->address); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); - device->present = DEVPRESENT_YES; - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); - } - /* - * 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) { - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); - /* - * Read PIOA or PIOB pin state bits - */ - if (device->subdevice == 0) - device->value = (rc & 0x01) ? 0 : 1; - else if (device->subdevice == 1) - device->value = (rc & 0x04) ? 0 : 1; - device->timestamp = time(NULL); - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); - } - } else { - if (device->present != DEVPRESENT_NO) { - syslog(LOG_NOTICE, "DS2413 %s is missing", device->address); - pthread_mutex_lock(&mutexes[LOCK_DEVICES]); - device->present = DEVPRESENT_NO; - pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); - } - } - free(addr); - addr = NULL; - } break; diff -r ca47c742a25d -r 38162f374842 thermferm/one-wire.c --- a/thermferm/one-wire.c Wed Apr 03 12:14:45 2024 +0200 +++ b/thermferm/one-wire.c Wed Apr 03 16:21:46 2024 +0200 @@ -166,25 +166,29 @@ for (device = Config.devices; device; device = device->next) { if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_IN_BIN)) { /* - * First make sure that if this device is configured as input - * to drive the output high. - * TODO: This must be made different. Check state and fix only if wrong. + * First make sure that this device is configured as input + * to drive the output high. Fix if programmed as 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 (i == 0) { - output = (output & 0xfe); + output = ((state & 0x02) >> 1) + ((state & 0x08) >> 2); /* Both latch states */ + if ((i == 0) && ((state & 0x02) == 0)) { /* Fix A side */ + syslog(LOG_NOTICE, "One-wire device %s-%d out %04x -> %04x", dev_w1->address, i, output, output | 0x01); output |= 0x01; - } else if (i == 1) { - output = (output & 0xfd); + write_w1(device->address, (char *)"output", output); + mDelay(10); + if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ + state = (unsigned int)rc; + } + if ((i == 1) && ((state & 0x08) == 0)) { /* Fix B side */ + syslog(LOG_NOTICE, "One-wire device %s-%d out %04x -> %04x", dev_w1->address, i, output, output | 0x02); output |= 0x02; - } else { - output = 0xff; + write_w1(device->address, (char *)"output", output); + mDelay(10); + if ((rc = read_w1(device->address, (char *)"state")) >= 0) /* Read PIO again */ + state = (unsigned int)rc; } - write_w1(device->address, (char *)"output", output); - } - if ((rc = read_w1(device->address, (char *)"state")) >= 0) { + pthread_mutex_lock(&mutexes[LOCK_DEVICES]); /* * Read PIOA or PIOB pin state bits @@ -198,7 +202,7 @@ } mDelay(20); } - } + } /* for (device = Config.devices; ... */ } } }