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; 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); pthread_create(&batt->batt_update_thd, NULL, battery_update_iv_thread, priv); do { chosen = iv->run(iv, &exit); switch (chosen) { #ifndef MTK_NCP1851_SUPPORT case ITEM_AC_CHARGER: set_Charger_Current(AC_CHARGER_CURRENT); break; case ITEM_USB_CHARGER: set_Charger_Current(USB_CHARGER_CURRENT); break; #endif 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 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; }