Sun, 08 Nov 2015 22:13:02 +0100
Reenabled code round LCD driver.
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 | |
108 | 29 | int current_lines = 0; |
30 | int current_offset = 0; | |
31 | lcd_rows *my_lcd_rows = NULL; | |
32 | ||
33 | extern int lcdHandle; | |
34 | extern sys_config Config; | |
35 | ||
36 | ||
37 | ||
38 | /* | |
245
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
39 | * Reset the LCD screens chain, it will automatic rebuild. |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
40 | */ |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
41 | void lcd_buf_reset(void) |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
42 | { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
43 | lcd_rows *tmp, *old; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
44 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
45 | for (tmp = my_lcd_rows; tmp; tmp = old) { |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
46 | old = tmp->next; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
47 | tmp->next = NULL; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
48 | free(tmp); |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
49 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
50 | current_lines = current_offset = 0; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
51 | my_lcd_rows = NULL; |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
52 | } |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
53 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
54 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
55 | |
b01b6238eb67
You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents:
231
diff
changeset
|
56 | /* |
108 | 57 | * Write to buffer array. Allocate more lines if needed. |
58 | */ | |
59 | void lcd_buf_write(int row, const char *format, ...) | |
60 | { | |
222 | 61 | char buf[81 * sizeof(char)]; |
108 | 62 | va_list va_ptr; |
63 | lcd_rows *tmp, *newrow; | |
64 | int i = 0; | |
65 | ||
66 | va_start(va_ptr, format); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
67 | vsnprintf(buf, (Config.lcd_cols + 1) * sizeof(char), format, va_ptr); |
108 | 68 | va_end(va_ptr); |
69 | ||
70 | /* | |
71 | * Check if the line in row is allocated. If not, do it | |
72 | * and make sure the chain is valid. | |
73 | */ | |
74 | while (row > current_lines) { | |
75 | ||
231 | 76 | syslog(LOG_NOTICE, "lcd_buf_write(%d, ...) allocate new row", row); |
108 | 77 | newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); |
78 | newrow->next = NULL; | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
205
diff
changeset
|
79 | snprintf(newrow->row, (Config.lcd_cols + 1) * sizeof(char), " "); |
108 | 80 | |
81 | if (my_lcd_rows == NULL) { | |
82 | my_lcd_rows = newrow; | |
83 | } else { | |
84 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
85 | if (tmp->next == NULL) { | |
86 | tmp->next = newrow; | |
87 | current_lines++; | |
88 | break; | |
89 | } | |
90 | } | |
91 | } | |
92 | } | |
93 | ||
94 | /* | |
95 | * Now update the text | |
96 | */ | |
97 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
98 | i++; | |
99 | if (i == row) { | |
100 | snprintf(tmp->row, Config.lcd_cols + 1, "%s", buf); | |
230
5a7024e6be88
Added logging for wrong LCD buffer allocations
Michiel Broek <mbroek@mbse.eu>
parents:
228
diff
changeset
|
101 | return; |
108 | 102 | } |
103 | } | |
230
5a7024e6be88
Added logging for wrong LCD buffer allocations
Michiel Broek <mbroek@mbse.eu>
parents:
228
diff
changeset
|
104 | syslog(LOG_NOTICE, "lcd_buf_write(%d, ...) could not find row, i=%d", row, i); |
108 | 105 | } |
106 | ||
107 | ||
108 | ||
205 | 109 | void lcd_buf_step(int key) |
108 | 110 | { |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
111 | 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
|
112 | if (current_offset < (current_lines - Config.lcd_rows)) |
228
11655e7124c5
Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents:
226
diff
changeset
|
113 | current_offset += Config.lcd_rows; |
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
|
114 | 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
|
115 | current_offset = 0; |
226
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
116 | syslog(LOG_NOTICE, "lcd_buf_step(KEY_DOWN) current_lines=%d current_offset=%d", current_lines, current_offset); |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
117 | 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
|
118 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
119 | if (key == KEY_UP) { |
228
11655e7124c5
Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents:
226
diff
changeset
|
120 | if (current_offset >= Config.lcd_rows) |
11655e7124c5
Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents:
226
diff
changeset
|
121 | current_offset -= Config.lcd_rows; |
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 | 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
|
123 | current_offset = (current_lines - Config.lcd_rows); |
226
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
124 | syslog(LOG_NOTICE, "lcd_buf_step(KEY_UP) current_lines=%d current_offset=%d", current_lines, current_offset); |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
125 | 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
|
126 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
127 | } |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
128 | |
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
|
129 | |
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
|
130 | |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
131 | /* |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
132 | * 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
|
133 | */ |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
134 | void lcd_buf_show(void) |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
135 | { |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
136 | int i = 0, r = 0; |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
137 | 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
|
138 | |
108 | 139 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
140 | if (i == current_offset) | |
141 | break; | |
142 | i++; | |
143 | } | |
144 | ||
226
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
145 | if (tmp == NULL) { |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
146 | syslog(LOG_NOTICE, "lcd_buf_show: search after last record, current_offset=%d current_lines=%d i=%d", current_offset, current_lines, i); |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
147 | return; |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
148 | } |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
149 | |
418
0bfe08c7ba6e
Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
150 | #ifdef HAVE_WIRINGPI_H |
108 | 151 | lcdPosition(lcdHandle, 0, r); |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
222
diff
changeset
|
152 | lcdPuts(lcdHandle, tmp->row); |
418
0bfe08c7ba6e
Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
153 | #endif |
108 | 154 | |
155 | r++; | |
156 | if (r < Config.lcd_rows) { | |
157 | if (tmp->next != NULL) | |
158 | tmp = tmp->next; | |
159 | else | |
160 | tmp = my_lcd_rows; | |
418
0bfe08c7ba6e
Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
161 | #ifdef HAVE_WIRINGPI_H |
108 | 162 | lcdPosition(lcdHandle, 0, r); |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
222
diff
changeset
|
163 | lcdPuts(lcdHandle, tmp->row); |
418
0bfe08c7ba6e
Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents:
245
diff
changeset
|
164 | #endif |
108 | 165 | } |
166 | } | |
106 | 167 | |
168 |