20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
21 *****************************************************************************/ |
21 *****************************************************************************/ |
22 |
22 |
23 #include "thermferm.h" |
23 #include "thermferm.h" |
24 #include "lcd-pcf8574.h" |
24 #include "lcd-pcf8574.h" |
|
25 #include "slcd.h" |
25 #include "panel.h" |
26 #include "panel.h" |
26 |
27 |
27 |
|
28 #ifdef HAVE_WIRINGPI_H |
|
29 |
28 |
30 |
29 |
31 /* |
30 /* |
32 * 10 Milliseconds counts for a key to be short or long pressed. |
31 * 10 Milliseconds counts for a key to be short or long pressed. |
33 */ |
32 */ |
96 return KEY_ENTER; |
96 return KEY_ENTER; |
97 return KEY_NONE; |
97 return KEY_NONE; |
98 } |
98 } |
99 |
99 |
100 |
100 |
101 |
101 #ifdef HAVE_WIRINGPI_H |
102 PI_THREAD (my_panel_loop) |
102 PI_THREAD (my_panel_loop) |
|
103 #else |
|
104 void *my_panel_loop(void *threadid) |
|
105 #endif |
103 { |
106 { |
104 int Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE; |
107 int Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE; |
105 time_t Last = (time_t)0, Now; |
108 time_t Last = (time_t)0, Now; |
106 |
109 |
|
110 #ifdef HAVE_WIRINGPI_H |
107 pinMode(PANEL_LED, OUTPUT); |
111 pinMode(PANEL_LED, OUTPUT); |
108 pinMode(PANEL_ENTER, INPUT); |
112 pinMode(PANEL_ENTER, INPUT); |
109 pinMode(PANEL_UP, INPUT); |
113 pinMode(PANEL_UP, INPUT); |
110 pinMode(PANEL_DOWN, INPUT); |
114 pinMode(PANEL_DOWN, INPUT); |
|
115 #endif |
111 |
116 |
112 syslog(LOG_NOTICE, "Thread my_panel_loop started"); |
117 syslog(LOG_NOTICE, "Thread my_panel_loop started"); |
113 |
118 |
114 /* |
119 /* |
115 * Loop forever until the external shutdown variable is set. |
120 * Loop forever until the external shutdown variable is set. |
116 */ |
121 */ |
117 for (;;) { |
122 for (;;) { |
118 if (my_shutdown) |
123 if (my_shutdown) |
119 break; |
124 break; |
120 |
125 |
121 if (digitalRead(PANEL_ENTER)) { |
126 #ifdef HAVE_WIRINGPI_H |
|
127 if (digitalRead(PANEL_ENTER) && ((keys & 0x0001) == 0)) { |
|
128 #else |
|
129 if ((keys & 0x0001) == 0) { |
|
130 #endif |
122 Enter = 0; |
131 Enter = 0; |
123 Key_Enter = FALSE; |
132 Key_Enter = FALSE; |
124 Key_Enter_Long = FALSE; |
133 Key_Enter_Long = FALSE; |
125 } else { |
134 } else { |
126 Enter++; |
135 Enter++; |
127 if (Enter > PRESS_NORMAL) |
136 if (Enter > PRESS_NORMAL) |
128 Key_Enter = TRUE; |
137 Key_Enter = TRUE; |
129 if (Enter > PRESS_LONG) |
138 if (Enter > PRESS_LONG) |
130 Key_Enter_Long = TRUE; |
139 Key_Enter_Long = TRUE; |
|
140 #ifdef HAVE_WIRINGPI_H |
131 if (Enter == PRESS_LONG) |
141 if (Enter == PRESS_LONG) |
132 digitalWrite(PANEL_LED, 1); |
142 digitalWrite(PANEL_LED, 1); |
133 if (Enter == (PRESS_LONG + 10)) |
143 if (Enter == (PRESS_LONG + 10)) |
134 digitalWrite(PANEL_LED, 0); |
144 digitalWrite(PANEL_LED, 0); |
135 } |
145 #endif |
136 |
146 } |
137 if (digitalRead(PANEL_UP)) { |
147 |
|
148 #ifdef HAVE_WIRINGPI_H |
|
149 if (digitalRead(PANEL_UP) && ((keys & 0x0008) == 0)) { |
|
150 #else |
|
151 if ((keys & 0x0008) == 0) { |
|
152 #endif |
138 Up = 0; |
153 Up = 0; |
139 Key_Up = FALSE; |
154 Key_Up = FALSE; |
140 } else { |
155 } else { |
141 Up++; |
156 Up++; |
142 if (Up > PRESS_NORMAL) |
157 if (Up > PRESS_NORMAL) |
143 Key_Up = TRUE; |
158 Key_Up = TRUE; |
144 } |
159 } |
145 |
160 |
146 if (digitalRead(PANEL_DOWN)) { |
161 #ifdef HAVE_WIRINGPI_H |
|
162 if (digitalRead(PANEL_DOWN) && ((keys & 0x0004) == 0)) { |
|
163 #else |
|
164 if ((keys & 0x0004) == 0) { |
|
165 #endif |
147 Down = 0; |
166 Down = 0; |
148 Key_Down = FALSE; |
167 Key_Down = FALSE; |
149 } else { |
168 } else { |
150 Down++; |
169 Down++; |
151 if (Down > PRESS_NORMAL) |
170 if (Down > PRESS_NORMAL) |
173 if (Now != Last) { |
194 if (Now != Last) { |
174 Last = Now; |
195 Last = Now; |
175 |
196 |
176 if (AnyKey == FALSE) { |
197 if (AnyKey == FALSE) { |
177 if (Backlight == 1) { |
198 if (Backlight == 1) { |
|
199 #ifdef HAVE_WIRINGPI_H |
178 piLock(LOCK_LCD); |
200 piLock(LOCK_LCD); |
179 setBacklight(0); |
201 setBacklight(0); |
180 piUnlock(LOCK_LCD); |
202 piUnlock(LOCK_LCD); |
|
203 #endif |
181 } |
204 } |
182 if (Backlight > 0) { |
205 if (Backlight > 0) { |
183 Backlight--; |
206 Backlight--; |
184 } |
207 } |
185 |
208 |
|
209 #ifdef HAVE_WIRINGPI_H |
186 piLock(LOCK_MENU); |
210 piLock(LOCK_MENU); |
|
211 #endif |
187 if (setupmenu != MENU_NONE) { |
212 if (setupmenu != MENU_NONE) { |
188 if (menutimer < MENU_TIMEOUT) |
213 if (menutimer < MENU_TIMEOUT) |
189 menutimer++; |
214 menutimer++; |
190 else { |
215 else { |
191 setupmenu = MENU_NONE; |
216 setupmenu = MENU_NONE; |
192 } |
217 } |
193 } |
218 } |
|
219 #ifdef HAVE_WIRINGPI_H |
194 piUnlock(LOCK_MENU); |
220 piUnlock(LOCK_MENU); |
|
221 #endif |
195 } |
222 } |
196 } |
223 } |
197 |
224 |
198 /* |
225 /* |
199 * Loop 10 milliseconds |
226 * Loop 10 milliseconds |