summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/button.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/button.c')
-rw-r--r--uisimulator/sdl/button.c275
1 files changed, 275 insertions, 0 deletions
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c
new file mode 100644
index 0000000000..5def88b9af
--- /dev/null
+++ b/uisimulator/sdl/button.c
@@ -0,0 +1,275 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Felix Arends
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#include "uisdl.h"
21#include "config.h"
22#include "button.h"
23#include "kernel.h"
24#include "backlight.h"
25#include "misc.h"
26
27/* how long until repeat kicks in */
28#define REPEAT_START 6
29
30/* the speed repeat starts at */
31#define REPEAT_INTERVAL_START 4
32
33/* speed repeat finishes at */
34#define REPEAT_INTERVAL_FINISH 2
35
36struct event_queue button_queue;
37
38static int btn = 0; /* Hopefully keeps track of currently pressed keys... */
39
40void button_event(int key, bool pressed)
41{
42 bool post = false;
43 int new_btn = 0;
44 int diff = 0;
45 static int count = 0;
46 static int lastbtn;
47 static int repeat_speed = REPEAT_INTERVAL_START;
48 static int repeat_count = 0;
49 static bool repeat = false;
50
51 switch (key)
52 {
53 case SDLK_KP4:
54 case SDLK_LEFT:
55 new_btn = BUTTON_LEFT;
56 break;
57 case SDLK_KP6:
58 case SDLK_RIGHT:
59 new_btn = BUTTON_RIGHT;
60 break;
61
62 case SDLK_KP8:
63 case SDLK_UP:
64#ifdef BUTTON_UP
65 new_btn = BUTTON_UP;
66#elif defined BUTTON_SCROLL_FWD
67 new_btn = BUTTON_SCROLL_FWD;
68#elif defined BUTTON_PLAY
69 new_btn = BUTTON_PLAY;
70#endif
71 break;
72
73 case SDLK_KP2:
74 case SDLK_DOWN:
75#ifdef BUTTON_DOWN
76 new_btn = BUTTON_DOWN;
77#elif defined BUTTON_SCROLL_BACK
78 new_btn = BUTTON_SCROLL_BACK;
79#elif defined BUTTON_STOP
80 new_btn = BUTTON_STOP;
81#endif
82 break;
83
84 case SDLK_KP_PLUS:
85#ifdef BUTTON_ON
86 new_btn = BUTTON_ON;
87#elif defined(BUTTON_SELECT) && defined(BUTTON_PLAY)
88 new_btn = BUTTON_PLAY;
89#endif
90 break;
91
92#ifdef BUTTON_OFF
93 case SDLK_RETURN:
94 new_btn = BUTTON_OFF;
95 break;
96#endif
97
98#ifdef BUTTON_F1
99 case SDLK_KP_DIVIDE:
100 case SDLK_F1:
101 new_btn = BUTTON_F1;
102 break;
103 case SDLK_KP_MULTIPLY:
104 case SDLK_F2:
105 new_btn = BUTTON_F2;
106 break;
107 case SDLK_KP_MINUS:
108 case SDLK_F3:
109 new_btn = BUTTON_F3;
110 break;
111#elif defined(BUTTON_REC)
112 case SDLK_KP_DIVIDE:
113 case SDLK_F1:
114 new_btn = BUTTON_REC;
115 break;
116#endif
117
118 case SDLK_KP5:
119 case SDLK_SPACE:
120#if defined(BUTTON_PLAY) && !defined(BUTTON_SELECT)
121 new_btn = BUTTON_PLAY;
122#elif defined(BUTTON_SELECT)
123 new_btn = BUTTON_SELECT;
124#endif
125 break;
126
127#ifdef HAVE_LCD_BITMAP
128 case SDLK_KP0:
129 case SDLK_F5:
130 if(pressed)
131 {
132 screen_dump();
133 return;
134 }
135 break;
136#endif
137
138 case SDLK_PERIOD:
139 case SDLK_INSERT:
140#ifdef BUTTON_MENU
141 new_btn = BUTTON_MENU;
142#elif defined(BUTTON_MODE)
143 new_btn = BUTTON_MODE;
144#endif
145 break;
146 }
147
148 if (pressed)
149 btn |= new_btn;
150 else
151 btn &= ~new_btn;
152
153 /* Lots of stuff copied from real button.c. Not good, I think... */
154
155 /* Find out if a key has been released */
156 diff = btn ^ lastbtn;
157
158 if(diff && (btn & diff) == 0)
159 {
160 queue_post(&button_queue, BUTTON_REL | diff, NULL);
161 }
162 else
163 {
164 if ( btn )
165 {
166 /* normal keypress */
167 if ( btn != lastbtn )
168 {
169 post = true;
170 repeat = false;
171 repeat_speed = REPEAT_INTERVAL_START;
172
173 }
174 else /* repeat? */
175 {
176 if ( repeat )
177 {
178 count--;
179 if (count == 0)
180 {
181 post = true;
182 /* yes we have repeat */
183 repeat_speed--;
184 if (repeat_speed < REPEAT_INTERVAL_FINISH)
185 repeat_speed = REPEAT_INTERVAL_FINISH;
186 count = repeat_speed;
187
188 repeat_count++;
189 }
190 }
191 else
192 {
193 if (count++ > REPEAT_START)
194 {
195 post = true;
196 repeat = true;
197 repeat_count = 0;
198 /* initial repeat */
199 count = REPEAT_INTERVAL_START;
200 }
201 }
202 }
203 if ( post )
204 {
205 if(repeat)
206 queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
207 else
208 queue_post(&button_queue, btn, NULL);
209
210#ifdef HAVE_REMOTE_LCD
211 if(btn & BUTTON_REMOTE)
212 remote_backlight_on();
213 else
214#endif
215 backlight_on();
216
217 }
218 }
219 else
220 {
221 repeat = false;
222 count = 0;
223 }
224 }
225 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
226}
227
228/* Again copied from real button.c... */
229
230long button_get(bool block)
231{
232 struct event ev;
233
234 if ( block || !queue_empty(&button_queue) ) {
235 queue_wait(&button_queue, &ev);
236 return ev.id;
237 }
238 return BUTTON_NONE;
239}
240
241long button_get_w_tmo(int ticks)
242{
243 struct event ev;
244 queue_wait_w_tmo(&button_queue, &ev, ticks);
245 return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE;
246}
247
248void button_init(void)
249{
250}
251
252int button_status(void)
253{
254 return btn;
255}
256
257void button_clear_queue(void)
258{
259 queue_clear(&button_queue);
260}
261
262#ifdef HAS_BUTTON_HOLD
263bool button_hold(void) {
264 /* temp fix for hold button on irivers */
265 return false;
266}
267#endif
268
269#ifdef HAS_REMOTE_BUTTON_HOLD
270bool remote_button_hold(void) {
271 /* temp fix for hold button on irivers */
272 return false;
273}
274#endif
275