thermferm/thermferm.c

changeset 75
4b976601737d
parent 74
879bd09e2b96
child 80
81bf78a7618e
--- a/thermferm/thermferm.c	Tue Jun 24 20:21:07 2014 +0200
+++ b/thermferm/thermferm.c	Tue Jun 24 22:38:46 2014 +0200
@@ -30,10 +30,10 @@
 key_t			key = 5680;		/* key to be passed to shmget()		*/
 int			shmid;
 
-bool			my_shutdown = false;
+int			my_shutdown = FALSE;
 static pid_t		pgrp, mypid;
 
-extern bool		debug;
+extern int		debug;
 extern sys_config	Config;
 #ifdef HAVE_WIRINGPI_H
 extern int		lcdHandle;
@@ -77,7 +77,7 @@
 	default:	syslog(LOG_NOTICE, "die() on signal %d", onsig);
     }
 
-    my_shutdown = true;
+    my_shutdown = TRUE;
 }
 
 
@@ -113,7 +113,7 @@
 	    break;
 
 	switch (c) {
-	    case 'd':	debug = true;
+	    case 'd':	debug = TRUE;
 			break;
 	    case 'h':	help();
 			return 1;
@@ -242,21 +242,29 @@
 #ifdef HAVE_WIRINGPI_H
     rc = piThreadCreate(my_sensors_loop);
 #else
-    rc = pthread_create(&threads[0], NULL, my_sensors_loop, (void *)t );
+    rc = pthread_create(&threads[t], NULL, my_sensors_loop, (void *)t );
 #endif
     if (rc) {
 	fprintf(stderr, "my_sensors_loop thread didn't start rc=%d\n", rc);
 	syslog(LOG_NOTICE, "my_sensors_loop thread didn't start rc=%d", rc);
+#ifndef HAVE_WIRINGPI_H
+    } else {
+	t++;
+#endif
     }
 
 #ifdef HAVE_WIRINGPI_H
     rc = piThreadCreate(my_server_loop);
 #else
-    rc = pthread_create(&threads[1], NULL, my_server_loop, (void *)t );
+    rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
 #endif
     if (rc) {
 	fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc);
 	syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc);
+#ifndef HAVE_WIRINGPI_H
+    } else {
+	t++;
+#endif
     }
 
     snprintf(buf, 1023, "tempA,tempB");
@@ -268,15 +276,11 @@
 	if (my_shutdown)
 	    run = 0;
 
-	tmp1 = Config.w1therms;
-	if (tmp1->update) {
-	    tmp1->update = FALSE;
-	    lcdupdate = TRUE;
-	}
-	tmp1 = tmp1->next;
-	if (tmp1->update) {
-	    tmp1->update = FALSE;
-	    lcdupdate = TRUE;
+	for (tmp1 = Config.w1therms; tmp1; tmp1 = tmp1->next) {
+	    if (tmp1->update) {
+	    	tmp1->update = FALSE;
+	    	lcdupdate = TRUE;
+	    }
 	}
 
 #ifdef HAVE_WIRINGPI_H
@@ -296,12 +300,14 @@
 	now = time(NULL);
 	if (((int)now - (int)last) > 60) {
 	    last = now;
-	    tmp1 = Config.w1therms;
-	    temp = tmp1->lastval;
-	    tmp1 = tmp1->next;
-	    if (temp && tmp1->lastval && run) {
-	    	snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0);
-	    	logger((char *)"thermferm.log", (char *)"thermferm", buf);
+	    if (Config.w1therms) {
+	    	tmp1 = Config.w1therms;
+	    	temp = tmp1->lastval;
+	    	tmp1 = tmp1->next;
+	    	if (temp && tmp1->lastval && run) {
+	    	    snprintf(buf, 1023, "%.2f,%.2f", temp / 1000.0, tmp1->lastval / 1000.0);
+	    	    logger((char *)"thermferm.log", (char *)"thermferm", buf);
+	    	}
 	    }
 	}
 	usleep(100000);
@@ -320,7 +326,7 @@
     stopLCD();
 #endif
 
-    wrconfig((char *)"thermferm.conf");
+    wrconfig((char *)"thermferm.conf", (char *)"thermferm.xml");
 
     ulockprog((char *)"thermferm");
 

mercurial