mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
clean up button.c optimize !filter_first_keypress
do a bit of cleanup in button_tick move filter_first_keypress to a function pointer Change-Id: Iefb05c1a182c1e15cfb5bca8e2ef31a710d15eba
This commit is contained in:
parent
6cbf2160e5
commit
a00bd421ac
3 changed files with 119 additions and 106 deletions
|
@ -1065,3 +1065,14 @@ void buttonlight_set_brightness(int val) { (void)val; }
|
||||||
#endif /* HAVE_BUTTON_LIGHT */
|
#endif /* HAVE_BUTTON_LIGHT */
|
||||||
|
|
||||||
#endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */
|
#endif /* defined(HAVE_BACKLIGHT) && defined(BACKLIGHT_FULL_INIT) */
|
||||||
|
|
||||||
|
#ifndef HAVE_BUTTON_LIGHT /* Dummy Functions */
|
||||||
|
void buttonlight_on(void) {}
|
||||||
|
void buttonlight_on_ignore(bool value, int timeout){(void)value;(void)timeout;}
|
||||||
|
void buttonlight_off(void) {}
|
||||||
|
void buttonlight_set_timeout(int value) {(void)value;}
|
||||||
|
#endif /* ndef HAVE_BUTTON_LIGHT */
|
||||||
|
|
||||||
|
#ifndef HAVE_BUTTONLIGHT_BRIGHTNESS /* Dummy Functions */
|
||||||
|
void buttonlight_set_brightness(int val) { (void)val; }
|
||||||
|
#endif /* ndef HAVE_BUTTONLIGHT_BRIGHTNESS */
|
||||||
|
|
|
@ -51,18 +51,14 @@ static long lastbtn; /* Last valid button status */
|
||||||
static long last_read; /* Last button status, for debouncing/filtering */
|
static long last_read; /* Last button status, for debouncing/filtering */
|
||||||
static intptr_t button_data; /* data value from last message dequeued */
|
static intptr_t button_data; /* data value from last message dequeued */
|
||||||
static bool flipped; /* buttons can be flipped to match the LCD flip */
|
static bool flipped; /* buttons can be flipped to match the LCD flip */
|
||||||
#ifdef HAVE_BACKLIGHT
|
|
||||||
static bool filter_first_keypress;
|
#ifdef HAVE_BACKLIGHT /* Filter first keypress function pointer */
|
||||||
|
static bool (*keypress_filter_fn)(int, int);
|
||||||
#ifdef HAVE_REMOTE_LCD
|
#ifdef HAVE_REMOTE_LCD
|
||||||
static bool remote_filter_first_keypress;
|
static bool (*remote_keypress_filter_fn)(int, int);
|
||||||
#endif
|
#endif
|
||||||
#endif /* HAVE_BACKLIGHT */
|
#endif /* HAVE_BACKLIGHT */
|
||||||
#ifdef HAVE_HEADPHONE_DETECTION
|
|
||||||
static bool phones_present = false;
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_LINEOUT_DETECTION
|
|
||||||
static bool lineout_present = false;
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_SW_POWEROFF
|
#ifdef HAVE_SW_POWEROFF
|
||||||
static bool enable_sw_poweroff = true;
|
static bool enable_sw_poweroff = true;
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,7 +68,7 @@ static bool enable_sw_poweroff = true;
|
||||||
|
|
||||||
/* The next two make repeat "accelerate", which is nice for lists
|
/* The next two make repeat "accelerate", which is nice for lists
|
||||||
* which begin to scroll a bit faster when holding until the
|
* which begin to scroll a bit faster when holding until the
|
||||||
* real list accerelation kicks in (this smooths acceleration).
|
* real list acceleration kicks in (this smooths acceleration).
|
||||||
*
|
*
|
||||||
* Note that touchscreen pointing events are not subject to this
|
* Note that touchscreen pointing events are not subject to this
|
||||||
* acceleration and always use REPEAT_INTERVAL_TOUCH. (Do repeat
|
* acceleration and always use REPEAT_INTERVAL_TOUCH. (Do repeat
|
||||||
|
@ -86,19 +82,24 @@ static bool enable_sw_poweroff = true;
|
||||||
/* repeat interval for touch events */
|
/* repeat interval for touch events */
|
||||||
#define REPEAT_INTERVAL_TOUCH (5*HZ/100)
|
#define REPEAT_INTERVAL_TOUCH (5*HZ/100)
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
static int button_read(int *data);
|
|
||||||
static int lastdata = 0;
|
static int lastdata = 0;
|
||||||
#else
|
static int button_read(int *data);
|
||||||
static int button_read(void);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
static long last_touchscreen_touch;
|
static long last_touchscreen_touch;
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_HEADPHONE_DETECTION)
|
|
||||||
static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */
|
|
||||||
|
|
||||||
|
static void button_remote_post(void)
|
||||||
|
{
|
||||||
|
#if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR)
|
||||||
|
/* Post events for the remote control */
|
||||||
|
int btn = remote_control_rx();
|
||||||
|
if(btn)
|
||||||
|
button_try_post(btn, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(HAVE_HEADPHONE_DETECTION)
|
||||||
static int hp_detect_callback(struct timeout *tmo)
|
static int hp_detect_callback(struct timeout *tmo)
|
||||||
{
|
{
|
||||||
/* Try to post only transistions */
|
/* Try to post only transistions */
|
||||||
|
@ -111,8 +112,6 @@ static int hp_detect_callback(struct timeout *tmo)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LINEOUT_DETECTION)
|
#if defined(HAVE_LINEOUT_DETECTION)
|
||||||
static struct timeout lo_detect_timeout; /* Debouncer for lineout plug/unplug */
|
|
||||||
|
|
||||||
static int lo_detect_callback(struct timeout *tmo)
|
static int lo_detect_callback(struct timeout *tmo)
|
||||||
{
|
{
|
||||||
/* Try to post only transistions */
|
/* Try to post only transistions */
|
||||||
|
@ -124,6 +123,34 @@ static int lo_detect_callback(struct timeout *tmo)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void check_audio_peripheral_state(void)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_HEADPHONE_DETECTION)
|
||||||
|
static struct timeout hp_detect_timeout; /* Debouncer for headphone plug/unplug */
|
||||||
|
static bool phones_present = false;
|
||||||
|
|
||||||
|
if (headphones_inserted() != phones_present)
|
||||||
|
{
|
||||||
|
/* Use the autoresetting oneshot to debounce the detection signal */
|
||||||
|
phones_present = !phones_present;
|
||||||
|
timeout_register(&hp_detect_timeout, hp_detect_callback,
|
||||||
|
HZ/2, phones_present);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(HAVE_LINEOUT_DETECTION)
|
||||||
|
static struct timeout lo_detect_timeout; /* Debouncer for lineout plug/unplug */
|
||||||
|
static bool lineout_present = false;
|
||||||
|
|
||||||
|
if (lineout_inserted() != lineout_present)
|
||||||
|
{
|
||||||
|
/* Use the autoresetting oneshot to debounce the detection signal */
|
||||||
|
lineout_present = !lineout_present;
|
||||||
|
timeout_register(&lo_detect_timeout, lo_detect_callback,
|
||||||
|
HZ/2, lineout_present);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static bool button_try_post(int button, int data)
|
static bool button_try_post(int button, int data)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
@ -153,6 +180,43 @@ static bool button_try_post(int button, int data)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_BACKLIGHT
|
||||||
|
/* disabled function is shared between Main & Remote LCDs */
|
||||||
|
static bool filter_first_keypress_disabled(int button, int data)
|
||||||
|
{
|
||||||
|
button_try_post(button, data);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool filter_first_keypress_enabled(int button, int data)
|
||||||
|
{
|
||||||
|
#if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP)
|
||||||
|
if (is_backlight_on(false) && lcd_active())
|
||||||
|
#else
|
||||||
|
if (is_backlight_on(false))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return filter_first_keypress_disabled(button, data);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_REMOTE_LCD
|
||||||
|
static bool filter_first_remote_keypress_enabled(int button, int data)
|
||||||
|
{
|
||||||
|
if (is_remote_backlight_on(false)
|
||||||
|
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
|
||||||
|
|| (remote_type()==REMOTETYPE_H300_NONLCD)
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return filter_first_keypress_disabled(button, data);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif /* def HAVE_REMOTE_LCD */
|
||||||
|
#endif /* def HAVE_BACKLIGHT */
|
||||||
|
|
||||||
static void button_tick(void)
|
static void button_tick(void)
|
||||||
{
|
{
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
|
@ -168,42 +232,13 @@ static void button_tick(void)
|
||||||
#endif
|
#endif
|
||||||
int diff;
|
int diff;
|
||||||
int btn;
|
int btn;
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
int data = 0;
|
int data = 0;
|
||||||
#else
|
|
||||||
const int data = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR)
|
button_remote_post();
|
||||||
/* Post events for the remote control */
|
|
||||||
btn = remote_control_rx();
|
|
||||||
if(btn)
|
|
||||||
button_try_post(btn, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
btn = button_read(&data);
|
btn = button_read(&data);
|
||||||
#else
|
|
||||||
btn = button_read();
|
check_audio_peripheral_state();
|
||||||
#endif
|
|
||||||
#if defined(HAVE_HEADPHONE_DETECTION)
|
|
||||||
if (headphones_inserted() != phones_present)
|
|
||||||
{
|
|
||||||
/* Use the autoresetting oneshot to debounce the detection signal */
|
|
||||||
phones_present = !phones_present;
|
|
||||||
timeout_register(&hp_detect_timeout, hp_detect_callback,
|
|
||||||
HZ/2, phones_present);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_LINEOUT_DETECTION)
|
|
||||||
if (lineout_inserted() != lineout_present)
|
|
||||||
{
|
|
||||||
/* Use the autoresetting oneshot to debounce the detection signal */
|
|
||||||
lineout_present = !lineout_present;
|
|
||||||
timeout_register(&lo_detect_timeout, lo_detect_callback,
|
|
||||||
HZ/2, lineout_present);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Find out if a key has been released */
|
/* Find out if a key has been released */
|
||||||
diff = btn ^ lastbtn;
|
diff = btn ^ lastbtn;
|
||||||
|
@ -348,48 +383,21 @@ static void button_tick(void)
|
||||||
#ifdef HAVE_BACKLIGHT
|
#ifdef HAVE_BACKLIGHT
|
||||||
#ifdef HAVE_REMOTE_LCD
|
#ifdef HAVE_REMOTE_LCD
|
||||||
if (btn & BUTTON_REMOTE) {
|
if (btn & BUTTON_REMOTE) {
|
||||||
if (!remote_filter_first_keypress
|
skip_remote_release = remote_keypress_filter_fn(btn, data);
|
||||||
|| is_remote_backlight_on(false)
|
remote_backlight_on();
|
||||||
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
|
|
||||||
|| (remote_type()==REMOTETYPE_H300_NONLCD)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
button_try_post(btn, data);
|
|
||||||
else
|
|
||||||
skip_remote_release = true;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
if (!filter_first_keypress
|
{
|
||||||
#if defined(HAVE_TRANSFLECTIVE_LCD) && defined(HAVE_LCD_SLEEP)
|
skip_release = keypress_filter_fn(btn, data);
|
||||||
|| (is_backlight_on(false) && lcd_active())
|
backlight_on();
|
||||||
#else
|
buttonlight_on();
|
||||||
|| is_backlight_on(false)
|
}
|
||||||
#endif
|
|
||||||
#if BUTTON_REMOTE
|
|
||||||
|| (btn & BUTTON_REMOTE)
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
button_try_post(btn, data);
|
|
||||||
else
|
|
||||||
skip_release = true;
|
|
||||||
#else /* no backlight, nothing to skip */
|
#else /* no backlight, nothing to skip */
|
||||||
button_try_post(btn, data);
|
button_try_post(btn, data);
|
||||||
#endif
|
#endif
|
||||||
post = false;
|
post = false;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_REMOTE_LCD
|
|
||||||
if(btn & BUTTON_REMOTE)
|
|
||||||
remote_backlight_on();
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
backlight_on();
|
|
||||||
#ifdef HAVE_BUTTON_LIGHT
|
|
||||||
buttonlight_on();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
reset_poweroff_timer();
|
reset_poweroff_timer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,9 +408,8 @@ static void button_tick(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
|
lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
lastdata = data;
|
lastdata = data;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
||||||
|
@ -515,30 +522,23 @@ intptr_t button_get_data(void)
|
||||||
|
|
||||||
void button_init(void)
|
void button_init(void)
|
||||||
{
|
{
|
||||||
|
int temp;
|
||||||
/* Init used objects first */
|
/* Init used objects first */
|
||||||
queue_init(&button_queue, true);
|
queue_init(&button_queue, true);
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
int temp;
|
|
||||||
#endif
|
|
||||||
/* hardware inits */
|
/* hardware inits */
|
||||||
button_init_device();
|
button_init_device();
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
button_read(&temp);
|
button_read(&temp);
|
||||||
lastbtn = button_read(&temp);
|
lastbtn = button_read(&temp);
|
||||||
#else
|
|
||||||
button_read();
|
|
||||||
lastbtn = button_read();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
reset_poweroff_timer();
|
reset_poweroff_timer();
|
||||||
|
|
||||||
flipped = false;
|
flipped = false;
|
||||||
#ifdef HAVE_BACKLIGHT
|
#ifdef HAVE_BACKLIGHT
|
||||||
filter_first_keypress = false;
|
set_backlight_filter_keypress(false);
|
||||||
#ifdef HAVE_REMOTE_LCD
|
#ifdef HAVE_REMOTE_LCD
|
||||||
remote_filter_first_keypress = false;
|
set_remote_backlight_filter_keypress(false);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_TOUCHSCREEN
|
#ifdef HAVE_TOUCHSCREEN
|
||||||
|
@ -649,12 +649,18 @@ void button_set_flip(bool flip)
|
||||||
#ifdef HAVE_BACKLIGHT
|
#ifdef HAVE_BACKLIGHT
|
||||||
void set_backlight_filter_keypress(bool value)
|
void set_backlight_filter_keypress(bool value)
|
||||||
{
|
{
|
||||||
filter_first_keypress = value;
|
if (!value)
|
||||||
|
keypress_filter_fn = filter_first_keypress_disabled;
|
||||||
|
else
|
||||||
|
keypress_filter_fn = filter_first_keypress_enabled;
|
||||||
}
|
}
|
||||||
#ifdef HAVE_REMOTE_LCD
|
#ifdef HAVE_REMOTE_LCD
|
||||||
void set_remote_backlight_filter_keypress(bool value)
|
void set_remote_backlight_filter_keypress(bool value)
|
||||||
{
|
{
|
||||||
remote_filter_first_keypress = value;
|
if (!value)
|
||||||
|
remote_keypress_filter_fn = filter_first_keypress_disabled;
|
||||||
|
else
|
||||||
|
remote_keypress_filter_fn = filter_first_remote_keypress_enabled;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -662,13 +668,13 @@ void set_remote_backlight_filter_keypress(bool value)
|
||||||
/*
|
/*
|
||||||
* Get button pressed from hardware
|
* Get button pressed from hardware
|
||||||
*/
|
*/
|
||||||
#ifdef HAVE_BUTTON_DATA
|
|
||||||
static int button_read(int *data)
|
static int button_read(int *data)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_BUTTON_DATA
|
||||||
int btn = button_read_device(data);
|
int btn = button_read_device(data);
|
||||||
#else
|
#else
|
||||||
static int button_read(void)
|
(void) data;
|
||||||
{
|
|
||||||
int btn = button_read_device();
|
int btn = button_read_device();
|
||||||
#endif
|
#endif
|
||||||
int retval;
|
int retval;
|
||||||
|
|
|
@ -98,16 +98,12 @@ extern int backlight_brightness;
|
||||||
void backlight_set_brightness(int val);
|
void backlight_set_brightness(int val);
|
||||||
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
|
#endif /* HAVE_BACKLIGHT_BRIGHTNESS */
|
||||||
|
|
||||||
#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
|
|
||||||
void buttonlight_set_brightness(int val);
|
void buttonlight_set_brightness(int val);
|
||||||
#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
|
|
||||||
|
|
||||||
#ifdef HAVE_BUTTON_LIGHT
|
|
||||||
void buttonlight_on_ignore(bool value, int timeout);
|
void buttonlight_on_ignore(bool value, int timeout);
|
||||||
void buttonlight_on(void);
|
void buttonlight_on(void);
|
||||||
void buttonlight_off(void);
|
void buttonlight_off(void);
|
||||||
void buttonlight_set_timeout(int value);
|
void buttonlight_set_timeout(int value);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Private API for use in target tree backlight code only */
|
/* Private API for use in target tree backlight code only */
|
||||||
#ifdef HAVE_BUTTON_LIGHT
|
#ifdef HAVE_BUTTON_LIGHT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue