1
0
Fork 0
forked from len0rd/rockbox

Wheel acceleration for e200. A general acceleration interface intended for use on any scroll target and by any code. A general interface to obtain data associated with most recently dequeued button presses and actions. Use #define HAVE_SCROLLWHEEL and set appropriate constants, values in the scroller driver that feel right.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13959 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-07-22 21:02:24 +00:00
parent 3213d4a0f5
commit 873e0fd1ef
11 changed files with 168 additions and 30 deletions

View file

@ -49,6 +49,7 @@ struct event_queue button_queue;
static long lastbtn; /* Last valid button status */
static long last_read; /* Last button status, for debouncing/filtering */
static intptr_t button_data; /* data value from last message dequeued */
#ifdef HAVE_LCD_BITMAP
static bool flipped; /* buttons can be flipped to match the LCD flip */
#endif
@ -309,7 +310,7 @@ long button_get(bool block)
if (current_tick - ev.tick > MAX_EVENT_AGE)
return BUTTON_NONE;
#endif
button_data = ev.data;
return ev.id;
}
@ -329,7 +330,17 @@ long button_get_w_tmo(int ticks)
#endif
queue_wait_w_tmo(&button_queue, &ev, ticks);
return (ev.id != SYS_TIMEOUT)? ev.id: BUTTON_NONE;
if (ev.id == SYS_TIMEOUT)
ev.id = BUTTON_NONE;
else
button_data = ev.data;
return ev.id;
}
intptr_t button_get_data(void)
{
return button_data;
}
void button_init(void)
@ -470,3 +481,33 @@ void button_clear_queue(void)
{
queue_clear(&button_queue);
}
#ifdef HAVE_SCROLLWHEEL
/**
* data:
* [31] Use acceleration
* [30:24] Message post count (skipped + 1) (1-127)
* [23:0] Velocity - clicks/uS - 0.24 fixed point
*
* factor:
* Wheel acceleration scaling factor - x.24 fixed point -
* no greater than what will not overflow 64 bits when multiplied
* by the driver's maximum velocity in (clicks/usec)^2 in 0.24
*/
int button_apply_acceleration(unsigned int data, unsigned int factor)
{
int delta = (data >> 24) & 0x7f;
if ((data & (1 << 31)) != 0)
{
unsigned int v = data & 0xffffff;
v = factor * (unsigned long long)v*v / 0xffffffffffffull;
if (v > 1)
delta *= v;
}
return delta;
}
#endif /* HAVE_SCROLLWHEEL */