Ejemplo n.º 1
0
        //Update the battery information
        void UpdateBatteryInformation(IHardware hardwareItem)
        {
            try
            {
                //Check if the information is visible
                bool showPercentage = Convert.ToBoolean(Setting_Load(vConfigurationFpsOverlayer, "BatShowPercentage"));
                if (!showPercentage)
                {
                    AVActions.ActionDispatcherInvoke(delegate
                    {
                        stackpanel_CurrentBat.Visibility = Visibility.Collapsed;
                    });
                    return;
                }

                if (hardwareItem.HardwareType == HardwareType.Battery)
                {
                    hardwareItem.Update();
                    string BatteryPercentage = string.Empty;
                    string BatteryStatus     = string.Empty;

                    foreach (ISensor sensor in hardwareItem.Sensors)
                    {
                        try
                        {
                            if (sensor.SensorType == SensorType.Level)
                            {
                                if (sensor.Name == "Charge Level")
                                {
                                    //Debug.WriteLine("Bat Level: " + sensor.Name + "/" + sensor.Identifier + "/" + sensor.Value.ToString());
                                    BatteryPercentage = " " + Convert.ToInt32(sensor.Value) + "%";
                                }
                            }
                            else if (sensor.SensorType == SensorType.Power)
                            {
                                if (sensor.Name == "Charge Rate")
                                {
                                    //Debug.WriteLine("Bat Charge Rate: " + sensor.Name + "/" + sensor.Identifier + "/" + sensor.Value.ToString());
                                    BatteryStatus = " (Charging)";
                                }
                            }
                            else if (sensor.SensorType == SensorType.TimeSpan)
                            {
                                //Debug.WriteLine("Bat Estimated Time: " + sensor.Name + "/" + sensor.Identifier + "/" + sensor.Value.ToString());
                                BatteryStatus = " (" + AVFunctions.SecondsToHms(Convert.ToInt32(sensor.Value), true) + ")";
                            }
                        }
                        catch { }
                    }

                    if (!string.IsNullOrWhiteSpace(BatteryPercentage) || !string.IsNullOrWhiteSpace(BatteryStatus))
                    {
                        string stringDisplay = AVFunctions.StringRemoveStart(vTitleBAT + BatteryPercentage + BatteryStatus, " ");
                        AVActions.ActionDispatcherInvoke(delegate
                        {
                            textblock_CurrentBat.Text        = stringDisplay;
                            stackpanel_CurrentBat.Visibility = Visibility.Visible;
                        });
                    }
                    else
                    {
                        AVActions.ActionDispatcherInvoke(delegate
                        {
                            stackpanel_CurrentBat.Visibility = Visibility.Collapsed;
                        });
                    }
                }
            }
            catch { }
        }