thermferm/thermferm.c

changeset 241
4ba138737bf4
parent 240
6bdda35b4a13
child 244
2f868eaefec2
--- a/thermferm/thermferm.c	Thu Aug 14 22:43:41 2014 +0200
+++ b/thermferm/thermferm.c	Fri Aug 15 14:38:32 2014 +0200
@@ -90,24 +90,28 @@
 
 
 
+#ifdef HAVE_WIRINGPI_H
 void show_mode(void)
 {
     char	buf[21];
 
     snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
+    piLock(LOCK_LCD);
     lcdPuts(lcdHandle, buf);
     lcdPosition(lcdHandle, 0, 1);
+    piUnlock(LOCK_LCD);
 }
 
 
 
-#ifdef HAVE_WIRINGPI_H
 void go_menu(int menu)
 {
     char	buf[21];
 
+    piLock(LOCK_LCD);
     lcdClear(lcdHandle);
     lcdPosition(lcdHandle, 0, 0);
+    piUnlock(LOCK_LCD);
     setupmenu = menu;
 
     switch (menu) {
@@ -210,8 +214,10 @@
 
 void stopLCD(void)
 {
+    piLock(LOCK_LCD);
     lcdClear(lcdHandle);
     setBacklight(0);
+    piUnlock(LOCK_LCD);
 }
 
 
@@ -482,8 +488,10 @@
 
 
 #ifdef HAVE_WIRINGPI_H
+    piLock(LOCK_LCD);
     lcd_buf_write(1, (char *)"   ThermFerm    ");
     lcd_buf_write(2, (char *)" Version %s     ", VERSION);
+    piUnlock(LOCK_LCD);
 #endif
 
     for (unit = Config.units; unit; unit = unit->next) {
@@ -507,8 +515,10 @@
 #ifdef HAVE_WIRINGPI_H
 	    row = 3;
 	    tm = localtime(&now);
+	    piLock(LOCK_LCD);
 	    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);
+	    piUnlock(LOCK_LCD);
 #endif
 
             if (Config.temp_address) {
@@ -517,7 +527,9 @@
 		    Config.temp_value = temp;
 		    Config.temp_state = 0;
 #ifdef HAVE_WIRINGPI_H
+		    piLock(LOCK_LCD);
 		    lcd_buf_write(row++, "Room temp %.1f %cC    ", Config.temp_value / 1000.0, 0xdf);
+		    piUnlock(LOCK_LCD);
 #endif
 		} else if (rc == DEVPRESENT_ERROR) {
 		    Config.temp_state = 1;
@@ -532,7 +544,9 @@
 		    Config.hum_value = temp;
 		    Config.hum_state = 0;
 #ifdef HAVE_WIRINGPI_H
+		    piLock(LOCK_LCD);
 		    lcd_buf_write(row++, " Humidity %.1f %%    ", Config.hum_value / 1000.0, 0xdf);
+		    piUnlock(LOCK_LCD);
 #endif
 		} else if (rc == DEVPRESENT_ERROR) {
 		    Config.hum_state = 1;
@@ -543,8 +557,10 @@
 
 	    for (unit = Config.units; unit; unit = unit->next) {
 #ifdef HAVE_WIRINGPI_H
+		piLock(LOCK_LCD);
 		lcd_buf_write(row++, "Unit %s              ", unit->name);
 		lcd_buf_write(row++, "Mode %s              ", UNITMODE[unit->mode]);
+		piUnlock(LOCK_LCD);
 #endif
 
 		if (unit->air_address) {
@@ -564,7 +580,9 @@
 			    unit->air_temperature = temp;
 			    unit->air_state = 0;
 #ifdef HAVE_WIRINGPI_H
+			    piLock(LOCK_LCD);
 			    lcd_buf_write(row++, " Air %.3f %cC         ", unit->air_temperature / 1000.0, 0xdf);
+			    piUnlock(LOCK_LCD);
 #endif
 			} else {
 			    syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
@@ -588,7 +606,9 @@
 			    unit->beer_temperature = temp;
 			    unit->beer_state = 0;
 #ifdef HAVE_WIRINGPI_H
+			    piLock(LOCK_LCD);
 			    lcd_buf_write(row++, "Beer %.3f %cC         ", unit->beer_temperature / 1000.0, 0xdf);
+			    piUnlock(LOCK_LCD);
 #endif
 			} else {
 			    syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
@@ -712,12 +732,16 @@
 		}
 #ifdef HAVE_WIRINGPI_H
 		if (unit->heater_address && unit->cooler_address) {
-		    if (unit->heater_state)
+		    piLock(LOCK_LCD);
+		    if (unit->heater_state) {
 			lcd_buf_write(row++, "Heater On          ");
-		    else if (unit->cooler_state)
+		    } else if (unit->cooler_state) {
 			lcd_buf_write(row++, "Cooler On          ");
-		    else
+		    } else {
 			lcd_buf_write(row++, "Standby            ");
+		    }
+		    piUnlock(LOCK_LCD);
+		    piLock(LOCK_LCD);
 		    switch (unit->mode) {
 			case UNITMODE_BEER:	lcd_buf_write(row++, "Target %.1f %cC     ", unit->beer_set, 0xdf);
 						break;
@@ -730,13 +754,16 @@
 						break;
 			default:		lcd_buf_write(row++, "Target not set     ");
 		    }
+		    piUnlock(LOCK_LCD);
 		} else {
+		    piLock(LOCK_LCD);
 		    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");
 		    }
+		    piUnlock(LOCK_LCD);
 		}
 #endif
 	    }
@@ -838,8 +865,11 @@
 	    }
 
 #ifdef HAVE_WIRINGPI_H
-	    if (setupmenu == MENU_NONE)
+	    if (setupmenu == MENU_NONE) {
+		piLock(LOCK_LCD);
 	    	lcd_buf_show();
+		piUnlock(LOCK_LCD);
+	    }
 #endif
 
 	    if (seconds == 60) {
@@ -942,8 +972,10 @@
 				if (strcmp(unit->uuid, current_unit->uuid) == 0) {	/* Current unit		*/
 				    if (unit->next) {				/* Is there a next	*/
 					unit = unit->next;			/* Select that		*/
+					piLock(LOCK_LCD);
 					lcdPosition(lcdHandle, 0, 1);
 					lcdPuts(lcdHandle, Config.units->name);
+					piUnlock(LOCK_LCD);
 				    }
 				}
 			    }

mercurial