static void battery_update_info(struct batteryFTM *batt, char *info) { char *ptr; int temp = 0; #ifdef FEATURE_FTM_PMIC_632X int battery_fg_current = 0; bool pmic_is_connect = 0; #endif temp = get_ADC_channel(ADC_CHARGER, ADC_COUNT); if (temp != -1) { batt->charger_voltage = (temp/ADC_COUNT); /* Charger_Voltage */ if ( batt->charger_voltage >= 4100 ) { batt->charger_exist = true; batt->is_charging = true; } else { batt->charger_voltage = 0; batt->charger_exist = false; batt->is_charging = false; } } else { batt->charger_voltage = -1; batt->charger_exist = false; batt->is_charging = false; } //batt->bat_voltage = get_BAT_vol(); batt->bat_voltage = get_v_bat_sen(); if (batt->bat_voltage != -1) { #ifdef FEATURE_FTM_PMIC_632X batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(4*1200); #else batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(2*2800); #endif } else { batt->adc_vbat_current = -1; } //batt->current_charging = get_FG_current(); batt->current_charging = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); temp = get_BAT_status(); if (temp != -1) { batt->is_calibration = (temp==1) ? true : false; } else { batt->is_calibration = false; } batt->bat_temperature = 25; #ifdef BATTERY_TYPE_B61UN temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_BLP509 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -100; } #endif #ifdef BATTERY_TYPE_Z3 temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); #ifdef FEATURE_FTM_PMIC_632X batt->bat_temperature = temp/ADC_COUNT; #else if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -101; } #endif #endif #ifdef FEATURE_FTM_PMIC_632X temp = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); if (temp != -1) { battery_fg_current = temp; } else { battery_fg_current = -1; } #endif #ifdef FEATURE_FTM_PMIC_632X if( batt->adc_vbat_current > 0 ) { pmic_is_connect = true; } else { pmic_is_connect = false; } #endif /* preare text view info */ ptr = info; ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_val, batt->bat_voltage, uistr_info_title_battery_mv); ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_temp, batt->bat_temperature, uistr_info_title_battery_c); ptr += sprintf(ptr, "%s : %s \n", uistr_info_title_battery_chr, (batt->is_charging) ? uistr_info_title_battery_yes : uistr_info_title_battery_no); ptr += sprintf(ptr, "%s : %d %s \n", uistr_info_title_battery_chr_val, batt->charger_voltage, uistr_info_title_battery_mv); #ifdef FEATURE_FTM_PMIC_632X ptr += sprintf(ptr, "%s: %d %s \n", uistr_info_title_battery_fg_cur, battery_fg_current, uistr_info_title_battery_ma); ptr += sprintf(ptr, "%s : %s \n", uistr_info_title_battery_pmic_chip, (pmic_is_connect) ? uistr_info_title_battery_connect : uistr_info_title_battery_no_connect); #endif return; }
int battery_entry(struct ftm_param *param, void *priv) { char *ptr; int chosen; bool exit = false; struct batteryFTM *batt = (struct batteryFTM *)priv; struct textview *tv; struct itemview *iv; //auto test int temp_v_bat=0; int temp_v_chr=0; LOGD(TAG "%s\n", __FUNCTION__); if(FTM_AUTO_ITEM == param->test_type) { gBatteryAutoTest = 1; } else { gBatteryAutoTest = 0; } LOGD(TAG "AutoMode=%d, %s\n", gBatteryAutoTest, __FUNCTION__); init_text(&batt->title, param->name, COLOR_YELLOW); init_text(&batt->text, &batt->info[0], COLOR_YELLOW); init_text(&batt->left_btn, "Fail", COLOR_YELLOW); init_text(&batt->center_btn, "Pass", COLOR_YELLOW); init_text(&batt->right_btn, "Back", COLOR_YELLOW); battery_update_info(batt, batt->info); /* show text view */ batt->exit_thd = false; if (!batt->iv) { iv = ui_new_itemview(); if (!iv) { LOGD(TAG "No memory"); return -1; } batt->iv = iv; } iv = batt->iv; iv->set_title(iv, &batt->title); if (gBatteryAutoTest) { iv->set_items(iv, battery_items_auto, 0); } else { iv->set_items(iv, battery_items_manual, 0); } iv->set_text(iv, &batt->text); iv->start_menu(iv,0); if (gBatteryAutoTest) { iv->redraw(iv); return_data.battery.current = 0; return_data.battery.voltage = 0; //check charger voltage, if no charger, return fail temp_v_chr = get_v_charger(); if(temp_v_chr < AUTO_TEST_VCHR_VALUE) { LOGD(TAG "[FTM_BAT 0] %d < %d => no charger, return fail\n", temp_v_chr, AUTO_TEST_VCHR_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } //auto test - V_bat temp_v_bat = get_v_bat_sen(); return_data.battery.voltage = temp_v_bat; if(temp_v_bat < AUTO_TEST_VBAT_VALUE) { LOGD(TAG "[FTM_BAT 1] %d,%d,%d\n", temp_v_bat, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } if(temp_v_bat > AUTO_TEST_THD_VALUE) { LOGD(TAG "[FTM_BAT 2] %d,%d,%d\n", temp_v_bat, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } #ifdef FEATURE_FTM_VBAT_TEMP_CHECK //auto test - V bat temp temp_v_bat_temp = get_v_bat_temp(); if(temp_v_bat_temp < AUTO_TEST_VBAT_TEMP_MIN || temp_v_bat_temp > AUTO_TEST_VBAT_TEMP_MAX) { LOGD(TAG "[FTM_BAT 5] VBatTemp = %d , return fail\n", temp_v_chr); batt->mod->test_result = FTM_TEST_FAIL; return 0; } #endif batt->mod->test_result = FTM_TEST_PASS; return 0; } else { pthread_create(&batt->batt_update_thd, NULL, battery_update_iv_thread, priv); do { chosen = iv->run(iv, &exit); switch (chosen) { case ITEM_PASS: case ITEM_FAIL: if (chosen == ITEM_PASS) { batt->mod->test_result = FTM_TEST_PASS; } else if (chosen == ITEM_FAIL) { batt->mod->test_result = FTM_TEST_FAIL; } exit = true; break; } if (exit) { batt->exit_thd = true; break; } } while (1); pthread_join(batt->batt_update_thd, NULL); } return 0; }
int battery_entry(struct ftm_param *param, void *priv) { char *ptr; int chosen; bool exit = false; struct batteryFTM *batt = (struct batteryFTM *)priv; struct textview *tv; struct itemview *iv; //auto test int temp=0; int temp_v_bat=0; int temp_chr_cuttent=0; int temp_v_chr=0; int temp_v_bat_temp=0; unsigned long i=0; unsigned long i_loop_time=100; LOGD(TAG "%s\n", __FUNCTION__); init_text(&batt->title, param->name, COLOR_YELLOW); init_text(&batt->text, &batt->info[0], COLOR_YELLOW); init_text(&batt->left_btn, "Fail", COLOR_YELLOW); init_text(&batt->center_btn, "Pass", COLOR_YELLOW); init_text(&batt->right_btn, "Back", COLOR_YELLOW); battery_update_info(batt, batt->info); /* show text view */ batt->exit_thd = false; #if 0 pthread_create(&batt->batt_update_thd, NULL, battery_update_thread, priv); tv = &batt->tv; ui_init_textview(tv, battery_key_handler, (void*)batt); tv->set_title(tv, &batt->title); tv->set_text(tv, &batt->text); tv->set_btn(tv, &batt->left_btn, &batt->center_btn, &batt->right_btn); tv->run(tv); pthread_join(batt->batt_update_thd, NULL); #else if (!batt->iv) { iv = ui_new_itemview(); if (!iv) { LOGD(TAG "No memory"); return -1; } batt->iv = iv; } iv = batt->iv; iv->set_title(iv, &batt->title); iv->set_items(iv, battery_items, 0); iv->set_text(iv, &batt->text); iv->start_menu(iv,0); #if 1 iv->redraw(iv); return_data.battery.current = 0; return_data.battery.voltage = 0; //auto test - if no charger, return fail #ifdef FEATURE_FTM_VBAT_TEMP_CHECK //auto test - V bat temp temp_v_bat_temp = get_v_bat_temp(); if(temp_v_bat_temp < AUTO_TEST_VBAT_TEMP_MIN || temp_v_bat_temp > AUTO_TEST_VBAT_TEMP_MAX) { LOGD(TAG "[FTM_BAT 5] VBatTemp = %d , return fail\n", temp_v_chr); batt->mod->test_result = FTM_TEST_FAIL; return 0; } #endif temp_v_chr = get_v_charger(); if(temp_v_chr < AUTO_TEST_VCHR_VALUE) { LOGD(TAG "[FTM_BAT 0] %d < %d => no charger, return fail\n", temp_v_chr, AUTO_TEST_VCHR_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } //auto test - V_bat temp_v_bat = get_v_bat_sen(); return_data.battery.voltage = temp_v_bat; if(temp_v_bat < AUTO_TEST_VBAT_VALUE) { LOGD(TAG "[FTM_BAT 1] %d,%d,%d,%d,%d,%d,%d\n", temp_v_bat, temp_chr_cuttent, i, i_loop_time, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE, AUTO_TEST_CHR_CURRENT_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } if(temp_v_bat > AUTO_TEST_THD_VALUE) { LOGD(TAG "[FTM_BAT 2] %d,%d,%d,%d,%d,%d,%d\n", temp_v_bat, temp_chr_cuttent, i, i_loop_time, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE, AUTO_TEST_CHR_CURRENT_VALUE); //ignore I_charging test because the battery is full, no charging current batt->mod->test_result = FTM_TEST_PASS; return 0; } //auto test - I_charging for(i=0 ; i<i_loop_time ; i++) { temp_chr_cuttent = get_charging_current(); return_data.battery.current = temp_chr_cuttent; if(temp_chr_cuttent > AUTO_TEST_CHR_CURRENT_VALUE) break; } if(i >= i_loop_time) { LOGD(TAG "[FTM_BAT 3] %d,%d,%d,%d,%d,%d,%d\n", temp_v_bat, temp_chr_cuttent, i, i_loop_time, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE, AUTO_TEST_CHR_CURRENT_VALUE); batt->mod->test_result = FTM_TEST_FAIL; return 0; } else { LOGD(TAG "[FTM_BAT 4] %d,%d,%d,%d,%d,%d,%d\n", temp_v_bat, temp_chr_cuttent, i, i_loop_time, AUTO_TEST_VBAT_VALUE, AUTO_TEST_THD_VALUE, AUTO_TEST_CHR_CURRENT_VALUE); batt->mod->test_result = FTM_TEST_PASS; return 0; } #else pthread_create(&batt->batt_update_thd, NULL, battery_update_iv_thread, priv); do { chosen = iv->run(iv, &exit); switch (chosen) { case ITEM_AC_CHARGER: set_Charger_Current(AC_CHARGER_CURRENT); break; case ITEM_USB_CHARGER: set_Charger_Current(USB_CHARGER_CURRENT); break; case ITEM_PASS: case ITEM_FAIL: if (chosen == ITEM_PASS) { batt->mod->test_result = FTM_TEST_PASS; } else if (chosen == ITEM_FAIL) { batt->mod->test_result = FTM_TEST_FAIL; } exit = true; break; } if (exit) { batt->exit_thd = true; break; } } while (1); pthread_join(batt->batt_update_thd, NULL); #endif //do nothing #endif return 0; }