static int handle_usb_events(void) { #if (CONFIG_STORAGE & STORAGE_MMC) int next_update=0; #endif /* STORAGE_MMC */ /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */ while(1) { int button; #ifdef USB_ENABLE_HID if (usb_hid) { button = get_hid_usb_action(); /* On mode change, we need to refresh the screen */ if (button == ACTION_USB_HID_MODE_SWITCH_NEXT || button == ACTION_USB_HID_MODE_SWITCH_PREV) { break; } } else #endif { button = button_get_w_tmo(HZ/2); /* hid emits the event in get_action */ send_event(GUI_EVENT_ACTIONUPDATE, NULL); } switch(button) { case SYS_USB_DISCONNECTED: usb_acknowledge(SYS_USB_DISCONNECTED_ACK); return 1; case SYS_CHARGER_DISCONNECTED: /*reset rockbox battery runtime*/ global_status.runtime = 0; break; case SYS_TIMEOUT: break; } #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */ if(TIME_AFTER(current_tick,next_update)) { if(usb_inserted()) { led(mmc_usb_active(HZ)); } next_update=current_tick+HZ/2; } #endif /* STORAGE_MMC */ } 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 gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw, struct viewport *vp) { struct screen * display = bar->display; if (!display) return; #ifdef HAVE_LCD_CHARCELLS int val; (void)force_redraw; /* The Player always has "redraw" */ (void)vp; #endif /* HAVE_LCD_CHARCELLS */ bar->info.battlevel = battery_level(); #ifdef HAVE_USB_POWER bar->info.usb_inserted = usb_inserted(); #endif #if CONFIG_CHARGING bar->info.inserted = (charger_input_state == CHARGER); if (bar->info.inserted) { bar->info.battery_state = true; #if CONFIG_CHARGING >= CHARGING_MONITOR /* zero battery run time if charging */ if (charge_state > DISCHARGING) lasttime = current_tick; /* animate battery if charging */ if ((charge_state == DISCHARGING) || (charge_state == TRICKLE)) { bar->info.batt_charge_step = -1; } else { #else /* CONFIG_CHARGING < CHARGING_MONITOR */ lasttime = current_tick; { #endif /* CONFIG_CHARGING < CHARGING_MONITOR */ /* animate in (max.) 4 steps, starting near the current charge level */ if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick)) { if (++bar->info.batt_charge_step > 3) bar->info.batt_charge_step = bar->info.battlevel / 34; bar->battery_icon_switch_tick = current_tick + HZ; } } } else #endif /* CONFIG_CHARGING */ {
/* * Estimate how much current we are drawing just to run. */ static int runcurrent(void) { int current = CURRENT_NORMAL; #ifndef BOOTLOADER if (usb_inserted() #ifdef HAVE_USB_POWER #if (CURRENT_USB < CURRENT_NORMAL) || usb_powered() #else && !usb_powered() #endif #endif ) { current = CURRENT_USB; } #if defined(HAVE_BACKLIGHT) if (backlight_get_current_timeout() == 0) /* LED always on */ current += CURRENT_BACKLIGHT; #endif #if defined(HAVE_RECORDING) && defined(CURRENT_RECORD) if (audio_status() & AUDIO_STATUS_RECORD) current += CURRENT_RECORD; #endif #ifdef HAVE_SPDIF_POWER if (spdif_powered()) current += CURRENT_SPDIF_OUT; #endif #ifdef HAVE_REMOTE_LCD if (remote_detect()) current += CURRENT_REMOTE; #endif #if defined(HAVE_ATA_POWER_OFF) && defined(CURRENT_ATA) if (ide_powered()) current += CURRENT_ATA; #endif #endif /* BOOTLOADER */ return current; }