📄 battdrvr.cpp
字号:
Init_check = TRUE;
}
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDPowerHandler\r\n")));
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDGetStatus
//
// This routine obtains the most current battery/power status available on the platform. It fills
// in the structures pointed to by its parameters
//
// Parameters:
// pstatus
// [in] pointer to the battery status structure
// pfBatteriesChangedSinceLastCall
// [in] Pointer to a flag that the function sets to TRUE if the user replaced or changed
// the system's batteries since the last call to this function.
//
// Returns:
// TRUE if success FALSE if error
//
//-----------------------------------------------------------------------------
BOOL WINAPI BatteryPDDGetStatus(PSYSTEM_POWER_STATUS_EX2 pstatus, PBOOL pfBatteriesChangedSinceLastCall)
{
DWORD capacity_delta;
DWORD t_delta;
BATT_INFO BattInfo; // batt information structure obtained from bsp layer
DWORD batt_V;
DWORD charger_V;
BOOL fCharge;
DWORD current;
DEBUGMSG(ZONE_FUNCTION, (TEXT("BatteryPDDGetStatus\r\n")));
//Get Info from BSP layer
if(BSPBattdrvrGetInfo(&BattInfo) != TRUE)
{
ERRORMSG(TRUE, (TEXT("BSPBattdrvrGetInfo fail !!\r\n")));
return FALSE;
}
if(BSPBattdrvrGetParameters(&batt_V, &charger_V, &fCharge, ¤t) != TRUE)
{
ERRORMSG(TRUE, (TEXT("BSPBattdrvrGetParameters fail !!\r\n")));
pstatus->ACLineStatus = AC_LINE_UNKNOWN;
pstatus->BatteryFlag = BATTERY_FLAG_UNKNOWN;
return FALSE;
}
#if FAKE_CHARGER
pstatus->ACLineStatus = AC_LINE_ONLINE;
capacity = Batt_FullCapacity*C_HR_TO_SEC; //in mAsec
#else
// update the ACLineStatus according to charger threshold voltage
if (charger_V < BattInfo.charger_V_limit)
pstatus->ACLineStatus = AC_LINE_OFFLINE;
else
pstatus->ACLineStatus = AC_LINE_ONLINE;
#endif
// determine whether battery is available according to the min batt voltage from batt spec
if (batt_V <= Batt_MinVoltage)
{
DEBUGMSG(ZONE_BATTERY, (TEXT("No Battery!!!\r\n")));
// update the SYSTEM_POWER_STATUS_EX2 structure
pstatus->BatteryFlag = BATTERY_FLAG_NO_BATTERY;
pstatus->BatteryLifePercent = 0;
pstatus->Reserved1 = 0;
pstatus->BatteryLifeTime = 0;
pstatus->BatteryFullLifeTime = 0;
pstatus->Reserved2 = 0;
pstatus->BackupBatteryFlag = BATTERY_FLAG_UNKNOWN;
pstatus->BackupBatteryLifePercent = 0;
pstatus->Reserved3 = 0;
pstatus->BackupBatteryLifeTime = BATTERY_LIFE_UNKNOWN;
pstatus->BackupBatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
pstatus->BatteryChemistry = BATTERY_CHEMISTRY_UNKNOWN;
pstatus->BatteryVoltage = 0;
pstatus->BatteryCurrent = 0;
pstatus->BatteryAverageCurrent = 0;
pstatus->BatteryAverageInterval = 0;
pstatus->BatterymAHourConsumed = 0;
pstatus->BatteryTemperature = 0;
pstatus->BackupBatteryVoltage = 0;
*pfBatteriesChangedSinceLastCall = FALSE;
// force the init check for next MDD call
Init_check = TRUE;
goto END;
}
else
{
if (Init_check == TRUE)
{
DEBUGMSG(ZONE_BATTERY, (TEXT("Initial Check!!! \r\n")));
// in inti_check, we use batt terminal voltage to determine the init capacity of the battery
percentage =
100*(batt_V - BattInfo.adc_batt_min_V)/(BattInfo.adc_batt_max_V - BattInfo.adc_batt_min_V);
capacity = Batt_FullCapacity*C_HR_TO_SEC/100* percentage; //in mAsec
DEBUGMSG(ZONE_BATTERY, (TEXT("capacity = %d percentage = %d\r\n"), capacity, percentage));
t1 = timeGetTime(); // updating the start time stamp
// no need to perform the init check for the next MDD call
Init_check = FALSE;
}
else
{
t2 = timeGetTime(); // updating the stop time stamp
//determine the time seperation from last call
if(t2 > t1)
t_delta = t2 - t1;
else
t_delta = ~(t1-1) + t2;
DEBUGMSG(ZONE_BATTERY, (TEXT("t_delta = %d\r\n"), t_delta));
if (fCharge) //charging
{
DEBUGMSG(ZONE_BATTERY, (TEXT("Charging!!!\r\n")));
// apply the charging equation to callculate the changing capacity during charging
capacity_delta = CalChargingCapacityChange(current, Batt_ChargeEff, t_delta);
capacity += capacity_delta;
percentage = 100*capacity / (Batt_FullCapacity*C_HR_TO_SEC);
if (percentage > 100)
{
percentage = 100;
capacity = Batt_FullCapacity*C_HR_TO_SEC*C_S_TO_MS;
}
DEBUGMSG(ZONE_BATTERY, (TEXT("capacity_delta = %d capacity = %d percentage = %d\r\n"), capacity_delta, capacity, percentage));
}
else //discharging
{
DEBUGMSG(ZONE_BATTERY, (TEXT("Discharging!!!\r\n")));
capacity_delta = CalDischargingCapacityChange(current, Batt_PeukertNumber, t_delta);
if (capacity_delta >= capacity)
{
percentage = 0;
capacity = 0;
}
else
{
capacity -= capacity_delta;
percentage = 100*capacity / (Batt_FullCapacity*C_HR_TO_SEC);
}
DEBUGMSG(ZONE_BATTERY, (TEXT("capacity_delta = %d capacity = %d percentage = %d\r\n"), capacity_delta, capacity, percentage));
}
// update the begining time stamp
t1 = t2;
}
}
// Level Indicator
if(percentage >= LIMIT_HIGH)
pstatus->BatteryFlag = BATTERY_FLAG_HIGH;
else if (( percentage <LIMIT_HIGH) && (percentage >=LIMIT_LOW))
pstatus->BatteryFlag = BATTERY_FLAG_LOW;
else if(percentage<=LIMIT_LOW)
pstatus->BatteryFlag = BATTERY_FLAG_CRITICAL;
if (fCharge) //charging
pstatus->BatteryFlag = BATTERY_FLAG_CHARGING;
// update the SYSTEM_POWER_STATUS_EX2 structure
pstatus->BatteryLifePercent = (BYTE)percentage;
pstatus->Reserved1 = 0;
pstatus->BatteryLifeTime = (DWORD) (percentage*Batt_FullLifeTime);
pstatus->BatteryFullLifeTime = Batt_FullLifeTime*C_HR_TO_SEC;
pstatus->Reserved2 = 0;
pstatus->BackupBatteryFlag = BATTERY_FLAG_UNKNOWN;
pstatus->BackupBatteryLifePercent = 0;
pstatus->Reserved3 = 0;
pstatus->BackupBatteryLifeTime = BATTERY_LIFE_UNKNOWN;
pstatus->BackupBatteryFullLifeTime = BATTERY_LIFE_UNKNOWN;
pstatus->BatteryChemistry = BATTERY_CHEMISTRY_LION;
pstatus->BatteryVoltage = batt_V;
pstatus->BatteryCurrent = 0;
pstatus->BatteryAverageCurrent = 0;
pstatus->BatteryAverageInterval = 0;
pstatus->BatterymAHourConsumed = 0;
pstatus->BatteryTemperature = 0;
pstatus->BackupBatteryVoltage = 0;
*pfBatteriesChangedSinceLastCall = FALSE;
END:
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDGetLevels
//
// This routine indicates how many battery levels will be reported
// in the BatteryFlag and BackupBatteryFlag fields of the PSYSTEM_POWER_STATUS_EX2
// filed in by BatteryPDDGetStatus(). This number ranges from 0 through 3 --
// see the Platform Builder documentation for details. The main battery
// level count is reported in the low word of the return value; the count
// for the backup battery is in the high word.
//
// Parameters:
// void
//
// Returns:
// Number of battery levels
//
//-----------------------------------------------------------------------------
long BatteryPDDGetLevels(void)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDGetLevels\r\n")));
LONG lLevels = MAKELONG (3 /* main battery levels */,
3 /* backup battery levels */);
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDGetLevels\r\n")));
return lLevels;
}
//-----------------------------------------------------------------------------
//
// Function: BatteryPDDSupportsChangeNotification
//
// This routine returns TRUE to indicate that the pfBatteriesChangedSinceLastCall
// value filled in by BatteryPDDGetStatus() is valid. If there is no way to
// tell that the platform's batteries have been changed this routine should
// return FALSE.
//
// Parameters:
// void
//
// Returns:
// false
//
//-----------------------------------------------------------------------------
BOOL BatteryPDDSupportsChangeNotification(void)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+BatteryPDDSupportsChangeNotification\r\n")));
BOOL fSupportsChange = FALSE;
DEBUGMSG(ZONE_FUNCTION, (TEXT("-BatteryPDDSupportsChangeNotification\r\n")));
return fSupportsChange;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -