Code cleanup

Sun, 10 Aug 2014 20:01:17 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Aug 2014 20:01:17 +0200
changeset 212
a76cbe676bf1
parent 211
81160e2e738c
child 213
2317b8d644fa

Code cleanup

thermferm/devices.c file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Sun Aug 10 17:43:33 2014 +0200
+++ b/thermferm/devices.c	Sun Aug 10 20:01:17 2014 +0200
@@ -180,8 +180,8 @@
 	if (strcmp(uuid, device->uuid) == 0) {
 	    /*
 	     * Execute command if different then the old value. But also
-	     * every 2 minutes because commands can get lost of devices were
-	     * disconnected, or with radio problems.
+	     * every 2 minutes because commands can have temporary
+	     * disconnects, or have radio problems.
 	     */
 	    if ((value != device->value) || (((int)now - (int)device->timestamp) > 120)) {
 
@@ -189,7 +189,7 @@
 		rc = 0;
 		if ((device->type == DEVTYPE_RC433) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
 	            enableTransmit(device->gpiopin);
-		    usleep(10000);
+//		    usleep(10000);
 		    snprintf(buf, 39, "%s,%d", device->address, value ? 1:0);
 		    for (i = 0; i < strlen(buf); i++)
 			if (buf[i] == '-')
@@ -198,12 +198,12 @@
 		    syslog(LOG_NOTICE, "RC433 command %s rc=%d", buf, rc);
 		    if (debug)
 			fprintf(stdout, "RC433 command %s rc=%d\n", buf, rc);
-		    usleep(50000);
+//		    usleep(50000);
 		    disableTransmit();
-		}
-                device->value = value;
-		device->timestamp = time(NULL);
-		return rc;
+                    device->value = value;
+		    device->timestamp = time(NULL);
+		    return rc;
+	        }
 
 		if ((device->type == DEVTYPE_GPIO) && (device->gpiopin != -1) && (device->present == DEVPRESENT_YES)) {
 
@@ -498,8 +498,12 @@
 		default:
 			break;
 	    }
-    	}
-	usleep(10000);
+
+	    /*
+	     * Delay a bit after procesing a device.
+	     */
+	    usleep(10000);
+	}
     }
 
     syslog(LOG_NOTICE, "Thread my_devices_loop stopped");

mercurial