thermferm/one-wire.c

changeset 731
8b7c63bddf75
parent 728
da038d0bed04
child 732
b0e99e30a008
--- a/thermferm/one-wire.c	Sun May 05 17:24:54 2024 +0200
+++ b/thermferm/one-wire.c	Mon May 06 15:34:32 2024 +0200
@@ -62,8 +62,11 @@
     payload = xstrcat(payload, (char *)"\",\"value\":");
     snprintf(vbuf, 63, "%d", dev_w1->value);
     payload = xstrcat(payload, vbuf);
-    payload = xstrcat(payload, (char *)",\"resolution\":");
-    snprintf(vbuf, 63, "%d", dev_w1->resolution);
+    payload = xstrcat(payload, (char *)",\"rd_cache\":");
+    snprintf(vbuf, 63, "%d", dev_w1->rd_cache);
+    payload = xstrcat(payload, vbuf);
+    payload = xstrcat(payload, (char *)",\"wr_cache\":");
+    snprintf(vbuf, 63, "%d", dev_w1->wr_cache);
     payload = xstrcat(payload, vbuf);
     payload = xstrcat(payload, (char *)",\"timestamp\":");
     snprintf(vbuf, 63, "%ld", (long)dev_w1->timestamp);
@@ -183,7 +186,8 @@
 			syslog(LOG_NOTICE, "One-wire device %s is back", buffer);
 			pthread_mutex_lock(&mutexes[LOCK_ONE_WIRE]);
 			dev_w1->present = DEVPRESENT_YES;
-			dev_w1->resolution = 0;			/* Might be wrong, so reset */
+			dev_w1->rd_cache = 0;			/* Might be wrong, so reset	*/
+			dev_w1->wr_cache = 0;			/* Not used here		*/
 			dev_w1->timestamp = time(NULL);
 			pthread_mutex_unlock(&mutexes[LOCK_ONE_WIRE]);
 			changed = true;
@@ -201,7 +205,7 @@
 		n_w1->family[2] = '\0';
 		n_w1->present = DEVPRESENT_YES;
 		n_w1->value = (strcmp(w1type, (char *)"3a") == 0) ? 3:-1;
-		n_w1->resolution = 0;
+		n_w1->rd_cache = n_w1->wr_cache = 0;
 		n_w1->timestamp = time(NULL);
 		changed = true;
 
@@ -292,8 +296,10 @@
 				if ((rc = read_w1(device->address, (char *)"state")) >= 0)      /* Read PIO again       */
 				    state = (unsigned int)rc;
 			    }
+			    dev_w1->rd_cache = state;
 
 			    newval = ((state & 0x04) >> 1) + (state & 0x01);
+			    dev_w1->wr_cache = newval;
 			    if (newval != dev_w1->value) {
 			    	syslog(LOG_NOTICE, "One-wire device %s-%d in %02x value %d => %d", dev_w1->address, i, state, dev_w1->value, newval);
 			    	dev_w1->value = newval;
@@ -329,6 +335,7 @@
 				newval |= (device->value) ? 0x00 : 0x02;
 			    }
 
+			    dev_w1->wr_cache = newval;
 			    if (output != newval) {
 				if ((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);
@@ -365,7 +372,7 @@
 	     * Check and correct resolution. Only do this for new sensors
 	     * or known sensors that are plugged in again.
 	     */
-	    if (cur_w1->resolution != W1_TEMP_RESOLUTION) {
+	    if (cur_w1->rd_cache != W1_TEMP_RESOLUTION) {
 	    	devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
 	    	devfile = xstrcat(devfile, cur_w1->address);
 	    	devfile = xstrcat(devfile, (char *)"/resolution");
@@ -379,7 +386,7 @@
 			    sprintf(buffer, "%d", W1_TEMP_RESOLUTION);
 			    fputs(buffer, fp);
 		     	}
-			cur_w1->resolution = W1_TEMP_RESOLUTION;
+			cur_w1->rd_cache = W1_TEMP_RESOLUTION;
 		    }
 		    fclose(fp);
 	    	} else {

mercurial