Sat, 09 Aug 2014 21:42:28 +0200
Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
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; | |
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
|
33 | int first_time = 1; |
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
|
34 | int previous_key = KEY_NONE; |
108 | 35 | lcd_rows *my_lcd_rows = NULL; |
36 | ||
37 | extern int lcdHandle; | |
38 | extern sys_config Config; | |
39 | ||
40 | ||
41 | ||
42 | /* | |
43 | * Write to buffer array. Allocate more lines if needed. | |
44 | */ | |
45 | void lcd_buf_write(int row, const char *format, ...) | |
46 | { | |
47 | char buf[21 * sizeof(char)]; | |
48 | va_list va_ptr; | |
49 | lcd_rows *tmp, *newrow; | |
50 | int i = 0; | |
51 | ||
52 | va_start(va_ptr, format); | |
53 | vsnprintf(buf, 20 * sizeof(char), format, va_ptr); | |
54 | va_end(va_ptr); | |
55 | ||
56 | /* | |
57 | * Check if the line in row is allocated. If not, do it | |
58 | * and make sure the chain is valid. | |
59 | */ | |
60 | while (row > current_lines) { | |
61 | ||
62 | newrow = (lcd_rows *)malloc(sizeof(lcd_rows)); | |
63 | newrow->next = NULL; | |
64 | snprintf(newrow->row, 21 * sizeof(char), " "); | |
65 | ||
66 | if (my_lcd_rows == NULL) { | |
67 | my_lcd_rows = newrow; | |
68 | } else { | |
69 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
70 | if (tmp->next == NULL) { | |
71 | tmp->next = newrow; | |
72 | current_lines++; | |
73 | break; | |
74 | } | |
75 | } | |
76 | } | |
77 | } | |
78 | ||
79 | /* | |
80 | * Now update the text | |
81 | */ | |
82 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { | |
83 | i++; | |
84 | if (i == row) { | |
85 | snprintf(tmp->row, Config.lcd_cols + 1, "%s", buf); | |
86 | break; | |
87 | } | |
88 | } | |
89 | } | |
90 | ||
91 | ||
92 | ||
93 | /* | |
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 | * This will be called from the main thread if not in edit mode. |
108 | 95 | */ |
96 | void lcd_buf_show(void) | |
97 | { | |
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 | int i = 0, r = 0, key, doit = FALSE; |
108 | 99 | lcd_rows *tmp; |
100 | ||
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 | 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
|
102 | |
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 | if ((key == KEY_NONE) && (previous_key == KEY_DOWN)) { |
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 | 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
|
105 | 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
|
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 = 0; |
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 | doit = TRUE; |
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 | if ((key == KEY_NONE) && (previous_key == KEY_UP)) { |
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
|
111 | 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
|
112 | 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
|
113 | 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
|
114 | 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
|
115 | doit = TRUE; |
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
|
116 | } |
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
|
117 | previous_key = key; |
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 | |
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
|
119 | |
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
|
120 | /* |
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
|
121 | * Make sure the display works when the program starts. |
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 | */ |
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 | if (first_time) { |
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
|
124 | first_time = 0; |
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
|
125 | doit = TRUE; |
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 | } |
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
|
127 | |
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
|
128 | if (! doit) |
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 | return; |
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 | |
108 | 131 | for (tmp = my_lcd_rows; tmp; tmp = tmp->next) { |
132 | if (i == current_offset) | |
133 | break; | |
134 | i++; | |
135 | } | |
136 | ||
137 | lcdPosition(lcdHandle, 0, r); | |
138 | mb_lcdPuts(lcdHandle, tmp->row); | |
139 | ||
140 | r++; | |
141 | if (r < Config.lcd_rows) { | |
142 | if (tmp->next != NULL) | |
143 | tmp = tmp->next; | |
144 | else | |
145 | tmp = my_lcd_rows; | |
146 | lcdPosition(lcdHandle, 0, r); | |
147 | mb_lcdPuts(lcdHandle, tmp->row); | |
148 | } | |
149 | } | |
106 | 150 | |
151 | ||
152 | ||
153 | #endif |