int get_charging_current(void) { int temp_bat_sen=0; int temp_i_sen=0; int temp_charging_current=0; temp_bat_sen = get_ADC_channel(ADC_BAT_SEN, ADC_COUNT); temp_bat_sen = (temp_bat_sen/ADC_COUNT); temp_i_sen = get_ADC_channel(ADC_I_SEN, ADC_COUNT); temp_i_sen = (temp_i_sen/ADC_COUNT); if(temp_i_sen > temp_bat_sen) { #ifdef FEATURE_FTM_SWCHR_I_68mohm temp_charging_current = ((temp_i_sen-temp_bat_sen)*1000)/68; #else temp_charging_current = ((temp_i_sen-temp_bat_sen)*10)/2; #endif } else temp_charging_current = 0; #ifdef FEATURE_FTM_HW_CANNOT_MEASURE_CURRENT temp_charging_current = 488; #endif return temp_charging_current; }
int get_v_bat_sen(void) { int temp=0; temp = get_ADC_channel(ADC_BAT_SEN, ADC_COUNT); temp = (temp/ADC_COUNT); return temp; }
int get_v_charger(void) { int temp=0; temp = get_ADC_channel(ADC_CHARGER, ADC_COUNT); temp = (temp/ADC_COUNT); return temp; }
int get_v_bat_temp(void) { int temp=0; temp = get_ADC_channel(ADC_BAT_TEMP, ADC_COUNT); temp = (temp/ADC_COUNT); return temp; }
int main() { int logFd; int battery_fg_current = 0; int bat_voltage = 0; char write_buf[50]; char write_buf_second[50]; int temp = -1; unsigned long long sum = 0; unsigned long long count = 0; unsigned long power = 0; //OPEN LOG FILE logFd = open(logFile, O_CREAT | O_RDWR, 0666); ALOGD("Read tart ...%s:[%d].\n", __func__, __LINE__); if(logFd == -1) { ALOGE("open TOUCH_FW_UPDATE_NODE failed reason = %s \n", strerror(errno)); return 0; } do{ //UPDATE I temp = get_ADC_channel(ADC_BAT_FG_CURRENT, ADC_COUNT); if (temp != -1) { battery_fg_current = temp; } else { battery_fg_current = -1; } //UPDATE V temp = get_ADC_channel(ADC_BAT_SEN, ADC_COUNT); if (temp != -1) { bat_voltage = (temp/ADC_COUNT); } else { bat_voltage = -1; } //WRITE TO LOGFILE memset(write_buf, 0, sizeof(write_buf)); memset(write_buf_second, 0, sizeof(write_buf_second)); ALOGD("%s:[%d]\n", __func__, __LINE__); sprintf(write_buf, "battery_fg_curren = %dmA, bat_voltage = %dmV\n", battery_fg_current, bat_voltage); if(write(logFd, write_buf, sizeof(write_buf)) == -1) { ALOGE("write fd errno \n"); return 0; } ALOGD("%s:[%d]:battery_fg_current = %dmA;bat_voltage = %dmV\n", __func__, __LINE__, battery_fg_current, bat_voltage); if (battery_fg_current > 0) { sum = sum + battery_fg_current * bat_voltage; count++; power = sum/count; sprintf(write_buf_second, "power = %dma.mv\n", power); ALOGD("power = %dma.mv\r\n", power); if(write(logFd, write_buf_second, sizeof(write_buf_second)) == -1) { ALOGE("write fd errno \n"); return 0; } } sync(); ALOGD("#####over2\n"); sleep(1); }while(1); close(logFd); return 0; }
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; }
static void battery_update_info(struct batteryFTM *batt, char *info) { char *ptr; int temp = 0; #ifdef FEATURE_FTM_PMIC_6329 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; } #ifdef MTK_NCP1851_SUPPORT batt->bat_voltage = get_BAT_vol(); batt->current_charging = get_FG_current(); #else temp = get_ADC_channel(ADC_BAT_SEN, ADC_COUNT); if (temp != -1) { batt->bat_voltage = (temp/ADC_COUNT); #ifdef FEATURE_FTM_PMIC_6329 batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(4*1200); #else batt->adc_vbat_current = ((batt->bat_voltage)*1024)/(2*2800); #endif } else { batt->bat_voltage = -1; batt->adc_vbat_current = -1; } temp = get_ADC_channel(ADC_I_SEN, ADC_COUNT); if (temp != -1) { temp = (temp/ADC_COUNT); /* I_sense */ if (batt->charger_exist) { batt->current_charging = ((temp-(batt->bat_voltage))*10)/2; } else { batt->current_charging = 0; } } else { batt->current_charging = -1; } #endif 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_6329 batt->bat_temperature = temp; #else if (temp != -1) { temp = (temp/ADC_COUNT); batt->bat_temperature = BattVoltToTemp(temp); } else { batt->bat_temperature = -101; } #endif #endif #ifdef FEATURE_FTM_PMIC_6329 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_6329 if( batt->adc_vbat_current > 0 ) { pmic_is_connect = true; } else { pmic_is_connect = false; } #endif /* preare text view info */ ptr = info; #ifndef MTK_NCP1851_SUPPORT ptr += sprintf(ptr, "BAT Cal. : %s\n", (batt->is_calibration) ? "YES" : "NO"); ptr += sprintf(ptr, "BAT Volt. : %d mV\n", batt->bat_voltage); ptr += sprintf(ptr, "BAT Temp. : %d Celsius\n", batt->bat_temperature); ptr += sprintf(ptr, "CHGR : %s\n", (batt->is_charging) ? "YES" : "NO"); ptr += sprintf(ptr, "CHGR Volt.: %d mV\n", batt->charger_voltage); ptr += sprintf(ptr, "CHGR Curr.: %d mA\n", batt->current_charging); ptr += sprintf(ptr, "AD32 : %d\n", batt->adc_vbat_3_2); ptr += sprintf(ptr, "AD42 : %d\n", batt->adc_vbat_4_2); ptr += sprintf(ptr, "CurAD : %d\n", batt->adc_vbat_current); #ifdef FEATURE_FTM_PMIC_6329 ptr += sprintf(ptr, "FG_Current: %dmA\n", battery_fg_current); ptr += sprintf(ptr, "PMIC Chip : %s\n", (pmic_is_connect) ? "Connect" : "NO connect"); #endif #else ptr += sprintf(ptr, "BAT Volt. : %d mV\n", batt->bat_voltage); ptr += sprintf(ptr, "BAT Temp. : %d Celsius\n", batt->bat_temperature); ptr += sprintf(ptr, "CHGR : %s\n", (batt->is_charging) ? "YES" : "NO"); ptr += sprintf(ptr, "CHGR Volt.: %d mV\n", batt->charger_voltage); #ifdef FEATURE_FTM_PMIC_6329 ptr += sprintf(ptr, "BAT Curr.: %dmA\n", battery_fg_current); #endif #endif return; }