bool charging_state(void) { const unsigned short charged_thres = 4170; bool ret = (power_input_status() == POWER_INPUT_MAIN_CHARGER); /* dont indicate for > ~95% */ return ret && (_battery_voltage() <= charged_thres); }
bool dbg_hw_info_adc(void) { lcd_setfont(FONT_SYSFIXED); while(1) { int button = get_action(CONTEXT_STD, HZ / 25); switch(button) { case ACTION_STD_NEXT: case ACTION_STD_PREV: case ACTION_STD_OK: case ACTION_STD_MENU: lcd_setfont(FONT_UI); return true; case ACTION_STD_CANCEL: lcd_setfont(FONT_UI); return false; } lcd_clear_display(); /* add battery readout in mV, this it is not the direct output of a channel */ lcd_putsf(0, 0, "Battery(mV) %d", _battery_voltage()); for(unsigned i = 0; i < NUM_ADC_CHANNELS; i++) { lcd_putsf(0, i + 1, "%s %d", imx233_adc_channel_name[i], adc_read(i)); } lcd_update(); yield(); } }
static void average_step(void) { avgbat += _battery_voltage() - avgbat / BATT_AVE_SAMPLES; /* * battery_millivolts is the millivolt-scaled filtered battery value. */ battery_millivolts = avgbat / BATT_AVE_SAMPLES; }
void battery_read_info(int *voltage, int *level) { int millivolts = _battery_voltage(); int percent; if (voltage) *voltage = millivolts; if (level) { percent = voltage_to_battery_level(millivolts); if (percent < 0) percent = _battery_level(); *level = percent; } }
static void average_init(void) { /* initialize the voltages for the exponential filter */ avgbat = _battery_voltage() + 15; #ifdef HAVE_DISK_STORAGE /* this adjustment is only needed for HD based */ /* The battery voltage is usually a little lower directly after turning on, because the disk was used heavily. Raise it by 5% */ #if CONFIG_CHARGING if (!charger_inserted()) /* only if charger not connected */ #endif { avgbat += (percent_to_volt_discharge[battery_type][6] - percent_to_volt_discharge[battery_type][5]) / 2; } #endif /* HAVE_DISK_STORAGE */ avgbat = avgbat * BATT_AVE_SAMPLES; battery_millivolts = power_history[0] = avgbat / BATT_AVE_SAMPLES; }
static void power_thread(void) { long next_power_hist; /* Delay reading the first battery level */ #ifdef MROBE_100 while (_battery_voltage() > 4200) /* gives false readings initially */ #elif defined(DX50) || defined(DX90) while (_battery_voltage() < 1) /* can give false readings initially */ #endif { sleep(HZ/100); } #if CONFIG_CHARGING /* Initialize power input status before calling other routines. */ power_thread_inputs = power_input_status(); #endif /* initialize voltage averaging (if available) */ average_init(); /* get initial battery level value (in %) */ init_battery_percent(); /* get some initial data for the power curve */ collect_power_history(); /* call target specific init now */ powermgmt_init_target(); next_power_hist = current_tick + HZ*60; while (1) { #if CONFIG_CHARGING unsigned int pwr = power_input_status(); #ifdef HAVE_BATTERY_SWITCH if ((pwr ^ power_thread_inputs) & POWER_INPUT_BATTERY) { sleep(HZ/10); reset_battery_filter(_battery_voltage()); } #endif power_thread_inputs = pwr; if (!detect_charger(pwr)) #endif /* CONFIG_CHARGING */ { /* Steady state */ sleep(POWER_THREAD_STEP_TICKS); /* Do common power tasks */ power_thread_step(); } /* Perform target tasks */ charging_algorithm_step(); /* check if some idle or sleep timer wears off */ handle_auto_poweroff(); if (TIME_AFTER(current_tick, next_power_hist)) { /* increment to ensure there is a record for every minute * rather than go forward from the current tick */ next_power_hist += HZ*60; collect_power_history(); } } } /* power_thread */
static void average_step_low(void) { battery_millivolts = (_battery_voltage() + battery_millivolts + 1) / 2; avgbat += battery_millivolts - avgbat / BATT_AVE_SAMPLES; }