# HG changeset patch # User Michiel Broek # Date 1407665347 -7200 # Node ID 9a14d6b2de7f4b6a6ee6cd2299f2d039b71630ae # Parent 47e5109c7f534152913bc112d59c5e958d1e552e Fixed LCD display updates. Better key routines. diff -r 47e5109c7f53 -r 9a14d6b2de7f thermferm/lcd-buffer.c --- 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) diff -r 47e5109c7f53 -r 9a14d6b2de7f thermferm/lcd-buffer.h --- 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 diff -r 47e5109c7f53 -r 9a14d6b2de7f thermferm/panel.c --- 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) diff -r 47e5109c7f53 -r 9a14d6b2de7f thermferm/panel.h --- 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); diff -r 47e5109c7f53 -r 9a14d6b2de7f thermferm/thermferm.c --- 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);