Wed, 13 Aug 2014 19:48:20 +0200
Added logging for wrong LCD buffer allocations
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 | { | |
222 | 45 | char buf[81 * sizeof(char)]; |
108 | 46 | va_list va_ptr; |
47 | lcd_rows *tmp, *newrow; | |
48 | int i = 0; | |
49 | ||
50 | va_start(va_ptr, format); | |
214
37d1eb0e1d66
Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
51 | vsnprintf(buf, (Config.lcd_cols + 1) * sizeof(char), format, va_ptr); |
108 | 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 | ||
230
5a7024e6be88
Added logging for wrong LCD buffer allocations
Michiel Broek <mbroek@mbse.eu>
parents:
228
diff
changeset
|
60 | syslog(LOG_NOTICE, "lcd_buf_write(%d, ...) allowcate new row", row); |
108 | 61 | newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); |
62 | newrow->next = NULL; | |
213
2317b8d644fa
Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents:
205
diff
changeset
|
63 | snprintf(newrow->row, (Config.lcd_cols + 1) * sizeof(char), " "); |
108 | 64 | |
65 | if (my_lcd_rows == NULL) { | |
66 | my_lcd_rows = newrow; | |
67 | } else { | |
68 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
69 | if (tmp->next == NULL) { | |
70 | tmp->next = newrow; | |
71 | current_lines++; | |
72 | break; | |
73 | } | |
74 | } | |
75 | } | |
76 | } | |
77 | ||
78 | /* | |
79 | * Now update the text | |
80 | */ | |
81 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
82 | i++; | |
83 | if (i == row) { | |
84 | 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
|
85 | return; |
108 | 86 | } |
87 | } | |
230
5a7024e6be88
Added logging for wrong LCD buffer allocations
Michiel Broek <mbroek@mbse.eu>
parents:
228
diff
changeset
|
88 | syslog(LOG_NOTICE, "lcd_buf_write(%d, ...) could not find row, i=%d", row, i); |
108 | 89 | } |
90 | ||
91 | ||
92 | ||
205 | 93 | void lcd_buf_step(int key) |
108 | 94 | { |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
95 | 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
|
96 | 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
|
97 | 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
|
98 | 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
|
99 | current_offset = 0; |
226
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
100 | 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
|
101 | 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
|
102 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
103 | if (key == KEY_UP) { |
228
11655e7124c5
Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents:
226
diff
changeset
|
104 | if (current_offset >= Config.lcd_rows) |
11655e7124c5
Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents:
226
diff
changeset
|
105 | 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
|
106 | 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
|
107 | 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
|
108 | 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
|
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 | ||
226
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
129 | if (tmp == NULL) { |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
130 | 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
|
131 | return; |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
132 | } |
d857032c6201
Added debug log info to lcd_buf functions.
Michiel Broek <mbroek@mbse.eu>
parents:
223
diff
changeset
|
133 | |
108 | 134 | lcdPosition(lcdHandle, 0, r); |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
222
diff
changeset
|
135 | lcdPuts(lcdHandle, tmp->row); |
108 | 136 | |
137 | r++; | |
138 | if (r < Config.lcd_rows) { | |
139 | if (tmp->next != NULL) | |
140 | tmp = tmp->next; | |
141 | else | |
142 | tmp = my_lcd_rows; | |
143 | lcdPosition(lcdHandle, 0, r); | |
223
14700edd2a67
Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents:
222
diff
changeset
|
144 | lcdPuts(lcdHandle, tmp->row); |
108 | 145 | } |
146 | } | |
106 | 147 | |
148 | ||
149 | ||
150 | #endif |