static void button_tick(void) { static int count = 0; static int repeat_speed = REPEAT_INTERVAL_START; static int repeat_count = 0; static bool repeat = false; static bool post = false; #ifdef HAVE_BACKLIGHT static bool skip_release = false; #ifdef HAVE_REMOTE_LCD static bool skip_remote_release = false; #endif #endif int diff; int btn; #ifdef HAVE_BUTTON_DATA int data = 0; #else const int data = 0; #endif #if defined(HAS_SERIAL_REMOTE) && !defined(SIMULATOR) /* 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); #else btn = button_read(); #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, btn_detect_callback, HZ/2, phones_present); } #endif /* Find out if a key has been released */ diff = btn ^ lastbtn; if(diff && (btn & diff) == 0) { #ifdef HAVE_BACKLIGHT #ifdef HAVE_REMOTE_LCD if(diff & BUTTON_REMOTE) if(!skip_remote_release) button_try_post(BUTTON_REL | diff, data); else skip_remote_release = false; else #endif if(!skip_release) button_try_post(BUTTON_REL | diff, data); else skip_release = false; #else button_try_post(BUTTON_REL | diff, data); #endif } else { if ( btn ) { /* normal keypress */ if ( btn != lastbtn ) { post = true; repeat = false; repeat_speed = REPEAT_INTERVAL_START; } else /* repeat? */ { if ( repeat ) { if (!post) count--; if (count == 0) { post = true; /* yes we have repeat */ if (repeat_speed > REPEAT_INTERVAL_FINISH) repeat_speed--; count = repeat_speed; repeat_count++; /* Send a SYS_POWEROFF event if we have a device which doesn't shut down easily with the OFF key */ #ifdef HAVE_SW_POWEROFF if ((btn & POWEROFF_BUTTON #ifdef RC_POWEROFF_BUTTON || btn == RC_POWEROFF_BUTTON #endif ) && #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) !charger_inserted() && #endif repeat_count > POWEROFF_COUNT) { /* Tell the main thread that it's time to power off */ sys_poweroff(); /* Safety net for players without hardware poweroff */ #if (CONFIG_PLATFORM & PLATFORM_NATIVE) if(repeat_count > POWEROFF_COUNT * 10) power_off(); #endif } #endif } } else { if (count++ > REPEAT_START) { post = true; repeat = true; repeat_count = 0; /* initial repeat */ count = REPEAT_INTERVAL_START; } #ifdef HAVE_TOUCHSCREEN else if (lastdata != data && btn == lastbtn) { /* only coordinates changed, post anyway */ if (touchscreen_get_mode() == TOUCHSCREEN_POINT) post = true; } #endif } } if ( post ) { if (repeat) { /* Only post repeat events if the queue is empty, * to avoid afterscroll effects. */ if (button_try_post(BUTTON_REPEAT | btn, data)) { #ifdef HAVE_BACKLIGHT #ifdef HAVE_REMOTE_LCD skip_remote_release = false; #endif skip_release = false; #endif post = false; } } else { #ifdef HAVE_BACKLIGHT #ifdef HAVE_REMOTE_LCD if (btn & BUTTON_REMOTE) { if (!remote_filter_first_keypress || is_remote_backlight_on(false) #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 #endif if (!filter_first_keypress || is_backlight_on(false) #if BUTTON_REMOTE || (btn & BUTTON_REMOTE) #endif ) button_try_post(btn, data); else skip_release = true; #else /* no backlight, nothing to skip */ button_try_post(btn, data); #endif 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(); } } else { repeat = false; count = 0; } } lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); #ifdef HAVE_BUTTON_DATA lastdata = data; #endif }
static void button_event(int key, bool pressed) { int new_btn = 0; static bool usb_connected = false; if (usb_connected && key != USB_KEY) return; switch (key) { case USB_KEY: if (!pressed) { usb_connected = !usb_connected; if (usb_connected) queue_post(&button_queue, SYS_USB_CONNECTED, 0); else queue_post(&button_queue, SYS_USB_DISCONNECTED, 0); } return; #if (CONFIG_PLATFORM & PLATFORM_PANDORA) case SDLK_LCTRL: /* Will post SDL_USEREVENT in shutdown_hw() if successful. */ sys_poweroff(); break; #endif #ifdef HAS_BUTTON_HOLD case SDLK_h: if(pressed) { hold_button_state = !hold_button_state; DEBUGF("Hold button is %s\n", hold_button_state?"ON":"OFF"); } return; #endif #ifdef HAS_REMOTE_BUTTON_HOLD case SDLK_j: if(pressed) { remote_hold_button_state = !remote_hold_button_state; DEBUGF("Remote hold button is %s\n", remote_hold_button_state?"ON":"OFF"); } return; #endif #if defined(IRIVER_H100_SERIES) || defined (IRIVER_H300_SERIES) case SDLK_t: if(pressed) switch(_remote_type) { case REMOTETYPE_UNPLUGGED: _remote_type=REMOTETYPE_H100_LCD; DEBUGF("Changed remote type to H100\n"); break; case REMOTETYPE_H100_LCD: _remote_type=REMOTETYPE_H300_LCD; DEBUGF("Changed remote type to H300\n"); break; case REMOTETYPE_H300_LCD: _remote_type=REMOTETYPE_H300_NONLCD; DEBUGF("Changed remote type to H300 NON-LCD\n"); break; case REMOTETYPE_H300_NONLCD: _remote_type=REMOTETYPE_UNPLUGGED; DEBUGF("Changed remote type to none\n"); break; } break; #endif case SDLK_KP0: case SDLK_F5: if(pressed) { sim_trigger_screendump(); return; } break; #ifdef HAVE_TOUCHSCREEN case SDLK_F4: if(pressed) { touchscreen_set_mode(touchscreen_get_mode() == TOUCHSCREEN_POINT ? TOUCHSCREEN_BUTTON : TOUCHSCREEN_POINT); printf("Touchscreen mode: %s\n", touchscreen_get_mode() == TOUCHSCREEN_POINT ? "TOUCHSCREEN_POINT" : "TOUCHSCREEN_BUTTON"); } #endif default: #ifdef HAVE_TOUCHSCREEN new_btn = key_to_touch(key, mouse_coords); if (!new_btn) #endif new_btn = key_to_button(key); break; } /* Call to make up for scrollwheel target implementation. This is * not handled in the main button.c driver, but on the target * implementation (look at button-e200.c for example if you are trying to * figure out why using button_get_data needed a hack before). */ #if defined(BUTTON_SCROLL_FWD) && defined(BUTTON_SCROLL_BACK) if((new_btn == BUTTON_SCROLL_FWD || new_btn == BUTTON_SCROLL_BACK) && pressed) { /* Clear these buttons from the data - adding them to the queue is * handled in the scrollwheel drivers for the targets. They do not * store the scroll forward/back buttons in their button data for * the button_read call. */ #ifdef HAVE_BACKLIGHT backlight_on(); #endif #ifdef HAVE_BUTTON_LIGHT buttonlight_on(); #endif queue_post(&button_queue, new_btn, 1<<24); new_btn &= ~(BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK); } #endif if (pressed) btn |= new_btn; else btn &= ~new_btn; }