# HG changeset patch # User Michiel Broek # Date 1712834300 -7200 # Node ID b2e2cbb13cb37372d9101e8e2aa45a15633708f1 # Parent 6c62e99ade003eb706445ef599cceced331ad7c9 Finished one-wire ds2413 output diff -r 6c62e99ade00 -r b2e2cbb13cb3 thermferm/devices.c --- a/thermferm/devices.c Thu Apr 11 11:19:04 2024 +0200 +++ b/thermferm/devices.c Thu Apr 11 13:18:20 2024 +0200 @@ -236,7 +236,7 @@ { devices_list *device; time_t now, my_timestamp; - int rc, my_value, test_value; + int my_value, test_value; #ifdef HAVE_WIRINGPI_H int i; char buf[40]; @@ -296,30 +296,30 @@ * the "other" PIO channel. To make things a bit more complicated * the bits in the state register differ from the output register. */ - uint8_t state, output; +// uint8_t state, output; - if ((rc = read_w1(device->address, (char *)"state")) >= 0) { - state = (unsigned int)rc; - output = (state & 0x01) + ((state & 0x04) >> 1); +// if ((rc = read_w1(device->address, (char *)"state")) >= 0) { +// state = (unsigned int)rc; +// output = (state & 0x01) + ((state & 0x04) >> 1); - if (device->subdevice == 0) { - output = (output & 0xfe); - output |= (value == 0) ? 0x01 : 0x00; - } else if (device->subdevice == 1) { - output = (output & 0xfd); - output |= (value == 0) ? 0x02 : 0x00; - } else { - output = 0xff; - } +// if (device->subdevice == 0) { +// output = (output & 0xfe); +// output |= (value == 0) ? 0x01 : 0x00; +// } else if (device->subdevice == 1) { +// output = (output & 0xfd); +// output |= (value == 0) ? 0x02 : 0x00; +// } else { +// output = 0xff; +// } - if ((write_w1(device->address, (char *)"output", output)) == 0) { +// if ((write_w1(device->address, (char *)"output", output)) == 0) { syslog(LOG_NOTICE, "DS2413 PIO%c value=%d (%s)", (device->subdevice == 0) ? 'A' : 'B', (value == 0) ? 0 : 1, device->comment); // pthread_mutex_lock(&mutexes[LOCK_DEVICES]); device->value = (value == 0) ? 0 : 1; device->timestamp = time(NULL); // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); - } - } +// } +// } } } diff -r 6c62e99ade00 -r b2e2cbb13cb3 thermferm/one-wire.c --- a/thermferm/one-wire.c Thu Apr 11 11:19:04 2024 +0200 +++ b/thermferm/one-wire.c Thu Apr 11 13:18:20 2024 +0200 @@ -160,7 +160,7 @@ pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]); } } else if (strcmp(w1type, (char *)"00")) { - syslog(LOG_NOTICE, "One-wire device %d %s unknown", strlen(buffer), buffer); + syslog(LOG_NOTICE, "One-wire device %ld %s unknown", strlen(buffer), buffer); } } fclose(fp); @@ -255,6 +255,33 @@ // pthread_mutex_unlock(&mutexes[LOCK_DEVICES]); } mDelay(20); + } else if ((strcmp(dev_w1->address, device->address) == 0) && (device->subdevice == i) && (device->direction == DEVDIR_OUT_BIN)) { + /* + * Sync output state + */ + if ((rc = read_w1(device->address, (char *)"state")) >= 0) { + state = (unsigned int)rc; + newval = output = (state & 0x01) + ((state & 0x04) >> 1); + + if (device->subdevice == 0) { + newval = (newval & 0xfe); + newval |= (device->value) ? 0x00 : 0x01; + } else if (device->subdevice == 1) { + newval = (newval & 0xfd); + newval |= (device->value) ? 0x00 : 0x02; + } + + if (output != newval) { + if ((rc = write_w1(dev_w1->address, (char *)"output", newval)) == 0) { + syslog(LOG_NOTICE, "One-wire device %s-%d out %02x -> %02x", dev_w1->address, i, output, newval); + dev_w1->value = newval; + } else { + syslog(LOG_NOTICE, "One-wire device %s-%d write output rc=%d", dev_w1->address, i, rc); + } + } + } else { + syslog(LOG_NOTICE, "One-wire device %s-%d read state rc=%d", dev_w1->address, i, rc); + } } } /* for (device = Config.devices; ... */ } diff -r 6c62e99ade00 -r b2e2cbb13cb3 thermferm/thermferm.h --- a/thermferm/thermferm.h Thu Apr 11 11:19:04 2024 +0200 +++ b/thermferm/thermferm.h Thu Apr 11 13:18:20 2024 +0200 @@ -314,7 +314,6 @@ char family[3]; ///< Device family int present; ///< Present on bus int value; ///< Last value -// int subdevices; ///< Number of subdevices time_t timestamp; ///< Last seen } w1_list;