thermferm/thermferm.c

changeset 486
5a237a99a793
parent 484
7362ebd40f26
child 488
bee1f70fb42b
--- a/thermferm/thermferm.c	Thu Feb 25 20:26:40 2016 +0100
+++ b/thermferm/thermferm.c	Thu Feb 25 22:42:54 2016 +0100
@@ -959,6 +959,9 @@
 #endif
     int			current_step, valid_step, time_until_now, previous_fridge_mode;
     float		previous_target_lo, previous_target_hi;
+    float		LCDair, LCDbeer, LCDspL, LCDspH;
+    unsigned char	LCDstatC, LCDstatH;
+    int			LCDunit;
 
 
     if (lockprog((char *)"thermferm")) {
@@ -1122,6 +1125,13 @@
 	    piUnlock(LOCK_LCD);
 #endif
 
+#ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_LCD);
+#endif
+	    lcd_buf_write(row, "Room temp N/A       ", Config.temp_value / 1000.0, 0x01);
+#ifdef HAVE_WIRINGPI_H
+	    piUnlock(LOCK_LCD);
+#endif
             if (Config.temp_address) {
 		rc = device_in(Config.temp_address, &temp);
 		if (rc == DEVPRESENT_YES) {
@@ -1130,7 +1140,7 @@
 #ifdef HAVE_WIRINGPI_H
 		    piLock(LOCK_LCD);
 #endif
-		    lcd_buf_write(row++, "Room temp %.1f%c    ", Config.temp_value / 1000.0, 0x01);
+		    lcd_buf_write(row, "Room temp %.1f%c    ", Config.temp_value / 1000.0, 0x01);
 #ifdef HAVE_WIRINGPI_H
 		    piUnlock(LOCK_LCD);
 #endif
@@ -1140,6 +1150,15 @@
 		    Config.temp_state = 2;
 		}
 	    }
+	    row++;
+
+#ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_LCD);
+#endif
+	    lcd_buf_write(row, " Humidity N/A       ", Config.hum_value / 1000.0);
+#ifdef HAVE_WIRINGPI_H
+	    piUnlock(LOCK_LCD);
+#endif
 
 	    if (Config.hum_address) {
 		rc = device_in(Config.hum_address, &temp);
@@ -1149,7 +1168,7 @@
 #ifdef HAVE_WIRINGPI_H
 		    piLock(LOCK_LCD);
 #endif
-		    lcd_buf_write(row++, " Humidity %.1f %%    ", Config.hum_value / 1000.0, 0xdf);
+		    lcd_buf_write(row, " Humidity %.1f%%     ", Config.hum_value / 1000.0);
 #ifdef HAVE_WIRINGPI_H
 		    piUnlock(LOCK_LCD);
 #endif
@@ -1159,17 +1178,11 @@
 		    Config.hum_state = 2;
 		}
 	    }
+	    row++;
 
+	    LCDunit = 0;
 	    for (unit = Config.units; unit; unit = unit->next) {
-#ifdef HAVE_WIRINGPI_H
-		piLock(LOCK_LCD);
-#endif
-		lcd_buf_write(row++, "Unit %s              ", unit->name);
-		lcd_buf_write(row++, "Mode %s              ", UNITMODE[unit->mode]);
-#ifdef HAVE_WIRINGPI_H
-		piUnlock(LOCK_LCD);
-#endif
-
+		LCDunit++;
 		if (unit->air_address) {
 		    rc = device_in(unit->air_address, &temp);
 		    if (rc == DEVPRESENT_YES) {
@@ -1186,13 +1199,6 @@
 			    (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
 			    unit->air_temperature = temp;
 			    unit->air_state = 0;
-#ifdef HAVE_WIRINGPI_H
-			    piLock(LOCK_LCD);
-#endif
-			    lcd_buf_write(row++, " Air %.3f %cC         ", unit->air_temperature / 1000.0, 0xdf);
-#ifdef HAVE_WIRINGPI_H
-			    piUnlock(LOCK_LCD);
-#endif
 			} else {
 			    syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
 			    if (debug) {
@@ -1214,13 +1220,6 @@
 			    (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
 			    unit->beer_temperature = temp;
 			    unit->beer_state = 0;
-#ifdef HAVE_WIRINGPI_H
-			    piLock(LOCK_LCD);
-#endif
-			    lcd_buf_write(row++, "Beer %.3f %cC         ", unit->beer_temperature / 1000.0, 0xdf);
-#ifdef HAVE_WIRINGPI_H
-			    piUnlock(LOCK_LCD);
-#endif
 			} else {
 			    syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
 			    if (debug) {
@@ -1487,51 +1486,6 @@
 		if (unit->light_address && unit->light_state)
 		    unit->light_usage++;
 
-		if (unit->heater_address && unit->cooler_address) {
-#ifdef HAVE_WIRINGPI_H
-    		    piLock(LOCK_LCD);
-#endif
-    		    if (unit->heater_state) {
-			lcd_buf_write(row++, "Heater On          ");
-		    } else if (unit->cooler_state) {
-			lcd_buf_write(row++, "Cooler On          ");
-		    } else {
-			lcd_buf_write(row++, "Standby            ");
-		    }
-#ifdef HAVE_WIRINGPI_H
-		    piUnlock(LOCK_LCD);
-		    piLock(LOCK_LCD);
-#endif
-		    switch (unit->mode) {
-			case UNITMODE_BEER:	lcd_buf_write(row++, "Target %.1f %cC     ", unit->beer_set, 0xdf);
-						break;
-			case UNITMODE_FRIDGE:	lcd_buf_write(row++, "Target %.1f %cC     ", unit->fridge_set, 0xdf);
-						break;
-			case UNITMODE_PROFILE:	if (unit->prof_state != PROFILE_OFF)
-						    lcd_buf_write(row++, "Tgt %.1f..%.1f %cC   ", unit->prof_target_lo, unit->prof_target_hi, 0xdf);
-						else
-						    lcd_buf_write(row++, "Target not set     ");
-						break;
-			default:		lcd_buf_write(row++, "Target not set     ");
-		    }
-#ifdef HAVE_WIRINGPI_H
-		    piUnlock(LOCK_LCD);
-#endif
-		} else {
-#ifdef HAVE_WIRINGPI_H
-    		    piLock(LOCK_LCD);
-#endif
-		    if (unit->heater_address) {
-		    	lcd_buf_write(row++, "Heat %s            ", unit->heater_state ? "On ":"Off");
-		    }
-		    if (unit->cooler_address) {
-		    	lcd_buf_write(row++, "Cool %s            ", unit->cooler_state ? "On ":"Off");
-		    }
-#ifdef HAVE_WIRINGPI_H
-		    piUnlock(LOCK_LCD);
-#endif
-		}
-
 		/*
 		 * Interior lights
 		 */
@@ -1709,6 +1663,46 @@
 		} else {
 		    unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
 		} /* fridge beer or profile mode */
+
+		/*
+		 * Now everything is set and done, update the LCD display
+		 */
+		LCDair = unit->air_temperature / 1000.0;
+		LCDbeer = unit->beer_temperature / 1000.0;
+		LCDstatC = LCDstatH = 'x';
+		if (unit->heater_address) {
+		    if (unit->heater_state) 
+			LCDstatH = '\5';
+		    else
+			LCDstatH = '\6';
+		}
+		if (unit->cooler_address) {
+		    if (unit->cooler_state) 
+			LCDstatC = '\3';
+		    else
+			LCDstatC = '\4';
+		}
+		LCDspH = LCDspL = 0.0;
+		if (unit->mode == UNITMODE_BEER)
+		    LCDspH = LCDspL = unit->beer_set;
+		else if (unit->mode == UNITMODE_FRIDGE)
+		    LCDspH = LCDspL = unit->fridge_set;
+		else if (unit->mode == UNITMODE_PROFILE) {
+		    if (unit->prof_state != PROFILE_OFF) {
+			LCDspL = unit->prof_target_lo;
+			LCDspH = unit->prof_target_hi;
+		    }
+		}
+#ifdef HAVE_WIRINGPI_H
+		piLock(LOCK_LCD);
+#endif
+		lcd_buf_write(row++, "Unit %d: %s          ", LCDunit, UNITMODE[unit->mode]);
+		lcd_buf_write(row++, "%s                   ", unit->name);
+		lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1    ", LCDstatC, LCDspH, LCDair);
+		lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1    ", LCDstatH, LCDspL, LCDbeer);
+#ifdef HAVE_WIRINGPI_H
+		piUnlock(LOCK_LCD);
+#endif
 	    } /* for units */
 
 #ifdef HAVE_WIRINGPI_H

mercurial