thermferm/one-wire.c

changeset 671
b2e2cbb13cb3
parent 670
6c62e99ade00
child 672
0c2c66920d79
--- 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; ... */
 	    }

mercurial