Selecting units in setup does now work. Menu select variables are protected with thread locking.

Sat, 16 Aug 2014 17:11:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 16 Aug 2014 17:11:09 +0200
changeset 244
2f868eaefec2
parent 243
ab75ff8e26e1
child 245
b01b6238eb67

Selecting units in setup does now work. Menu select variables are protected with thread locking.

thermferm/panel.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/thermferm/panel.c	Sat Aug 16 15:38:45 2014 +0200
+++ b/thermferm/panel.c	Sat Aug 16 17:11:09 2014 +0200
@@ -49,7 +49,6 @@
 extern int		my_shutdown;
 extern int		debug;
 extern int		setupmenu;
-extern units_list	*current_unit;
 
 int			Key_Enter = FALSE;
 int			Key_Enter_Long = FALSE;
@@ -184,16 +183,15 @@
 		    Backlight--;
 		}
 
+		piLock(LOCK_MENU);
 	    	if (setupmenu != MENU_NONE) {
 		    if (menutimer < MENU_TIMEOUT)
 			menutimer++;
 		    else {
 			setupmenu = MENU_NONE;
-			if (current_unit)
-			    free(current_unit);
-			current_unit = NULL;
 		    }
 		}
+		piUnlock(LOCK_MENU);
 	    }
 	}
 
--- a/thermferm/thermferm.c	Sat Aug 16 15:38:45 2014 +0200
+++ b/thermferm/thermferm.c	Sat Aug 16 17:11:09 2014 +0200
@@ -96,10 +96,8 @@
     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);
 }
 
 
@@ -109,9 +107,10 @@
     char	buf[21];
 
     piLock(LOCK_LCD);
+    piLock(LOCK_MENU);
     lcdClear(lcdHandle);
     lcdPosition(lcdHandle, 0, 0);
-    piUnlock(LOCK_LCD);
+    syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu);
     setupmenu = menu;
 
     switch (menu) {
@@ -127,14 +126,8 @@
 				break;
 
 	case MENU_UNITS:	lcdPuts(lcdHandle, "Choose unit:");
-				if ((current_unit == NULL) && Config.units) {
-				    /*
-				     * First time in this menu, select the first unit.
-				     */
-				    current_unit = Config.units;
-				    lcdPosition(lcdHandle, 0, 1);
-				    lcdPuts(lcdHandle, Config.units->name);
-				}
+				lcdPosition(lcdHandle, 0, 1);
+				lcdPuts(lcdHandle, current_unit->name);
 				break;
 
 	case MENU_MODE_OFF:	show_mode();
@@ -208,6 +201,9 @@
 	case MENU_SYS_THERMS:	lcdPuts(lcdHandle, "Start Thermometers");
 				break;
     }
+
+    piUnlock(LOCK_MENU);
+    piUnlock(LOCK_LCD);
 }
 
 
@@ -865,11 +861,13 @@
 	    }
 
 #ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_MENU);
 	    if (setupmenu == MENU_NONE) {
 		piLock(LOCK_LCD);
 	    	lcd_buf_show();
 		piUnlock(LOCK_LCD);
 	    }
+	    piUnlock(LOCK_MENU);
 #endif
 
 	    if (seconds == 60) {
@@ -960,34 +958,48 @@
 			    go_menu(MENU_TOP_SYS);
 			if (key == KEY_UP)
 			    go_menu(MENU_TOP_DEFAULT);
-			if (key == KEY_ENTER)
+			if ((key == KEY_ENTER) && Config.units) {
+			    /*
+			     * Start with the first unit
+			     */
+			    current_unit = Config.units;
 			    go_menu(MENU_UNITS);
+			}
 			break;
 
 	    case MENU_UNITS:
 			if (key == KEY_ESCAPE)
 			    go_menu(MENU_TOP_UNITS);
 			if (key == KEY_DOWN) {
+			    if (current_unit->next) {
+				current_unit = current_unit->next;
+				go_menu(MENU_UNITS);
+			    }
+			}
+			if (key == KEY_UP) {
 			    for (unit = Config.units; unit; unit = unit->next) {
-				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);
-				    }
+				if (unit->next && (unit->next == current_unit)) {
+				    current_unit = unit;
+				    go_menu(MENU_UNITS);
+				    break;
 				}
 			    }
 			}
 			if (key == KEY_ENTER) {
-			    for (unit = Config.units; unit; unit = unit->next) {
-				if (strcmp(unit->uuid, current_unit->uuid) == 0) {
-				    if (unit->mode == UNITMODE_OFF)
-					go_menu(MENU_MODE_NONE);
-				    else
-			    		go_menu(MENU_MODE_OFF);
-				}
+			    /*
+			     * Drop into the current mode
+			     */
+			    switch (current_unit->mode) {
+				case UNITMODE_OFF:	go_menu(MENU_MODE_OFF);
+							break;
+				case UNITMODE_NONE:	go_menu(MENU_MODE_NONE);
+							break;
+				case UNITMODE_FRIDGE:	go_menu(MENU_MODE_FRIDGE);
+							break;
+				case UNITMODE_BEER:	go_menu(MENU_MODE_BEER);
+							break;
+				case UNITMODE_PROFILE:	go_menu(MENU_MODE_PROFILE);
+							break;
 			    }
 			}
 			break;
--- a/thermferm/thermferm.h	Sat Aug 16 15:38:45 2014 +0200
+++ b/thermferm/thermferm.h	Sat Aug 16 17:11:09 2014 +0200
@@ -50,7 +50,7 @@
  */
 #define	LOCK_DEVICES		0
 #define	LOCK_LCD		1
-#define	LOCK_SPARE1		2
+#define	LOCK_MENU		2
 #define	LOCK_SPARE2		3
 
 

mercurial