Sun, 10 Aug 2014 13:26:35 +0200
Start initial menu setup
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 | ||
205 | 91 | void lcd_buf_step(int key) |
108 | 92 | { |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
93 | 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
|
94 | 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
|
95 | 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
|
96 | 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
|
97 | current_offset = 0; |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
98 | 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
|
99 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
100 | 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
|
101 | 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
|
102 | 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
|
103 | 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
|
104 | 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
|
105 | 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
|
106 | } |
204
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
107 | } |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
108 | |
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
|
109 | |
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 | * 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
|
113 | */ |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
114 | void lcd_buf_show(void) |
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 | int i = 0, r = 0; |
9a14d6b2de7f
Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents:
200
diff
changeset
|
117 | 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
|
118 | |
108 | 119 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
120 | if (i == current_offset) | |
121 | break; | |
122 | i++; | |
123 | } | |
124 | ||
125 | lcdPosition(lcdHandle, 0, r); | |
126 | mb_lcdPuts(lcdHandle, tmp->row); | |
127 | ||
128 | r++; | |
129 | if (r < Config.lcd_rows) { | |
130 | if (tmp->next != NULL) | |
131 | tmp = tmp->next; | |
132 | else | |
133 | tmp = my_lcd_rows; | |
134 | lcdPosition(lcdHandle, 0, r); | |
135 | mb_lcdPuts(lcdHandle, tmp->row); | |
136 | } | |
137 | } | |
106 | 138 | |
139 | ||
140 | ||
141 | #endif |