mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
hosted: Have common /dev/input code handle touchscreens.
With this we should be able to consolidate some of the hosted variations. Change-Id: Ie03631b4e700e3a0adcdc1b8476237384f0ace1a
This commit is contained in:
parent
f38109f8ed
commit
3270daf2c4
2 changed files with 140 additions and 35 deletions
|
@ -92,7 +92,79 @@ static int button_delay_release = 0;
|
||||||
static int delay_tick = 0;
|
static int delay_tick = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int button_read_device(void)
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
/* Last known touchscreen coordinates. */
|
||||||
|
static int _last_x = 0;
|
||||||
|
static int _last_y = 0;
|
||||||
|
|
||||||
|
/* Last known touchscreen state. */
|
||||||
|
static enum
|
||||||
|
{
|
||||||
|
TOUCHSCREEN_STATE_UNKNOWN = 0,
|
||||||
|
TOUCHSCREEN_STATE_UP,
|
||||||
|
TOUCHSCREEN_STATE_DOWN
|
||||||
|
} _last_touch_state = TOUCHSCREEN_STATE_UNKNOWN;
|
||||||
|
|
||||||
|
// XXX ... figure out what is standard.
|
||||||
|
#define EVENT_VALUE_TOUCHSCREEN_PRESS 1
|
||||||
|
#define EVENT_VALUE_TOUCHSCREEN_RELEASE -1
|
||||||
|
|
||||||
|
static int ts_enabled = 0;
|
||||||
|
|
||||||
|
void touchscreen_enable_device(bool en)
|
||||||
|
{
|
||||||
|
ts_enabled = en;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool handle_touchscreen_event(__u16 code, __s32 value)
|
||||||
|
{
|
||||||
|
bool read_more = false;
|
||||||
|
|
||||||
|
switch(code)
|
||||||
|
{
|
||||||
|
case ABS_MT_POSITION_X:
|
||||||
|
{
|
||||||
|
_last_x = value;
|
||||||
|
|
||||||
|
/* x -> next will be y. */
|
||||||
|
read_more = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ABS_MT_POSITION_Y:
|
||||||
|
{
|
||||||
|
_last_y = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ABS_MT_TRACKING_ID:
|
||||||
|
{
|
||||||
|
if(value == EVENT_VALUE_TOUCHSCREEN_PRESS)
|
||||||
|
{
|
||||||
|
_last_touch_state = TOUCHSCREEN_STATE_DOWN;
|
||||||
|
|
||||||
|
/* Press -> next will be x. */
|
||||||
|
read_more = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_last_touch_state = TOUCHSCREEN_STATE_UP;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return read_more;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
#define BDATA int *data
|
||||||
|
#else
|
||||||
|
#define BDATA void
|
||||||
|
#endif
|
||||||
|
int button_read_device(BDATA)
|
||||||
{
|
{
|
||||||
static int button_bitmap = 0;
|
static int button_bitmap = 0;
|
||||||
struct input_event event;
|
struct input_event event;
|
||||||
|
@ -121,44 +193,62 @@ int button_read_device(void)
|
||||||
int size = read(poll_fds[i].fd, &event, sizeof(event));
|
int size = read(poll_fds[i].fd, &event, sizeof(event));
|
||||||
if(size == (int)sizeof(event))
|
if(size == (int)sizeof(event))
|
||||||
{
|
{
|
||||||
/* map linux event code to rockbox button bitmap */
|
switch(event.type) {
|
||||||
int bmap = button_map(event.code);
|
case EV_KEY: {
|
||||||
|
/* map linux event code to rockbox button bitmap */
|
||||||
|
int bmap = button_map(event.code);
|
||||||
|
|
||||||
/* event.value == 0x10000 means press
|
/* event.value == 0x10000 means press
|
||||||
* event.value == 0 means release
|
* event.value == 0 means release
|
||||||
*/
|
*/
|
||||||
if(event.value)
|
if(event.value)
|
||||||
{
|
|
||||||
#ifdef HAVE_SCROLLWHEEL
|
|
||||||
/* Filter out wheel ticks */
|
|
||||||
if (bmap & BUTTON_SCROLL_BACK)
|
|
||||||
wheel_ticks--;
|
|
||||||
else if (bmap & BUTTON_SCROLL_FWD)
|
|
||||||
wheel_ticks++;
|
|
||||||
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
|
|
||||||
#endif
|
|
||||||
#ifdef BUTTON_DELAY_RELEASE
|
|
||||||
bmap &= ~BUTTON_DELAY_RELEASE;
|
|
||||||
#endif
|
|
||||||
button_bitmap |= bmap;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef BUTTON_DELAY_RELEASE
|
|
||||||
/* Delay the release of any requested buttons */
|
|
||||||
if (bmap & BUTTON_DELAY_RELEASE)
|
|
||||||
{
|
{
|
||||||
button_delay_release |= bmap & ~BUTTON_DELAY_RELEASE;
|
#ifdef HAVE_SCROLLWHEEL
|
||||||
delay_tick = current_tick + HZ/20;
|
/* Filter out wheel ticks */
|
||||||
bmap = 0;
|
if (bmap & BUTTON_SCROLL_BACK)
|
||||||
}
|
wheel_ticks--;
|
||||||
|
else if (bmap & BUTTON_SCROLL_FWD)
|
||||||
|
wheel_ticks++;
|
||||||
|
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef BUTTON_DELAY_RELEASE
|
||||||
|
bmap &= ~BUTTON_DELAY_RELEASE;
|
||||||
|
#endif
|
||||||
|
button_bitmap |= bmap;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#ifdef BUTTON_DELAY_RELEASE
|
||||||
|
/* Delay the release of any requested buttons */
|
||||||
|
if (bmap & BUTTON_DELAY_RELEASE)
|
||||||
|
{
|
||||||
|
button_delay_release |= bmap & ~BUTTON_DELAY_RELEASE;
|
||||||
|
delay_tick = current_tick + HZ/20;
|
||||||
|
bmap = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#ifdef HAVE_SCROLLWHEEL
|
#ifdef HAVE_SCROLLWHEEL
|
||||||
/* Wheel gives us press+release back to back; ignore the release */
|
/* Wheel gives us press+release back to back; ignore the release */
|
||||||
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
|
bmap &= ~(BUTTON_SCROLL_BACK|BUTTON_SCROLL_FWD);
|
||||||
#endif
|
#endif
|
||||||
button_bitmap &= ~bmap;
|
button_bitmap &= ~bmap;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
case EV_ABS: {
|
||||||
|
if (ts_enabled) {
|
||||||
|
handle_touchscreen_event(event.code, event.value);
|
||||||
|
} else {
|
||||||
|
/* If disabled... ignore */
|
||||||
|
_last_touch_state = TOUCHSCREEN_STATE_UNKNOWN;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
/* Ignore other event types */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,5 +283,14 @@ int button_read_device(void)
|
||||||
}
|
}
|
||||||
#endif /* HAVE_SCROLLWHEEL */
|
#endif /* HAVE_SCROLLWHEEL */
|
||||||
|
|
||||||
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
int touch = touchscreen_to_pixels(_last_x, _last_y, data);
|
||||||
|
|
||||||
|
if(_last_touch_state == TOUCHSCREEN_STATE_DOWN)
|
||||||
|
{
|
||||||
|
return button_bitmap | touch;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return button_bitmap;
|
return button_bitmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,10 +125,16 @@ void system_exception_wait(void)
|
||||||
backlight_hw_on();
|
backlight_hw_on();
|
||||||
backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
|
backlight_hw_brightness(DEFAULT_BRIGHTNESS_SETTING);
|
||||||
/* wait until button press and release */
|
/* wait until button press and release */
|
||||||
while(button_read_device() != 0) {}
|
#ifdef HAVE_BUTTON_DATA
|
||||||
while(button_read_device() == 0) {}
|
int bdata;
|
||||||
while(button_read_device() != 0) {}
|
#define BDATA &bdata
|
||||||
while(button_read_device() == 0) {}
|
#else
|
||||||
|
#define BDATA
|
||||||
|
#endif
|
||||||
|
while(button_read_device(BDATA) != 0) {}
|
||||||
|
while(button_read_device(BDATA) == 0) {}
|
||||||
|
while(button_read_device(BDATA) != 0) {}
|
||||||
|
while(button_read_device(BDATA) == 0) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hostfs_removable(IF_MD_NONVOID(int drive))
|
bool hostfs_removable(IF_MD_NONVOID(int drive))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue