summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2009-09-23 16:59:56 +0000
committerThomas Martitz <kugel@rockbox.org>2009-09-23 16:59:56 +0000
commitca85c401f58e089b27a4d37ce76265985fa470d7 (patch)
tree494dd606a51ad63132b5fdf19e4ddc12b552e45a
parentfe4526e8682fe53a9c1eac422f8e9dd8224b8376 (diff)
downloadrockbox-ca85c401f58e089b27a4d37ce76265985fa470d7.tar.gz
rockbox-ca85c401f58e089b27a4d37ce76265985fa470d7.zip
Rework the simulators button reading to not implement it's own complete driver.
Instead, implement it more as a target driver with button_read_device(), button_init_device() and button_hold(), then use the normal button driver from firmware/drivers/button.c. Fixes FS#10451 ("backlight off on hold doesn't function properly"). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22799 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/button.c27
-rw-r--r--uisimulator/sdl/button-sdl.h42
-rw-r--r--uisimulator/sdl/button.c227
3 files changed, 92 insertions, 204 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 6f6eb8f222..7199d99e28 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -33,13 +33,16 @@
33#include "serial.h" 33#include "serial.h"
34#include "power.h" 34#include "power.h"
35#include "powermgmt.h" 35#include "powermgmt.h"
36#ifdef SIMULATOR
37#include "button-sdl.h"
38#else
36#include "button-target.h" 39#include "button-target.h"
40#endif
37 41
38#ifdef HAVE_REMOTE_LCD 42#ifdef HAVE_REMOTE_LCD
39#include "lcd-remote.h" 43#include "lcd-remote.h"
40#endif 44#endif
41 45
42#ifndef SIMULATOR
43#if 0 46#if 0
44/* Older than MAX_EVENT_AGE button events are going to be ignored. 47/* Older than MAX_EVENT_AGE button events are going to be ignored.
45 * Used to prevent for example volume going up uncontrollable when events 48 * Used to prevent for example volume going up uncontrollable when events
@@ -82,9 +85,9 @@ static int button_read(void);
82#endif 85#endif
83 86
84#ifdef HAVE_TOUCHSCREEN 87#ifdef HAVE_TOUCHSCREEN
85 int last_touchscreen_touch; 88static int last_touchscreen_touch;
86#endif 89#endif
87#if defined(HAVE_HEADPHONE_DETECTION) 90#if defined(HAVE_HEADPHONE_DETECTION) && !defined(SIMULATOR)
88static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */ 91static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */
89/* This callback can be used for many different functions if needed - 92/* This callback can be used for many different functions if needed -
90 just check to which object tmo points */ 93 just check to which object tmo points */
@@ -211,8 +214,10 @@ static void button_tick(void)
211 214
212 /* Safety net for players without hardware 215 /* Safety net for players without hardware
213 poweroff */ 216 poweroff */
217#ifndef SIMULATOR
214 if(repeat_count > POWEROFF_COUNT * 10) 218 if(repeat_count > POWEROFF_COUNT * 10)
215 power_off(); 219 power_off();
220#endif
216 } 221 }
217#endif 222#endif
218 } 223 }
@@ -376,7 +381,11 @@ long button_get_w_tmo(int ticks)
376 381
377intptr_t button_get_data(void) 382intptr_t button_get_data(void)
378{ 383{
384#if defined(SIMULATOR)
385 return button_get_data_sdl();
386#else
379 return button_data; 387 return button_data;
388#endif
380} 389}
381 390
382void button_init(void) 391void button_init(void)
@@ -416,6 +425,7 @@ void button_init(void)
416 tick_add_task(button_tick); 425 tick_add_task(button_tick);
417} 426}
418 427
428#ifndef SIMULATOR
419#ifdef BUTTON_DRIVER_CLOSE 429#ifdef BUTTON_DRIVER_CLOSE
420void button_close(void) 430void button_close(void)
421{ 431{
@@ -423,7 +433,7 @@ void button_close(void)
423} 433}
424#endif /* BUTTON_DRIVER_CLOSE */ 434#endif /* BUTTON_DRIVER_CLOSE */
425 435
426#ifdef HAVE_LCD_BITMAP /* only bitmap displays can be flipped */ 436#ifdef HAVE_LCD_FLIP
427/* 437/*
428 * helper function to swap LEFT/RIGHT, UP/DOWN (if present), and F1/F3 (Recorder) 438 * helper function to swap LEFT/RIGHT, UP/DOWN (if present), and F1/F3 (Recorder)
429 */ 439 */
@@ -508,7 +518,7 @@ void button_set_flip(bool flip)
508 restore_irq(oldlevel); 518 restore_irq(oldlevel);
509 } 519 }
510} 520}
511#endif /* HAVE_LCD_BITMAP */ 521#endif /* HAVE_LCD_FLIP */
512 522
513#ifdef HAVE_BACKLIGHT 523#ifdef HAVE_BACKLIGHT
514void set_backlight_filter_keypress(bool value) 524void set_backlight_filter_keypress(bool value)
@@ -523,6 +533,7 @@ void set_remote_backlight_filter_keypress(bool value)
523#endif 533#endif
524#endif 534#endif
525 535
536#endif /* SIMULATOR */
526/* 537/*
527 * Get button pressed from hardware 538 * Get button pressed from hardware
528 */ 539 */
@@ -537,10 +548,11 @@ static int button_read(void)
537#endif 548#endif
538 int retval; 549 int retval;
539 550
540#ifdef HAVE_LCD_BITMAP 551#ifdef HAVE_LCD_FLIP
541 if (btn && flipped) 552 if (btn && flipped)
542 btn = button_flip(btn); /* swap upside down */ 553 btn = button_flip(btn); /* swap upside down */
543#endif 554#endif /* HAVE_LCD_FLIP */
555
544#ifdef HAVE_TOUCHSCREEN 556#ifdef HAVE_TOUCHSCREEN
545 if (btn & BUTTON_TOUCHSCREEN) 557 if (btn & BUTTON_TOUCHSCREEN)
546 last_touchscreen_touch = current_tick; 558 last_touchscreen_touch = current_tick;
@@ -574,7 +586,6 @@ int touchscreen_last_touch(void)
574 return last_touchscreen_touch; 586 return last_touchscreen_touch;
575} 587}
576#endif 588#endif
577#endif /* SIMULATOR */
578 589
579#ifdef HAVE_WHEEL_ACCELERATION 590#ifdef HAVE_WHEEL_ACCELERATION
580/* WHEEL_ACCEL_FACTOR = 2^16 / WHEEL_ACCEL_START */ 591/* WHEEL_ACCEL_FACTOR = 2^16 / WHEEL_ACCEL_START */
diff --git a/uisimulator/sdl/button-sdl.h b/uisimulator/sdl/button-sdl.h
new file mode 100644
index 0000000000..0adb434e6a
--- /dev/null
+++ b/uisimulator/sdl/button-sdl.h
@@ -0,0 +1,42 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Thomas Martitz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#ifndef _BUTTON_SDL_H_
24#define _BUTTON_SDL_H_
25
26#include <stdbool.h>
27#include "config.h"
28#include "button-target.h"
29
30#define HAS_BUTTON_HOLD
31#undef HAVE_LCD_FLIP
32
33#undef button_init_device
34#define button_init_device()
35
36bool button_hold(void);
37void button_init_sdl(void);
38intptr_t button_get_data_sdl(void);
39#undef button_init_device
40#define button_init_device() button_init_sdl()
41
42#endif
diff --git a/uisimulator/sdl/button.c b/uisimulator/sdl/button.c
index 45dfc3fe2c..c52cf12f9c 100644
--- a/uisimulator/sdl/button.c
+++ b/uisimulator/sdl/button.c
@@ -28,15 +28,13 @@
28#include "backlight.h" 28#include "backlight.h"
29#include "misc.h" 29#include "misc.h"
30#include "sim_tasks.h" 30#include "sim_tasks.h"
31#include "button-sdl.h"
31 32
32#include "debug.h" 33#include "debug.h"
33 34
34static intptr_t button_data; /* data value from last message dequeued */
35
36#ifdef HAVE_TOUCHSCREEN 35#ifdef HAVE_TOUCHSCREEN
37#include "touchscreen.h" 36#include "touchscreen.h"
38static int mouse_coords = 0; 37static int mouse_coords = 0;
39static int last_touchscreen_touch = 0xffff;
40#endif 38#endif
41/* how long until repeat kicks in */ 39/* how long until repeat kicks in */
42#define REPEAT_START 6 40#define REPEAT_START 6
@@ -91,23 +89,9 @@ bool remote_button_hold(void) {
91} 89}
92#endif 90#endif
93 91
94static int lastbtn;
95void button_event(int key, bool pressed) 92void button_event(int key, bool pressed)
96{ 93{
97 int new_btn = 0; 94 int new_btn = 0;
98 int diff = 0;
99 int data = 0;
100 static int count = 0;
101 static int repeat_speed = REPEAT_INTERVAL_START;
102 static int repeat_count = 0;
103 static bool repeat = false;
104 static bool post = false;
105#ifdef HAVE_BACKLIGHT
106 static bool skip_release = false;
107#ifdef HAVE_REMOTE_LCD
108 static bool skip_remote_release = false;
109#endif
110#endif
111 static bool usb_connected = false; 95 static bool usb_connected = false;
112 if (usb_connected && key != SDLK_u) 96 if (usb_connected && key != SDLK_u)
113 return; 97 return;
@@ -116,7 +100,6 @@ void button_event(int key, bool pressed)
116 100
117#ifdef HAVE_TOUCHSCREEN 101#ifdef HAVE_TOUCHSCREEN
118 case BUTTON_TOUCHSCREEN: 102 case BUTTON_TOUCHSCREEN:
119 data = mouse_coords;
120 switch (touchscreen_get_mode()) 103 switch (touchscreen_get_mode())
121 { 104 {
122 case TOUCHSCREEN_POINT: 105 case TOUCHSCREEN_POINT:
@@ -129,7 +112,8 @@ void button_event(int key, bool pressed)
129 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT}, 112 {BUTTON_MIDLEFT, BUTTON_CENTER, BUTTON_MIDRIGHT},
130 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT}, 113 {BUTTON_BOTTOMLEFT, BUTTON_BOTTOMMIDDLE, BUTTON_BOTTOMRIGHT},
131 }; 114 };
132 int px_x = ((data&0xffff0000)>>16), px_y = ((data&0x0000ffff)); 115 int px_x = ((mouse_coords&0xffff0000)>>16);
116 int px_y = ((mouse_coords&0x0000ffff));
133 new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)]; 117 new_btn = touchscreen_buttons[px_y/(LCD_HEIGHT/3)][px_x/(LCD_WIDTH/3)];
134 break; 118 break;
135 } 119 }
@@ -1223,177 +1207,30 @@ void button_event(int key, bool pressed)
1223 btn |= new_btn; 1207 btn |= new_btn;
1224 else 1208 else
1225 btn &= ~new_btn; 1209 btn &= ~new_btn;
1226
1227 /* Lots of stuff copied from real button.c. Not good, I think... */
1228
1229 /* Find out if a key has been released */
1230 diff = btn ^ lastbtn;
1231 if(diff && (btn & diff) == 0)
1232 {
1233#ifdef HAVE_BACKLIGHT
1234#ifdef HAVE_REMOTE_LCD
1235 if(diff & BUTTON_REMOTE)
1236 if(!skip_remote_release)
1237 queue_post(&button_queue, BUTTON_REL | diff, data);
1238 else
1239 skip_remote_release = false;
1240 else
1241#endif
1242 if(!skip_release)
1243 queue_post(&button_queue, BUTTON_REL | diff, data);
1244 else
1245 skip_release = false;
1246#else
1247 queue_post(&button_queue, BUTTON_REL | diff, data);
1248#endif
1249 }
1250
1251 else
1252 {
1253 if ( btn )
1254 {
1255 /* normal keypress */
1256 if ( btn != lastbtn )
1257 {
1258 post = true;
1259 repeat = false;
1260 repeat_speed = REPEAT_INTERVAL_START;
1261
1262 }
1263 else /* repeat? */
1264 {
1265 if ( repeat )
1266 {
1267 if (!post)
1268 count--;
1269 if (count == 0)
1270 {
1271 post = true;
1272 /* yes we have repeat */
1273 repeat_speed--;
1274 if (repeat_speed < REPEAT_INTERVAL_FINISH)
1275 repeat_speed = REPEAT_INTERVAL_FINISH;
1276 count = repeat_speed;
1277
1278 repeat_count++;
1279 }
1280 }
1281 else
1282 {
1283 if (count++ > REPEAT_START)
1284 {
1285 post = true;
1286 repeat = true;
1287 repeat_count = 0;
1288 /* initial repeat */
1289 count = REPEAT_INTERVAL_START;
1290 }
1291 }
1292 }
1293 if ( post )
1294 {
1295 if(repeat)
1296 {
1297 if (queue_empty(&button_queue))
1298 {
1299 queue_post(&button_queue, BUTTON_REPEAT | btn, data);
1300#ifdef HAVE_BACKLIGHT
1301#ifdef HAVE_REMOTE_LCD
1302 if(btn & BUTTON_REMOTE)
1303 {
1304 if(skip_remote_release)
1305 skip_remote_release = false;
1306 }
1307 else
1308#endif
1309 if(skip_release)
1310 skip_release = false;
1311#endif
1312 post = false;
1313 }
1314 }
1315 else
1316 {
1317#ifdef HAVE_BACKLIGHT
1318#ifdef HAVE_REMOTE_LCD
1319 if (btn & BUTTON_REMOTE) {
1320 if (!remote_filter_first_keypress
1321 || is_remote_backlight_on(false))
1322 queue_post(&button_queue, btn, data);
1323 else
1324 skip_remote_release = true;
1325 }
1326 else
1327#endif
1328 if (!filter_first_keypress
1329 || is_backlight_on(false))
1330 queue_post(&button_queue, btn, data);
1331 else
1332 skip_release = true;
1333#else /* no backlight, nothing to skip */
1334 queue_post(&button_queue, btn, data);
1335#endif
1336 post = false;
1337 }
1338
1339#ifdef HAVE_REMOTE_LCD
1340 if(btn & BUTTON_REMOTE)
1341 remote_backlight_on();
1342 else
1343#endif
1344 backlight_on();
1345
1346 }
1347 }
1348 else
1349 {
1350 repeat = false;
1351 count = 0;
1352 }
1353 }
1354 lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
1355} 1210}
1356 1211#ifdef HAVE_BUTTON_DATA
1357/* Again copied from real button.c... */ 1212int button_read_device(int* data)
1358
1359int button_queue_count( void )
1360{ 1213{
1361 return queue_count(&button_queue); 1214 (void)data;
1362} 1215#else
1363 1216int button_read_device(void)
1364long button_get(bool block)
1365{ 1217{
1366 struct queue_event ev; 1218#endif
1367 1219 static int hold_button_old = false;
1368 if ( block || !queue_empty(&button_queue) ) { 1220 int hold_button = button_hold();
1369 queue_wait(&button_queue, &ev); 1221 /* light handling */
1370 button_data = ev.data; 1222 if (hold_button != hold_button_old)
1371 return ev.id; 1223 {
1224 hold_button_old = hold_button;
1225 backlight_hold_changed(hold_button);
1372 } 1226 }
1373 return BUTTON_NONE;
1374}
1375 1227
1376long button_get_w_tmo(int ticks) 1228 if (hold_button)
1377{ 1229 return BUTTON_NONE;
1378 struct queue_event ev;
1379 queue_wait_w_tmo(&button_queue, &ev, ticks);
1380 if (ev.id == SYS_TIMEOUT)
1381 ev.id = BUTTON_NONE;
1382 else
1383 button_data = ev.data;
1384 1230
1385 return ev.id; 1231 return btn;
1386} 1232}
1387 1233
1388intptr_t button_get_data(void)
1389{
1390#ifdef HAVE_TOUCHSCREEN
1391 return button_data;
1392#else
1393 /* Needed by the accelerating wheel driver for Sansa e200 */
1394 return 1 << 24;
1395#endif
1396}
1397 1234
1398#ifdef HAVE_TOUCHSCREEN 1235#ifdef HAVE_TOUCHSCREEN
1399extern bool debug_wps; 1236extern bool debug_wps;
@@ -1416,31 +1253,29 @@ void mouse_tick_task(void)
1416 } 1253 }
1417 1254
1418 mouse_coords = (x<<16)|y; 1255 mouse_coords = (x<<16)|y;
1419 last_touchscreen_touch = current_tick;
1420 button_event(BUTTON_TOUCHSCREEN, true); 1256 button_event(BUTTON_TOUCHSCREEN, true);
1421 if (debug_wps) 1257 if (debug_wps)
1422 printf("Mouse at: (%d, %d)\n", x, y); 1258 printf("Mouse at: (%d, %d)\n", x, y);
1423 } 1259 }
1424} 1260}
1425int touchscreen_last_touch(void) 1261
1426{
1427 return last_touchscreen_touch;
1428}
1429#endif 1262#endif
1430void button_init(void) 1263
1264intptr_t button_get_data_sdl(void)
1431{ 1265{
1432#ifdef HAVE_TOUCHSCREEN 1266#ifdef HAVE_TOUCHSCREEN
1433 tick_add_task(mouse_tick_task); 1267 /* pass the mouse coordinates to the button driver */
1268 return mouse_coords;
1269#else
1270 /* pass scrollwheel acceleration to the button driver */
1271 return 1<<24;
1434#endif 1272#endif
1435} 1273}
1436 1274
1437int button_status(void) 1275void button_init_sdl(void)
1438{
1439 return btn;
1440}
1441
1442void button_clear_queue(void)
1443{ 1276{
1444 queue_clear(&button_queue); 1277#ifdef HAVE_TOUCHSCREEN
1278 tick_add_task(mouse_tick_task);
1279#endif
1445} 1280}
1446 1281