thermferm/thermferm.c

changeset 108
50d2187fdb74
parent 106
1bd9a16f5061
child 111
bdf3c5278a24
--- a/thermferm/thermferm.c	Sun Jul 13 17:34:41 2014 +0200
+++ b/thermferm/thermferm.c	Sun Jul 13 21:00:01 2014 +0200
@@ -108,9 +108,6 @@
 {
     int		rc, c, i;
     pid_t	frk;
-#ifdef HAVE_WIRINGPI_H
-    char	buf[80];
-#endif
 
     while (1) {
 	int option_index = 0;
@@ -157,17 +154,10 @@
     if (wiringPiSetup () )
 	return 1;
 
-    if ((rc = initLCD (16, 2))) {
+    if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
 	fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
 	return 1;
     }
-
-    lcdPosition(lcdHandle, 0, 0);
-    sprintf(buf, "    Thermferm");
-    mb_lcdPuts(lcdHandle, buf);
-    lcdPosition(lcdHandle, 0, 1);
-    sprintf(buf, "  Version %s", VERSION);
-    mb_lcdPuts(lcdHandle, buf);
 #endif
 
     if (debug) {
@@ -244,8 +234,8 @@
     units_list		*unit;
     int			rc, run = 1, temp, seconds = 0;
 #ifdef HAVE_WIRINGPI_H
-    int			lcdshow = 0;
     struct tm		*tm;
+    int			row;
 #else
     long		t = 0;
 #endif
@@ -297,6 +287,9 @@
 #endif
     }
 
+    lcd_buf_write(1, (char *)"    ThermFerm   ");
+    lcd_buf_write(2, (char *)" Version %s     ", VERSION);
+
     snprintf(buf, 1023, "tempA,tempB");
     logger((char *)"thermferm.log", buf);
 
@@ -333,38 +326,25 @@
 	    seconds++;
 
 #ifdef HAVE_WIRINGPI_H
-	    if ((seconds % 5) == 0) {
+	    row = 3;
+	    tm = localtime(&now);
+	    lcd_buf_write(row++, "   %02d-%02d-%04d   ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
+	    lcd_buf_write(row++, "    %02d:%02d:%02d    ", tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-		if (lcdshow == 0) {
-			lcdPosition(lcdHandle, 0, 0);
-			snprintf(buf, 17, "    ThermFerm   ");
-			mb_lcdPuts(lcdHandle, buf);
-			lcdPosition(lcdHandle, 0, 1);
-			snprintf(buf, 17, "  Version %s    ", VERSION);
-			mb_lcdPuts(lcdHandle, buf);
-			lcdshow++;
-		} else if (lcdshow == 1) {
-			tm = localtime(&now);
-			lcdPosition(lcdHandle, 0, 0);
-			snprintf(buf, 17, "   %02d-%02d-%04d   ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
-			mb_lcdPuts(lcdHandle, buf);
-			lcdPosition(lcdHandle, 0, 1);
-			snprintf(buf, 17, "    %02d:%02d:%02d    ", tm->tm_hour, tm->tm_min, tm->tm_sec);
-			mb_lcdPuts(lcdHandle, buf);
-			lcdshow++;
-		} else {
-			lcdPosition(lcdHandle, 0, 0);
-			tmp1 = Config.w1therms;
-			snprintf(buf, 17, "%5.2f %cC %s              ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
-			mb_lcdPuts(lcdHandle, buf);
-			temp = tmp1->lastval;
-			tmp1 = tmp1->next;
-			lcdPosition(lcdHandle, 0, 1);
-			snprintf(buf, 17, "%5.2f %cC %s              ", tmp1->lastval / 1000.0, 0xdf, tmp1->alias);
-			mb_lcdPuts(lcdHandle, buf);
-			lcdshow = 0;
+	    for (unit = Config.units; unit; unit = unit->next) {
+		if (unit->mode != UNITMODE_OFF) {
+		    lcd_buf_write(row++, "Unit %s              ", unit->name);
+		    lcd_buf_write(row++, "Mode %s              ", UNITMODE[unit->mode]);
+		    if (unit->air_address) {
+		    	lcd_buf_write(row++, " Air %.3f %cC         ", unit->air_temperature / 1000.0, 0xdf);
+		    }
+		    if (unit->beer_address) {
+			lcd_buf_write(row++, "Beer %.3f %cC         ", unit->beer_temperature / 1000.0, 0xdf);
+		    }
 		}
 	    }
+
+	    lcd_buf_show();
 #endif
 
 	    if (seconds == 60) {

mercurial