thermometers/main.c

changeset 18
3f4823083b9d
parent 16
f4cbe008da72
child 19
eaa03048c269
--- a/thermometers/main.c	Fri May 02 23:14:50 2014 +0200
+++ b/thermometers/main.c	Fri May 02 23:24:44 2014 +0200
@@ -42,7 +42,9 @@
 
 extern bool		debug;
 extern sys_config	Config;
+#ifdef HAVE_WIRINGPI_H
 extern int		lcdHandle;
+#endif
 
 int server(void);
 void help(void);
@@ -123,11 +125,13 @@
 
 
 
+#ifdef HAVE_WIRINGPI_H
 void stopLCD(void)
 {
    lcdClear(lcdHandle);
    setBacklight(0);
 }
+#endif
 
 
 
@@ -135,7 +139,9 @@
 {
     int		rc, c, i;
     pid_t	frk;
+#ifdef HAVE_WIRINGPI_H
     char	buf[80];
+#endif
 
     while (1) {
 	int option_index = 0;
@@ -178,6 +184,7 @@
 	    signal(i, (void (*))die);
     }
 
+#ifdef HAVE_WIRINGPI_H
     if ((rc = initLCD (16, 2))) {
 	fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
 	return 1;
@@ -188,6 +195,7 @@
     lcdPosition(lcdHandle, 0, 1);
     sprintf(buf, "Version %s", VERSION);
     lcdPuts(lcdHandle, buf);
+#endif
 
     if (debug) {
 	/*
@@ -213,7 +221,9 @@
 	    case -1:	
 		    	syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno));
 			syslog(LOG_NOTICE, "Finished, rc=1");
+#ifdef HAVE_WIRINGPI_H
 			stopLCD();
+#endif
 			exit(1);
 	    case 0:	/*
 			 * Run the daemon
@@ -258,7 +268,10 @@
     char                *id = NULL, *state = NULL;
     struct mosquitto    *mosq = NULL;
     char                hostname[256], buf[1024];
-    int                 temp, rc, deviation, keepalive = 60, lcdupdate;
+    int                 temp, rc, deviation, keepalive = 60;
+#ifdef HAVE_WIRINGPI_H
+    int			lcdupdate;
+#endif
     unsigned int        max_inflight = 20;
     char                err[1024];
     w1_therm		*tmp1, *old1;
@@ -378,7 +391,9 @@
 
     do {
 	if (status == STATUS_CONNACK_RECVD) {
+#ifdef HAVE_WIRINGPI_H
 	    lcdupdate = FALSE;
+#endif
 
 	    /*
 	     * Here send our 1-wire sensors values
@@ -451,7 +466,9 @@
 				}
 			    }
 			    tmp1->lastval = temp;
+#ifdef HAVE_WIRINGPI_H
 			    lcdupdate = TRUE;
+#endif
 			}
 		    } else {
 			syslog(LOG_NOTICE, "sensor %s/%s CRC error", tmp1->master, tmp1->name);
@@ -470,6 +487,7 @@
 		alias = NULL;
 	    }
 
+#ifdef HAVE_WIRINGPI_H
 	    if (lcdupdate) {
 		lcdPosition(lcdHandle, 0, 0);
 		tmp1 = Config.w1therms;
@@ -481,6 +499,7 @@
 		snprintf(buf, 16, "%5.1f %cC %s            ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
 		lcdPuts(lcdHandle, buf);
 	    }
+#endif
 
 	    if (shutdown) {
 		/*
@@ -490,9 +509,11 @@
 		mosquitto_publish(mosq, &mid_sent, state, strlen(buf), buf, qos, true);
 		last_mid = mid_sent;
 		status = STATUS_WAITING;
+#ifdef HAVE_WIRINGPI_H
 		lcdClear(lcdHandle);
 		lcdPosition(lcdHandle, 0, 0);
 		lcdPuts(lcdHandle, "Shuting down ...");
+#endif
 	    }
 
 	    usleep(100000);
@@ -517,7 +538,9 @@
     mosquitto_destroy(mosq);
     mosquitto_lib_cleanup();
 
+#ifdef HAVE_WIRINGPI_H
     stopLCD();
+#endif
 
     return rc;
 }

mercurial