One-wire tread more relaxed logging.

Fri, 05 Apr 2024 20:10:26 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 05 Apr 2024 20:10:26 +0200
changeset 662
56c72393ca26
parent 661
8c1e7a52e24f
child 663
fa39f9c0e219

One-wire tread more relaxed logging.

thermferm/one-wire.c file | annotate | diff | comparison | revisions
--- a/thermferm/one-wire.c	Fri Apr 05 19:30:41 2024 +0200
+++ b/thermferm/one-wire.c	Fri Apr 05 20:10:26 2024 +0200
@@ -83,7 +83,7 @@
     devices_list	*device;
     w1_list		*dev_w1, *n_w1, *cur_w1 = NULL;
     char		buffer[25], w1type[10], *devfile = NULL;
-    uint8_t		state, output;
+    uint8_t		state, output, newval;
 
 SM_START(ScanNew)
 
@@ -237,8 +237,11 @@
 				    state = (unsigned int)rc;
 			    }
 
-			    dev_w1->value = ((state & 0x04) >> 1) + (state & 0x01);
-			    syslog(LOG_NOTICE, "One-wire device %s-%d in %02x value %d", dev_w1->address, i, state, dev_w1->value);
+			    newval = ((state & 0x04) >> 1) + (state & 0x01);
+			    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;
+			    }
 
 //			    pthread_mutex_lock(&mutexes[LOCK_DEVICES]);
 			    /*
@@ -274,14 +277,6 @@
 	if ((strcmp(cur_w1->family, (char *)"10") == 0) || (strcmp(cur_w1->family, (char *)"22") == 0) || (strcmp(cur_w1->family, (char *)"28") == 0) ||
 	    (strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0)) {
 //	    syslog(LOG_NOTICE, "Reading %s", cur_w1->address);
-	    /*
-	     * 1. Read sensor resolution. This is a present check too.
-	     * 2. Fix resolution if wrong.
-	     * 3. Read conversion time.
-	     * 4. Open temperature for read.
-	     * 5. Wait conversion time.
-	     * 6. Read temperature.
-	     */
 	    devfile = xstrcpy((char *)"/sys/bus/w1/devices/");
 	    devfile = xstrcat(devfile, cur_w1->address);
 	    devfile = xstrcat(devfile, (char *)"/resolution");
@@ -314,11 +309,12 @@
 		devfile = xstrcat(devfile, cur_w1->address);
 		devfile = xstrcat(devfile, (char *)"/temperature");
 		if ((fp = fopen(devfile, "r"))) {
-		    syslog(LOG_NOTICE, "One-wire device %s temperature is open, delay %d", cur_w1->address, conv_time);
+//		    syslog(LOG_NOTICE, "One-wire device %s temperature is open, delay %d", cur_w1->address, conv_time);
 		    mDelay(conv_time);
 		    if ((fgets(buffer, 25, fp))) {
 			sscanf(buffer, "%d", &value);
-			syslog(LOG_NOTICE, "One-wire device %s temperature read %d", cur_w1->address, value);
+			if (cur_w1->value != value)
+			    syslog(LOG_NOTICE, "One-wire device %s temperature read %d => %d", cur_w1->address, cur_w1->value, value);
 			cur_w1->value = value;		/* devices.c will pick this up */
 		    } else {
 			syslog(LOG_NOTICE, "One-wire device %s temperature read error", cur_w1->address);
@@ -343,11 +339,11 @@
 		(strcmp(cur_w1->family, (char *)"3b") == 0) || (strcmp(cur_w1->family, (char *)"42") == 0))
 		break;
 	}
-	syslog(LOG_NOTICE, "One-wire device %s next sensor %s", cur_w1->address, cur_w1->family);
+//	syslog(LOG_NOTICE, "One-wire device %s next sensor %s", cur_w1->address, cur_w1->family);
 
     } else {
-	syslog(LOG_NOTICE, "cur_w1 == NULL");
-    	sleep(1);
+//	syslog(LOG_NOTICE, "cur_w1 == NULL");
+    	mDelay(750);
     }
 
     SM_PROCEED(Missing);

mercurial