@@ -13,6 +13,7 @@ internal sealed class Battery : Hardware
1313 private readonly uint _batteryTag ;
1414 private readonly Sensor _chargeDischargeCurrent ;
1515 private readonly Sensor _chargeDischargeRate ;
16+ private readonly Sensor _cycleCount ;
1617 private readonly Sensor _chargeLevel ;
1718 private readonly Sensor _degradationLevel ;
1819 private readonly Sensor _designedCapacity ;
@@ -103,6 +104,13 @@ public Battery
103104 ActivateSensor ( _fullChargedCapacity ) ;
104105 ActivateSensor ( _degradationLevel ) ;
105106 }
107+
108+ _cycleCount = new Sensor ( "Charge-Discharge Cycle Count" , 0 , SensorType . IntFactor , this , settings ) ;
109+ if ( batteryInfo . CycleCount > 0 )
110+ {
111+ _cycleCount . Value = batteryInfo . CycleCount ;
112+ ActivateSensor ( _cycleCount ) ;
113+ }
106114 }
107115
108116 public float ? ChargeDischargeCurrent { get ; private set ; }
@@ -245,13 +253,32 @@ public override void Update()
245253 _temperature . Value = null ;
246254 }
247255
256+ bqi . InformationLevel = Kernel32 . BATTERY_QUERY_INFORMATION_LEVEL . BatteryInformation ;
257+ Kernel32 . BATTERY_INFORMATION bi = default ;
258+ if ( Kernel32 . DeviceIoControl ( _batteryHandle ,
259+ Kernel32 . IOCTL . IOCTL_BATTERY_QUERY_INFORMATION ,
260+ ref bqi ,
261+ Marshal . SizeOf ( bqi ) ,
262+ ref bi ,
263+ Marshal . SizeOf ( bi ) ,
264+ out _ ,
265+ IntPtr . Zero ) )
266+ {
267+ _cycleCount . Value = bi . CycleCount ;
268+ }
269+ else
270+ {
271+ _cycleCount . Value = null ;
272+ }
273+
248274 ActivateSensorIfValueNotNull ( _remainingCapacity ) ;
249275 ActivateSensorIfValueNotNull ( _chargeLevel ) ;
250276 ActivateSensorIfValueNotNull ( _voltage ) ;
251277 ActivateSensorIfValueNotNull ( _chargeDischargeCurrent ) ;
252278 ActivateSensorIfValueNotNull ( _chargeDischargeRate ) ;
253279 ActivateSensorIfValueNotNull ( _remainingTime ) ;
254280 ActivateSensorIfValueNotNull ( _temperature ) ;
281+ ActivateSensorIfValueNotNull ( _cycleCount ) ;
255282 }
256283
257284 public override void Close ( )
0 commit comments