Sun, 10 Aug 2014 12:09:07 +0200
Fixed LCD display updates. Better key routines.
106 | 1 | /***************************************************************************** |
108 | 2 | * Copyright (C) 2014 |
106 | 3 | * |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with mbsePi-apps; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "thermferm.h" | |
24 | #include "lcd-buffer.h" | |
108 | 25 | #include "lcd-pcf8574.h" |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
26 | #include "panel.h" |
108 | 27 | |
106 | 28 | |
29 | #ifdef HAVE_WIRINGPI_H | |
30 | ||
108 | 31 | int current_lines = 0; |
32 | int current_offset = 0; | |
33 | lcd_rows *my_lcd_rows = NULL; | |
34 | ||
35 | extern int lcdHandle; | |
36 | extern sys_config Config; | |
37 | ||
38 | ||
39 | ||
40 | /* | |
41 | * Write to buffer array. Allocate more lines if needed. | |
42 | */ | |
43 | void lcd_buf_write(int row, const char *format, ...) | |
44 | { | |
45 | char buf[21 * sizeof(char)]; | |
46 | va_list va_ptr; | |
47 | lcd_rows *tmp, *newrow; | |
48 | int i = 0; | |
49 | ||
50 | va_start(va_ptr, format); | |
51 | vsnprintf(buf, 20 * sizeof(char), format, va_ptr); | |
52 | va_end(va_ptr); | |
53 | ||
54 | /* | |
55 | * Check if the line in row is allocated. If not, do it | |
56 | * and make sure the chain is valid. | |
57 | */ | |
58 | while (row > current_lines) { | |
59 | ||
60 | newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); | |
61 | newrow->next = NULL; | |
62 | snprintf(newrow->row, 21 * sizeof(char), " "); | |
63 | ||
64 | if (my_lcd_rows == NULL) { | |
65 | my_lcd_rows = newrow; | |
66 | } else { | |
67 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
68 | if (tmp->next == NULL) { | |
69 | tmp->next = newrow; | |
70 | current_lines++; | |
71 | break; | |
72 | } | |
73 | } | |
74 | } | |
75 | } | |
76 | ||
77 | /* | |
78 | * Now update the text | |
79 | */ | |
80 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
81 | i++; | |
82 | if (i == row) { | |
83 | snprintf(tmp->row, Config.lcd_cols + 1, "%s", buf); | |
84 | break; | |
85 | } | |
86 | } | |
87 | } | |
88 | ||
89 | ||
90 | ||
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
91 | void lcd_buf_step(void) |
108 | 92 | { |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
93 | int key; |
108 | 94 | |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
95 | key = keycheck(); |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
96 | |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
97 | if (key == KEY_DOWN) { |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
98 | if (current_offset < (current_lines - Config.lcd_rows)) |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
99 | current_offset = current_offset + Config.lcd_rows; |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
100 | else |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
101 | current_offset = 0; |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
102 | lcd_buf_show(); |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
103 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
104 | if (key == KEY_UP) { |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
105 | if (current_offset > Config.lcd_rows) |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
106 | current_offset = current_offset - Config.lcd_rows; |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
107 | else |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
108 | current_offset = (current_lines - Config.lcd_rows); |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
109 | lcd_buf_show(); |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
110 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
111 | } |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
112 | |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
113 | |
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
114 | |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
115 | /* |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
116 | * This will be called from the main thread every second. |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
117 | */ |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
118 | void lcd_buf_show(void) |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
119 | { |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
120 | int i = 0, r = 0; |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
121 | lcd_rows *tmp; |
200
a215ddaabbe2
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents:
108
diff
changeset
|
122 | |
108 | 123 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
124 | if (i == current_offset) | |
125 | break; | |
126 | i++; | |
127 | } | |
128 | ||
129 | lcdPosition(lcdHandle, 0, r); | |
130 | mb_lcdPuts(lcdHandle, tmp->row); | |
131 | ||
132 | r++; | |
133 | if (r < Config.lcd_rows) { | |
134 | if (tmp->next != NULL) | |
135 | tmp = tmp->next; | |
136 | else | |
137 | tmp = my_lcd_rows; | |
138 | lcdPosition(lcdHandle, 0, r); | |
139 | mb_lcdPuts(lcdHandle, tmp->row); | |
140 | } | |
141 | } | |
106 | 142 | |
143 | ||
144 | ||
145 | #endif |