Fixed LCD display updates. Better key routines.

Sun, 10 Aug 2014 12:09:07 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Aug 2014 12:09:07 +0200
changeset 204
9a14d6b2de7f
parent 203
47e5109c7f53
child 205
ca18ff45deba

Fixed LCD display updates. Better key routines.

thermferm/lcd-buffer.c file | annotate | diff | comparison | revisions
thermferm/lcd-buffer.h file | annotate | diff | comparison | revisions
thermferm/panel.c file | annotate | diff | comparison | revisions
thermferm/panel.h file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
--- a/thermferm/lcd-buffer.c	Sat Aug 09 23:13:56 2014 +0200
+++ b/thermferm/lcd-buffer.c	Sun Aug 10 12:09:07 2014 +0200
@@ -30,8 +30,6 @@
 
 int			current_lines = 0;
 int			current_offset = 0;
-int			first_time = 1;
-int			previous_key = KEY_NONE;
 lcd_rows		*my_lcd_rows = NULL;
 
 extern int		lcdHandle;
@@ -90,43 +88,37 @@
 
 
 
-/*
- * This will be called from the main thread if not in edit mode.
- */
-void lcd_buf_show(void)
+void lcd_buf_step(void)
 {
-    int		i = 0, r = 0, key, doit = FALSE;
-    lcd_rows	*tmp;
+    int		key;
 
     key = keycheck();
 
-    if ((key == KEY_NONE) && (previous_key == KEY_DOWN)) {
+    if (key == KEY_DOWN) {
 	if (current_offset < (current_lines - Config.lcd_rows))
 	    current_offset = current_offset + Config.lcd_rows;
 	else
 	    current_offset = 0;
-	doit = TRUE;
+	lcd_buf_show();
     }
-    if ((key == KEY_NONE) && (previous_key == KEY_UP)) {
+    if (key == KEY_UP) {
 	if (current_offset > Config.lcd_rows)
 	    current_offset = current_offset - Config.lcd_rows;
 	else
 	    current_offset = (current_lines - Config.lcd_rows);
-	doit = TRUE;
+	lcd_buf_show();
     }
-    previous_key = key;
+}
+
 
 
-    /*
-     * Make sure the display works when the program starts.
-     */
-    if (first_time) {
-	first_time = 0;
-	doit = TRUE;
-    }
-
-    if (! doit)
-	return;
+/*
+ * This will be called from the main thread every second.
+ */
+void lcd_buf_show(void)
+{
+    int		i = 0, r = 0;
+    lcd_rows	*tmp;
 
     for (tmp = my_lcd_rows; tmp; tmp = tmp->next) {
 	if (i == current_offset)
--- a/thermferm/lcd-buffer.h	Sat Aug 09 23:13:56 2014 +0200
+++ b/thermferm/lcd-buffer.h	Sun Aug 10 12:09:07 2014 +0200
@@ -9,6 +9,7 @@
 
 
 void lcd_buf_write(int, const char *, ...);
+void lcd_buf_step(void);
 void lcd_buf_show(void);
 
 #endif
--- a/thermferm/panel.c	Sat Aug 09 23:13:56 2014 +0200
+++ b/thermferm/panel.c	Sun Aug 10 12:09:07 2014 +0200
@@ -36,9 +36,30 @@
 int			Key_Up = FALSE;
 int			Key_Down = FALSE;
 
+int			previous_key = KEY_NONE;
 
+
+
+/*
+ * Check for a key. Return last pressed key or none.
+ */
 int keycheck(void)
 {
+    int		key, retkey = KEY_NONE;
+
+    key = keypressed();
+    if ((key == KEY_NONE) && (previous_key != KEY_NONE)) {
+	retkey = previous_key;
+    }
+
+    previous_key = key;
+    return retkey;
+}
+
+
+
+int keypressed(void)
+{
     if (Key_Enter && Key_Up && Key_Down)
 	return KEY_ALL;
     if (Key_Up && Key_Down)
--- a/thermferm/panel.h	Sat Aug 09 23:13:56 2014 +0200
+++ b/thermferm/panel.h	Sun Aug 10 12:09:07 2014 +0200
@@ -41,6 +41,8 @@
 
 
 int keycheck(void);
+int keypressed(void);
+
 
 PI_THREAD (my_panel_loop);
 
--- a/thermferm/thermferm.c	Sat Aug 09 23:13:56 2014 +0200
+++ b/thermferm/thermferm.c	Sun Aug 10 12:09:07 2014 +0200
@@ -564,6 +564,9 @@
 		}
 	    }
 
+#ifdef HAVE_WIRINGPI_H
+	    lcd_buf_show();
+#endif
 	    if (seconds == 60) {
 		seconds = 0;
 
@@ -623,7 +626,7 @@
 
 #ifdef HAVE_WIRINGPI_H
 	// FIXME: not in editmode.
-	lcd_buf_show();
+	lcd_buf_step();
 #endif
 
 	usleep(100000);

mercurial