public void Initialize() { _batteryStatus = new BatteryStatus(); _batteryStatus.Start(); _batteryStatus.BatteryStatusUpdate += (s, bi) => { this.BatteryDetails.BatteryStatus = bi.ChargeStatus; this.BatteryDetails.ChargeDischargeRate = bi.DischargeRate; this.BatteryDetails.DesignCapacity = bi.DesignedMaxCapacity; this.BatteryDetails.FullCharge = bi.FullChargeCapacity; this.BatteryDetails.RemainingCapacity = (int)bi.CurrentCapacity; this.BatteryDetails.RemainingCapacityInPercent = bi.CurrentCapacityPercent; this.BatteryDetails.BatteryHealthInPercent = bi.BatteryHealthPercent; Chart.DischargeRateSeries.Values.Add(this.BatteryDetails.ChargeDischargeRate); Chart.RemainingCapacity.Values.Add(this.BatteryDetails.RemainingCapacity); if (Chart.DischargeRateSeries.Values.Count > 50) { Chart.MaxValue = Chart.DischargeRateSeries.Values.Count; } if (Chart.MaxValue > 200) { Chart.DischargeRateSeries.Values.RemoveAt(0); Chart.RemainingCapacity.Values.RemoveAt(0); } }; }
static void Main(string[] args) { BatteryStatus bs = new BatteryStatus(); bs.BatteryStatusUpdate += (s, bi) => { Console.Clear(); Console.WriteLine(nameof(bi.CurrentCapacity) + ", " + bi.CurrentCapacity); Console.WriteLine(nameof(bi.DesignedMaxCapacity) + ", " + bi.DesignedMaxCapacity); Console.WriteLine(nameof(bi.FullChargeCapacity) + ", " + bi.FullChargeCapacity); Console.WriteLine(nameof(bi.Voltage) + ", " + bi.Voltage); Console.WriteLine(nameof(bi.DischargeRate) + ", " + bi.DischargeRate); Console.WriteLine(nameof(bi.CurrentCapacityPercent) + ", " + bi.CurrentCapacityPercent); Console.WriteLine(nameof(bi.BatteryHealthPercent) + ", " + bi.BatteryHealthPercent); Console.WriteLine(nameof(bi.ChargeStatus) + ", " + bi.ChargeStatus); }; bs.Start(); Console.ReadLine(); }