@@ -275,10 +275,12 @@ CmBattUnload(IN PDRIVER_OBJECT DriverObject)
275275
276276NTSTATUS
277277NTAPI
278- CmBattVerifyStaticInfo (PCMBATT_DEVICE_EXTENSION DeviceExtension ,
279- ULONG BatteryTag )
278+ CmBattVerifyStaticInfo (
279+ _Inout_ PCMBATT_DEVICE_EXTENSION DeviceExtension ,
280+ _In_ ULONG BatteryTag )
280281{
281282 ACPI_BIF_DATA BifData ;
283+ ULONG DesignVoltage ;
282284 PBATTERY_INFORMATION Info = & DeviceExtension -> BatteryInformation ;
283285 NTSTATUS Status ;
284286
@@ -292,16 +294,73 @@ CmBattVerifyStaticInfo(PCMBATT_DEVICE_EXTENSION DeviceExtension,
292294 // FIXME: take from _BIX method: Info->CycleCount
293295 DeviceExtension -> BifData = BifData ;
294296
295- if (BifData .PowerUnit == 1 )
297+ /* Check if the power stats are reported in ampere or watts */
298+ if (BifData .PowerUnit == ACPI_BATT_POWER_UNIT_AMPS )
296299 {
297- DPRINT1 ("FIXME: need to convert mAh into mWh\n" );
298- Info -> DesignedCapacity = BATTERY_UNKNOWN_CAPACITY ;
299- Info -> FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY ;
300- Info -> DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY ;
301- Info -> DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY ;
300+ /*
301+ * We have got power stats in milli-ampere but ReactOS expects the values
302+ * to be reported in milli-watts, so we have to convert them.
303+ * In order to do so we must expect the design voltage of the battery
304+ * is not unknown.
305+ */
306+ DesignVoltage = DeviceExtension -> BifData .DesignVoltage ;
307+ if ((DesignVoltage != BATTERY_UNKNOWN_VOLTAGE ) && (DesignVoltage ))
308+ {
309+ /* Convert the design capacity */
310+ if (BifData .DesignCapacity != BATTERY_UNKNOWN_CAPACITY )
311+ {
312+ Info -> DesignedCapacity = CONVERT_MAH_TO_MWH (BifData .DesignCapacity , DesignVoltage );
313+ }
314+ else
315+ {
316+ Info -> DesignedCapacity = BATTERY_UNKNOWN_CAPACITY ;
317+ }
318+
319+ /* Convert the full charged capacity */
320+ if (BifData .LastFullCapacity != BATTERY_UNKNOWN_CAPACITY )
321+ {
322+ Info -> FullChargedCapacity = CONVERT_MAH_TO_MWH (BifData .LastFullCapacity , DesignVoltage );
323+ }
324+ else
325+ {
326+ Info -> FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY ;
327+ }
328+
329+ /* Convert the low capacity alarm (DefaultAlert1) */
330+ if (BifData .DesignCapacityLow != BATTERY_UNKNOWN_CAPACITY )
331+ {
332+ Info -> DefaultAlert1 = CONVERT_MAH_TO_MWH (BifData .DesignCapacityLow , DesignVoltage );
333+ }
334+ else
335+ {
336+ Info -> DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY ;
337+ }
338+
339+ /* Convert the designed capacity warning alarm (DefaultAlert2) */
340+ if (BifData .DesignCapacityWarning != BATTERY_UNKNOWN_CAPACITY )
341+ {
342+ Info -> DefaultAlert2 = CONVERT_MAH_TO_MWH (BifData .DesignCapacityWarning , DesignVoltage );
343+ }
344+ else
345+ {
346+ Info -> DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY ;
347+ }
348+ }
349+ else
350+ {
351+ /*
352+ * Without knowing the nominal designed voltage of the battery
353+ * we cannot determine the power consumption of this battery.
354+ */
355+ Info -> DesignedCapacity = BATTERY_UNKNOWN_CAPACITY ;
356+ Info -> FullChargedCapacity = BATTERY_UNKNOWN_CAPACITY ;
357+ Info -> DefaultAlert1 = BATTERY_UNKNOWN_CAPACITY ;
358+ Info -> DefaultAlert2 = BATTERY_UNKNOWN_CAPACITY ;
359+ }
302360 }
303361 else
304362 {
363+ /* The stats are in milli-watts, use them directly */
305364 Info -> DesignedCapacity = BifData .DesignCapacity ;
306365 Info -> FullChargedCapacity = BifData .LastFullCapacity ;
307366 Info -> DefaultAlert1 = BifData .DesignCapacityLow ;
@@ -582,8 +641,13 @@ CmBattQueryTag(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
582641 Status = CmBattGetStaData (PdoDevice , & StaData );
583642 if (NT_SUCCESS (Status ))
584643 {
585- /* Is a battery present? */
586- if (StaData & ACPI_STA_BATTERY_PRESENT )
644+ /*
645+ * Check if _STA method has returned us the battery state as being
646+ * present. On some machines the returned _STA element might be 0xF
647+ * which is still valid.
648+ */
649+ if ((StaData & ACPI_STA_BATTERY_PRESENT ) ||
650+ (StaData & ACPI_STA_BATTERY_PRESENT_V2 ))
587651 {
588652 /* Do we not have a tag yet? */
589653 if (DeviceExtension -> Tag == BATTERY_TAG_INVALID )
@@ -939,7 +1003,7 @@ CmBattGetBatteryStatus(IN PCMBATT_DEVICE_EXTENSION DeviceExtension,
9391003 }
9401004 }
9411005 }
942- else if ((DesignVoltage != CM_UNKNOWN_VALUE ) && (DesignVoltage ))
1006+ else if ((DesignVoltage != CM_UNKNOWN_VALUE ) && (DesignVoltage )) // Same as doing DeviceExtension->BifData.PowerUnit == ACPI_BATT_POWER_UNIT_AMPS
9431007 {
9441008 /* We have voltage data, what about capacity? */
9451009 if (RemainingCapacity == CM_UNKNOWN_VALUE )
0 commit comments