static int do_shutdown(void) { #if CONFIG_CHARGING if (charger_inserted()) charging_splash(); else #endif sys_poweroff(); return 0; }
/* * Monitor the presence of a charger and perform critical frequent steps * such as running the battery voltage filter. */ static inline void power_thread_step(void) { /* If the power off timeout expires, the main thread has failed to shut down the system, and we need to force a power off */ if (shutdown_timeout) { shutdown_timeout -= POWER_THREAD_STEP_TICKS; if (shutdown_timeout <= 0) power_off(); } #ifdef HAVE_RTC_ALARM power_thread_rtc_process(); #endif /* * Do a digital exponential filter. We don't sample the battery if * the disk is spinning unless we are in USB mode (the disk will most * likely always be spinning in USB mode) or charging. */ if (!storage_disk_is_active() || usb_inserted() #if CONFIG_CHARGING >= CHARGING_MONITOR || charger_input_state == CHARGER #endif ) { avgbat += battery_adc_voltage() - avgbat / BATT_AVE_SAMPLES; /* * battery_millivolts is the millivolt-scaled filtered battery value. */ battery_millivolts = avgbat / BATT_AVE_SAMPLES; /* update battery status every time an update is available */ battery_status_update(); } else if (battery_percent < 8) { /* * If battery is low, observe voltage during disk activity. * Shut down if voltage drops below shutoff level and we are not * using NiMH or Alkaline batteries. */ battery_millivolts = (battery_adc_voltage() + battery_millivolts + 1) / 2; /* update battery status every time an update is available */ battery_status_update(); if (!shutdown_timeout && query_force_shutdown()) { sys_poweroff(); } else { avgbat += battery_millivolts - avgbat / BATT_AVE_SAMPLES; } } } /* power_thread_step */
void EXT3(void) { if (get_pmu_type() == PCF50606) { unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ /* Clear pending interrupts from pcf50606 */ pcf50606_read_multiple(0x02, data, 3); if (data[0] & 0x04) { /* ONKEY1S */ if (!charger_inserted()) sys_poweroff(); else pcf50606_reset_timeout(); } if (data[2] & 0x08) { /* Touchscreen event, do something about it */ touchscreen_handle_device_irq(); } } else { unsigned char data[5]; /* 0 = INT1, 1 = INT2, 2 = INT3, ... 4 = INT5 */ /* Clear pending interrupts from pcf50635 */ pcf50635_read_multiple(PCF5063X_REG_INT1, data, 5); if (data[2] & PCF5063X_INT3_ONKEY1S) { if (!charger_inserted()) sys_poweroff(); } } }
void sdl_sys_quit(void) { quitting = true; sys_poweroff(); }
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; }
static bool event_handler(SDL_Event *event) { SDLKey ev_key; switch(event->type) { case SDL_ACTIVEEVENT: if (event->active.state & SDL_APPINPUTFOCUS) { if (event->active.gain == 1) sdl_app_has_input_focus = 1; else sdl_app_has_input_focus = 0; } break; case SDL_KEYDOWN: case SDL_KEYUP: ev_key = event->key.keysym.sym; #if (CONFIG_PLATFORM & PLATFORM_MAEMO5) /* N900 with shared up/down cursor mapping. Seen on the German, Finnish, Italian, French and Russian version. Probably more. */ if (event->key.keysym.mod & KMOD_MODE || n900_updown_key_pressed) { /* Prevent stuck up/down keys: If you release the ALT key before the cursor key, rockbox will see a KEYUP event for left/right instead of up/down and the previously pressed up/down key would stay active. */ if (ev_key == SDLK_LEFT || ev_key == SDLK_RIGHT) { if (event->type == SDL_KEYDOWN) n900_updown_key_pressed = 1; else n900_updown_key_pressed = 0; } if (ev_key == SDLK_LEFT) ev_key = SDLK_UP; else if (ev_key == SDLK_RIGHT) ev_key = SDLK_DOWN; } #endif button_event(ev_key, event->type == SDL_KEYDOWN); break; #ifdef HAVE_TOUCHSCREEN case SDL_MOUSEMOTION: if (event->motion.state & SDL_BUTTON(1)) { int x = event->motion.x / display_zoom; int y = event->motion.y / display_zoom; touchscreen_event(x, y); } break; #endif case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONDOWN: { SDL_MouseButtonEvent *mev = &event->button; mev->x /= display_zoom; mev->y /= display_zoom; mouse_event(mev, event->type == SDL_MOUSEBUTTONUP); break; } case SDL_QUIT: /* Will post SDL_USEREVENT in shutdown_hw() if successful. */ sys_poweroff(); break; case SDL_USEREVENT: return true; break; } return false; }
int do_shortcut_menu(void *ignored) { (void)ignored; struct simplelist_info list; struct shortcut *sc; int done = GO_TO_PREVIOUS; if (first_handle == 0) shortcuts_init(); simplelist_info_init(&list, P2STR(ID2P(LANG_SHORTCUTS)), shortcut_count, NULL); list.get_name = shortcut_menu_get_name; list.action_callback = shortcut_menu_get_action; if (global_settings.show_icons) list.get_icon = shortcut_menu_get_icon; list.title_icon = Icon_Bookmark; if (global_settings.talk_menu) list.get_talk = shortcut_menu_speak_item; push_current_activity(ACTIVITY_SHORTCUTSMENU); while (done == GO_TO_PREVIOUS) { if (simplelist_show_list(&list)) break; /* some error happened?! */ if (list.selection == -1) break; else { sc = get_shortcut(list.selection); if (!sc) continue; switch (sc->type) { case SHORTCUT_PLAYLISTMENU: if (!file_exists(sc->u.path)) { splash(HZ, ID2P(LANG_NO_FILES)); break; } else { onplay_show_playlist_menu(sc->u.path); } break; case SHORTCUT_FILE: if (!file_exists(sc->u.path)) { splash(HZ, ID2P(LANG_NO_FILES)); break; } /* else fall through */ case SHORTCUT_BROWSER: { struct browse_context browse; browse_context_init(&browse, global_settings.dirfilter, 0, NULL, NOICON, sc->u.path, NULL); if (sc->type == SHORTCUT_FILE) browse.flags |= BROWSE_RUNFILE; done = rockbox_browse(&browse); } break; case SHORTCUT_SETTING: do_setting_screen(sc->u.setting, sc->name[0] ? sc->name : P2STR(ID2P(sc->u.setting->lang_id)),NULL); break; case SHORTCUT_DEBUGITEM: run_debug_screen(sc->u.path); break; case SHORTCUT_SHUTDOWN: #if CONFIG_CHARGING if (charger_inserted()) charging_splash(); else #endif sys_poweroff(); break; case SHORTCUT_TIME: #if CONFIG_RTC if (sc->u.timedata.talktime) { talk_timedate(); talk_force_enqueue_next(); } else #endif { char timer_buf[10]; set_sleep_timer(sc->u.timedata.sleep_timeout * 60); splashf(HZ, "%s (%s)", str(LANG_SLEEP_TIMER), sleep_timer_formatter(timer_buf, sizeof(timer_buf), sc->u.timedata.sleep_timeout, NULL)); } break; case SHORTCUT_UNDEFINED: default: break; } } } pop_current_activity(); return done; }