thermferm/panel.c

changeset 422
13502d0dda65
parent 244
2f868eaefec2
child 426
e54611453d29
--- a/thermferm/panel.c	Sat Nov 14 17:00:37 2015 +0100
+++ b/thermferm/panel.c	Sat Nov 14 23:40:51 2015 +0100
@@ -22,11 +22,10 @@
 
 #include "thermferm.h"
 #include "lcd-pcf8574.h"
+#include "slcd.h"
 #include "panel.h"
 
 
-#ifdef HAVE_WIRINGPI_H
-
 
 /*
  * 10 Milliseconds counts for a key to be short or long pressed.
@@ -49,6 +48,7 @@
 extern int		my_shutdown;
 extern int		debug;
 extern int		setupmenu;
+extern uint16_t		keys;
 
 int			Key_Enter = FALSE;
 int			Key_Enter_Long = FALSE;
@@ -98,16 +98,21 @@
 }
 
 
-
+#ifdef HAVE_WIRINGPI_H
 PI_THREAD (my_panel_loop)
+#else
+void *my_panel_loop(void *threadid)
+#endif
 {
     int		Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE;
     time_t	Last = (time_t)0, Now;
 
+#ifdef HAVE_WIRINGPI_H
     pinMode(PANEL_LED, OUTPUT);
     pinMode(PANEL_ENTER, INPUT);
     pinMode(PANEL_UP, INPUT);
     pinMode(PANEL_DOWN, INPUT);
+#endif
 
     syslog(LOG_NOTICE, "Thread my_panel_loop started");
 
@@ -118,7 +123,11 @@
 	if (my_shutdown)
 	    break;
 
-	if (digitalRead(PANEL_ENTER)) {
+#ifdef HAVE_WIRINGPI_H
+	if (digitalRead(PANEL_ENTER) && ((keys & 0x0001) == 0)) {
+#else
+	if ((keys & 0x0001) == 0) {
+#endif
 	    Enter = 0;
 	    Key_Enter = FALSE;
 	    Key_Enter_Long = FALSE;
@@ -128,13 +137,19 @@
 		Key_Enter = TRUE;
 	    if (Enter > PRESS_LONG)
 		Key_Enter_Long = TRUE;
+#ifdef HAVE_WIRINGPI_H
 	    if (Enter == PRESS_LONG)
 		digitalWrite(PANEL_LED, 1);
 	    if (Enter == (PRESS_LONG + 10))
 		digitalWrite(PANEL_LED, 0);
+#endif
 	}
 
-	if (digitalRead(PANEL_UP)) {
+#ifdef HAVE_WIRINGPI_H
+	if (digitalRead(PANEL_UP) && ((keys & 0x0008) == 0)) {
+#else
+	if ((keys & 0x0008) == 0) {
+#endif
 	    Up = 0;
 	    Key_Up = FALSE;
 	} else {
@@ -143,7 +158,11 @@
 		Key_Up = TRUE;
 	}
 
-	if (digitalRead(PANEL_DOWN)) {
+#ifdef HAVE_WIRINGPI_H
+	if (digitalRead(PANEL_DOWN) && ((keys & 0x0004) == 0)) {
+#else
+	if ((keys & 0x0004) == 0) {
+#endif
 	    Down = 0;
 	    Key_Down = FALSE;
 	} else {
@@ -157,9 +176,11 @@
 	    /*
 	     * Any key is pressed.
 	     */
+#ifdef HAVE_WIRINGPI_H
 	    piLock(LOCK_LCD);
 	    setBacklight(1);
 	    piUnlock(LOCK_LCD);
+#endif
 	    Backlight = LCD_SLEEP;
 	    menutimer = 0;
 	} else {
@@ -175,15 +196,19 @@
 
 	    if (AnyKey == FALSE) {
 		if (Backlight == 1) {
+#ifdef HAVE_WIRINGPI_H
 		    piLock(LOCK_LCD);
 		    setBacklight(0);
 		    piUnlock(LOCK_LCD);
+#endif
 		}
 		if (Backlight > 0) {
 		    Backlight--;
 		}
 
+#ifdef HAVE_WIRINGPI_H
 		piLock(LOCK_MENU);
+#endif
 	    	if (setupmenu != MENU_NONE) {
 		    if (menutimer < MENU_TIMEOUT)
 			menutimer++;
@@ -191,7 +216,9 @@
 			setupmenu = MENU_NONE;
 		    }
 		}
+#ifdef HAVE_WIRINGPI_H
 		piUnlock(LOCK_MENU);
+#endif
 	    }
 	}
 
@@ -206,4 +233,3 @@
 }
 
 
-#endif

mercurial