19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
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 "panel.h" |
25 #include "panel.h" |
|
26 |
25 |
27 |
26 #ifdef HAVE_WIRINGPI_H |
28 #ifdef HAVE_WIRINGPI_H |
27 |
29 |
28 |
30 |
29 extern int my_shutdown; |
31 extern int my_shutdown; |
30 extern int debug; |
32 extern int debug; |
31 |
33 |
|
34 int Key_Enter = FALSE; |
|
35 int Key_Enter_Long = FALSE; |
|
36 int Key_Up = FALSE; |
|
37 int Key_Down = FALSE; |
|
38 |
|
39 |
|
40 int keycheck(void) |
|
41 { |
|
42 if (Key_Enter && Key_Up && Key_Down) |
|
43 return KEY_ALL; |
|
44 if (Key_Up && Key_Down) |
|
45 return KEY_UPDOWN; |
|
46 if (Key_Up) |
|
47 return KEY_UP; |
|
48 if (Key_Down) |
|
49 return KEY_DOWN; |
|
50 if (Key_Enter_Long) |
|
51 return KEY_CONFIRM; |
|
52 if (Key_Enter) |
|
53 return KEY_ENTER; |
|
54 return KEY_NONE; |
|
55 } |
|
56 |
32 |
57 |
33 |
58 |
34 PI_THREAD (my_panel_loop) |
59 PI_THREAD (my_panel_loop) |
35 { |
60 { |
|
61 int Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE; |
|
62 time_t Last = (time_t)0, Now; |
|
63 |
|
64 pinMode(PANEL_LED, OUTPUT); |
|
65 pinMode(PANEL_ENTER, INPUT); |
|
66 pinMode(PANEL_UP, INPUT); |
|
67 pinMode(PANEL_DOWN, INPUT); |
|
68 |
36 |
69 |
37 syslog(LOG_NOTICE, "Thread my_panel_loop started"); |
70 syslog(LOG_NOTICE, "Thread my_panel_loop started"); |
38 if (debug) |
71 if (debug) |
39 fprintf(stdout, "Thread my_panel_loop started\n"); |
72 fprintf(stdout, "Thread my_panel_loop started\n"); |
40 |
73 |
42 * Loop forever until the external shutdown variable is set. |
75 * Loop forever until the external shutdown variable is set. |
43 */ |
76 */ |
44 for (;;) { |
77 for (;;) { |
45 if (my_shutdown) |
78 if (my_shutdown) |
46 break; |
79 break; |
|
80 |
|
81 if (digitalRead(PANEL_ENTER)) { |
|
82 Enter = 0; |
|
83 Key_Enter = FALSE; |
|
84 Key_Enter_Long = FALSE; |
|
85 } else { |
|
86 Enter++; |
|
87 if (Enter > PRESS_NORMAL) |
|
88 Key_Enter = TRUE; |
|
89 if (Enter > PRESS_LONG) |
|
90 Key_Enter_Long = TRUE; |
|
91 } |
|
92 |
|
93 if (digitalRead(PANEL_UP)) { |
|
94 Up = 0; |
|
95 Key_Up = FALSE; |
|
96 } else { |
|
97 Up++; |
|
98 if (Up > PRESS_NORMAL) |
|
99 Key_Up = TRUE; |
|
100 } |
|
101 |
|
102 if (digitalRead(PANEL_DOWN)) { |
|
103 Down = 0; |
|
104 Key_Down = FALSE; |
|
105 } else { |
|
106 Down++; |
|
107 if (Down > PRESS_NORMAL) |
|
108 Key_Down = TRUE; |
|
109 } |
|
110 |
|
111 if (Key_Enter || Key_Up || Key_Down) { |
|
112 AnyKey = TRUE; |
|
113 /* |
|
114 * Any key is pressed. |
|
115 */ |
|
116 if (Backlight == 0) |
|
117 setBacklight(1); |
|
118 Backlight = LCD_SLEEP; |
|
119 } else { |
|
120 /* |
|
121 * No key pressed. |
|
122 */ |
|
123 AnyKey = FALSE; |
|
124 } |
|
125 |
|
126 // if (debug && AnyKey) |
|
127 // fprintf(stdout, "keys Enter=%d,%s,%s Up=%d,%s Down=%d,%s\n", |
|
128 // Enter, Key_Enter ?"True":"False", Key_Enter_Long ?"True":"False", Up, Key_Up ?"True":"False", Down, Key_Down ?"True":"False"); |
|
129 |
|
130 Now = time(NULL); |
|
131 if (Now != Last) { |
|
132 Last = Now; |
|
133 |
|
134 // if (debug) |
|
135 // fprintf(stdout, "AnyKey=%s Backlight=%d\n", AnyKey ?"True":"False", Backlight); |
|
136 if (AnyKey == FALSE) { |
|
137 if (Backlight == 1) |
|
138 setBacklight(0); |
|
139 if (Backlight > 0) { |
|
140 Backlight--; |
|
141 } |
|
142 } |
|
143 |
|
144 } |
47 |
145 |
48 /* |
146 /* |
49 * Loop 10 milliseconds |
147 * Loop 10 milliseconds |
50 */ |
148 */ |
51 usleep(10000); |
149 usleep(10000); |