mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Added Battery Charge
This commit is contained in:
@@ -56,6 +56,7 @@ namespace GHelper
|
||||
break;
|
||||
case "fne":
|
||||
customActions[""] = "Calculator";
|
||||
customActions["ghelper"] = Properties.Strings.OpenGHelper;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,13 @@ public static class HardwareControl
|
||||
public static float? cpuTemp = -1;
|
||||
public static decimal? batteryRate = 0;
|
||||
public static decimal batteryHealth = -1;
|
||||
public static decimal batteryCapacity = -1;
|
||||
|
||||
public static decimal? designCapacity;
|
||||
public static decimal? fullCapacity;
|
||||
public static decimal? chargeCapacity;
|
||||
|
||||
|
||||
public static int? gpuTemp = null;
|
||||
|
||||
public static string? cpuFan;
|
||||
@@ -106,9 +111,12 @@ public static class HardwareControl
|
||||
}
|
||||
|
||||
|
||||
public static decimal GetBatteryRate()
|
||||
public static void GetBatteryStatus()
|
||||
{
|
||||
|
||||
batteryRate = 0;
|
||||
chargeCapacity = 0;
|
||||
|
||||
try
|
||||
{
|
||||
ManagementScope scope = new ManagementScope("root\\WMI");
|
||||
@@ -117,26 +125,29 @@ public static class HardwareControl
|
||||
using ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
|
||||
foreach (ManagementObject obj in searcher.Get().Cast<ManagementObject>())
|
||||
{
|
||||
|
||||
chargeCapacity = Convert.ToDecimal(obj["RemainingCapacity"]);
|
||||
|
||||
decimal chargeRate = Convert.ToDecimal(obj["ChargeRate"]);
|
||||
decimal dischargeRate = Convert.ToDecimal(obj["DischargeRate"]);
|
||||
|
||||
if (chargeRate > 0)
|
||||
return chargeRate;
|
||||
batteryRate = chargeRate / 1000;
|
||||
else
|
||||
return -dischargeRate;
|
||||
}
|
||||
batteryRate = -dischargeRate / 1000;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.WriteLine("Discharge Reading: " + ex.Message);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
public static void ReadFullChargeCapacity()
|
||||
{
|
||||
if (fullCapacity > 0) return;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -159,6 +170,8 @@ public static class HardwareControl
|
||||
|
||||
public static void ReadDesignCapacity()
|
||||
{
|
||||
if (designCapacity > 0) return;
|
||||
|
||||
try
|
||||
{
|
||||
ManagementScope scope = new ManagementScope("root\\WMI");
|
||||
@@ -253,7 +266,15 @@ public static class HardwareControl
|
||||
if (gpuTemp is null || gpuTemp < 0)
|
||||
gpuTemp = Program.acpi.DeviceGet(AsusACPI.Temp_GPU);
|
||||
|
||||
batteryRate = GetBatteryRate() / 1000;
|
||||
ReadFullChargeCapacity();
|
||||
GetBatteryStatus();
|
||||
|
||||
if (fullCapacity > 0 && chargeCapacity > 0)
|
||||
{
|
||||
batteryCapacity = Math.Min(100, ((decimal)chargeCapacity / (decimal)fullCapacity) * 100);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static bool IsUsedGPU(int threshold = 10)
|
||||
|
||||
@@ -520,7 +520,7 @@ namespace GHelper.Input
|
||||
break;
|
||||
case 107: // FN+F10
|
||||
AsusUSB.TouchpadToggle();
|
||||
Thread.Sleep(50);
|
||||
Thread.Sleep(200);
|
||||
Program.toast.RunToast(GetTouchpadState() ? "On" : "Off", ToastIcon.Touchpad);
|
||||
break;
|
||||
case 108: // FN+F11
|
||||
|
||||
15
app/Properties/Strings.Designer.cs
generated
15
app/Properties/Strings.Designer.cs
generated
@@ -429,6 +429,15 @@ namespace GHelper.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Charge.
|
||||
/// </summary>
|
||||
internal static string BatteryCharge {
|
||||
get {
|
||||
return ResourceManager.GetString("BatteryCharge", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Battery Charge Limit.
|
||||
/// </summary>
|
||||
@@ -437,7 +446,7 @@ namespace GHelper.Properties {
|
||||
return ResourceManager.GetString("BatteryChargeLimit", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Battery Health.
|
||||
/// </summary>
|
||||
@@ -1150,7 +1159,7 @@ namespace GHelper.Properties {
|
||||
return ResourceManager.GetString("NoNewUpdates", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Not Connected.
|
||||
/// </summary>
|
||||
@@ -1456,7 +1465,7 @@ namespace GHelper.Properties {
|
||||
return ResourceManager.GetString("ToggleAura", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Auto Toggle Clamshell Mode.
|
||||
/// </summary>
|
||||
|
||||
@@ -240,6 +240,9 @@
|
||||
<data name="Balanced" xml:space="preserve">
|
||||
<value>Balanced</value>
|
||||
</data>
|
||||
<data name="BatteryCharge" xml:space="preserve">
|
||||
<value>Charge</value>
|
||||
</data>
|
||||
<data name="BatteryChargeLimit" xml:space="preserve">
|
||||
<value>Battery Charge Limit</value>
|
||||
</data>
|
||||
|
||||
92
app/Settings.Designer.cs
generated
92
app/Settings.Designer.cs
generated
@@ -47,8 +47,9 @@ namespace GHelper
|
||||
labelBatteryTitle = new Label();
|
||||
panelFooter = new Panel();
|
||||
tableButtons = new TableLayoutPanel();
|
||||
buttonUpdates = new RButton();
|
||||
labelVersion = new Label();
|
||||
buttonQuit = new RButton();
|
||||
buttonUpdates = new RButton();
|
||||
checkStartup = new CheckBox();
|
||||
panelPerformance = new Panel();
|
||||
tablePerf = new TableLayoutPanel();
|
||||
@@ -95,8 +96,8 @@ namespace GHelper
|
||||
panelKeyboardTitle = new Panel();
|
||||
pictureKeyboard = new PictureBox();
|
||||
labelKeyboard = new Label();
|
||||
labelVersion = new Label();
|
||||
panelVersion = new Panel();
|
||||
labelCharge = new Label();
|
||||
panelPeripherals = new Panel();
|
||||
tableLayoutPeripherals = new TableLayoutPanel();
|
||||
buttonPeripheral3 = new RButton();
|
||||
@@ -365,8 +366,9 @@ namespace GHelper
|
||||
tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.3333321F));
|
||||
tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 33.3333321F));
|
||||
tableButtons.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 27F));
|
||||
tableButtons.Controls.Add(buttonUpdates, 0, 0);
|
||||
tableButtons.Controls.Add(labelVersion, 0, 0);
|
||||
tableButtons.Controls.Add(buttonQuit, 2, 0);
|
||||
tableButtons.Controls.Add(buttonUpdates, 1, 0);
|
||||
tableButtons.Dock = DockStyle.Top;
|
||||
tableButtons.Location = new Point(20, 20);
|
||||
tableButtons.Margin = new Padding(4);
|
||||
@@ -376,26 +378,20 @@ namespace GHelper
|
||||
tableButtons.Size = new Size(787, 60);
|
||||
tableButtons.TabIndex = 25;
|
||||
//
|
||||
// buttonUpdates
|
||||
// labelVersion
|
||||
//
|
||||
buttonUpdates.AccessibleName = "BIOS and Driver Updates";
|
||||
buttonUpdates.Activated = false;
|
||||
buttonUpdates.BackColor = SystemColors.ControlLight;
|
||||
buttonUpdates.BorderColor = Color.Transparent;
|
||||
buttonUpdates.BorderRadius = 2;
|
||||
buttonUpdates.Dock = DockStyle.Top;
|
||||
buttonUpdates.FlatStyle = FlatStyle.Flat;
|
||||
buttonUpdates.Image = Properties.Resources.icons8_software_32_white;
|
||||
buttonUpdates.ImageAlign = ContentAlignment.MiddleRight;
|
||||
buttonUpdates.Location = new Point(4, 6);
|
||||
buttonUpdates.Margin = new Padding(4, 6, 4, 6);
|
||||
buttonUpdates.Name = "buttonUpdates";
|
||||
buttonUpdates.Secondary = true;
|
||||
buttonUpdates.Size = new Size(254, 48);
|
||||
buttonUpdates.TabIndex = 24;
|
||||
buttonUpdates.Text = "Updates";
|
||||
buttonUpdates.TextImageRelation = TextImageRelation.ImageBeforeText;
|
||||
buttonUpdates.UseVisualStyleBackColor = false;
|
||||
labelVersion.Cursor = Cursors.Hand;
|
||||
labelVersion.Dock = DockStyle.Fill;
|
||||
labelVersion.Font = new Font("Segoe UI", 9F, FontStyle.Underline, GraphicsUnit.Point);
|
||||
labelVersion.ForeColor = SystemColors.ControlDark;
|
||||
labelVersion.Location = new Point(0, 0);
|
||||
labelVersion.Margin = new Padding(0);
|
||||
labelVersion.Name = "labelVersion";
|
||||
labelVersion.Padding = new Padding(5);
|
||||
labelVersion.Size = new Size(262, 60);
|
||||
labelVersion.TabIndex = 37;
|
||||
labelVersion.Text = "v.0";
|
||||
labelVersion.TextAlign = ContentAlignment.MiddleLeft;
|
||||
//
|
||||
// buttonQuit
|
||||
//
|
||||
@@ -418,6 +414,27 @@ namespace GHelper
|
||||
buttonQuit.TextImageRelation = TextImageRelation.ImageBeforeText;
|
||||
buttonQuit.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// buttonUpdates
|
||||
//
|
||||
buttonUpdates.AccessibleName = "BIOS and Driver Updates";
|
||||
buttonUpdates.Activated = false;
|
||||
buttonUpdates.BackColor = SystemColors.ControlLight;
|
||||
buttonUpdates.BorderColor = Color.Transparent;
|
||||
buttonUpdates.BorderRadius = 2;
|
||||
buttonUpdates.Dock = DockStyle.Top;
|
||||
buttonUpdates.FlatStyle = FlatStyle.Flat;
|
||||
buttonUpdates.Image = Properties.Resources.icons8_software_32_white;
|
||||
buttonUpdates.ImageAlign = ContentAlignment.MiddleRight;
|
||||
buttonUpdates.Location = new Point(266, 6);
|
||||
buttonUpdates.Margin = new Padding(4, 6, 4, 6);
|
||||
buttonUpdates.Name = "buttonUpdates";
|
||||
buttonUpdates.Secondary = true;
|
||||
buttonUpdates.Size = new Size(254, 48);
|
||||
buttonUpdates.TabIndex = 24;
|
||||
buttonUpdates.Text = "Updates";
|
||||
buttonUpdates.TextImageRelation = TextImageRelation.ImageBeforeText;
|
||||
buttonUpdates.UseVisualStyleBackColor = false;
|
||||
//
|
||||
// checkStartup
|
||||
//
|
||||
checkStartup.AutoSize = true;
|
||||
@@ -1169,23 +1186,9 @@ namespace GHelper
|
||||
labelKeyboard.TabIndex = 34;
|
||||
labelKeyboard.Text = "Laptop Keyboard";
|
||||
//
|
||||
// labelVersion
|
||||
//
|
||||
labelVersion.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
labelVersion.Cursor = Cursors.Hand;
|
||||
labelVersion.Font = new Font("Segoe UI", 9F, FontStyle.Underline, GraphicsUnit.Point);
|
||||
labelVersion.ForeColor = SystemColors.ControlDark;
|
||||
labelVersion.Location = new Point(502, 13);
|
||||
labelVersion.Margin = new Padding(11, 0, 11, 0);
|
||||
labelVersion.Name = "labelVersion";
|
||||
labelVersion.Size = new Size(300, 32);
|
||||
labelVersion.TabIndex = 37;
|
||||
labelVersion.Text = "v.0";
|
||||
labelVersion.TextAlign = ContentAlignment.TopRight;
|
||||
//
|
||||
// panelVersion
|
||||
//
|
||||
panelVersion.Controls.Add(labelVersion);
|
||||
panelVersion.Controls.Add(labelCharge);
|
||||
panelVersion.Controls.Add(checkStartup);
|
||||
panelVersion.Dock = DockStyle.Top;
|
||||
panelVersion.Location = new Point(11, 1379);
|
||||
@@ -1194,6 +1197,18 @@ namespace GHelper
|
||||
panelVersion.Size = new Size(827, 56);
|
||||
panelVersion.TabIndex = 6;
|
||||
//
|
||||
// labelCharge
|
||||
//
|
||||
labelCharge.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
labelCharge.ForeColor = SystemColors.ControlDark;
|
||||
labelCharge.Location = new Point(476, 10);
|
||||
labelCharge.Margin = new Padding(8, 0, 8, 0);
|
||||
labelCharge.Name = "labelCharge";
|
||||
labelCharge.Size = new Size(324, 36);
|
||||
labelCharge.TabIndex = 40;
|
||||
labelCharge.Text = " ";
|
||||
labelCharge.TextAlign = ContentAlignment.TopRight;
|
||||
//
|
||||
// panelPeripherals
|
||||
//
|
||||
panelPeripherals.AutoSize = true;
|
||||
@@ -1482,7 +1497,6 @@ namespace GHelper
|
||||
private Label labelVersion;
|
||||
private RButton buttonStopGPU;
|
||||
private TableLayoutPanel tableButtons;
|
||||
private RButton buttonUpdates;
|
||||
private Panel panelPeripherals;
|
||||
private TableLayoutPanel tableLayoutPeripherals;
|
||||
private Panel panelPeripheralsTile;
|
||||
@@ -1492,5 +1506,7 @@ namespace GHelper
|
||||
private RButton buttonPeripheral3;
|
||||
private RButton buttonPeripheral1;
|
||||
private RButton buttonKeyboard;
|
||||
private RButton buttonUpdates;
|
||||
private Label labelCharge;
|
||||
}
|
||||
}
|
||||
@@ -178,9 +178,13 @@ namespace GHelper
|
||||
sensorTimer.Elapsed += OnTimedEvent;
|
||||
sensorTimer.Enabled = true;
|
||||
|
||||
panelBattery.MouseEnter += PanelBattery_MouseEnter;
|
||||
labelCharge.MouseEnter += PanelBattery_MouseEnter;
|
||||
labelBattery.MouseEnter += PanelBattery_MouseEnter;
|
||||
labelBatteryTitle.MouseEnter += PanelBattery_MouseEnter;
|
||||
|
||||
panelBattery.MouseLeave += PanelBattery_MouseLeave;
|
||||
labelCharge.MouseLeave += PanelBattery_MouseLeave;
|
||||
labelBattery.MouseLeave += PanelBattery_MouseLeave;
|
||||
labelBatteryTitle.MouseLeave += PanelBattery_MouseLeave;
|
||||
|
||||
@@ -229,7 +233,7 @@ namespace GHelper
|
||||
|
||||
if (HardwareControl.batteryHealth != -1)
|
||||
{
|
||||
labelBattery.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%";
|
||||
labelCharge.Text = Properties.Strings.BatteryHealth + ": " + Math.Round(HardwareControl.batteryHealth, 1) + "%";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -822,6 +826,7 @@ namespace GHelper
|
||||
string cpuTemp = "";
|
||||
string gpuTemp = "";
|
||||
string battery = "";
|
||||
string charge = "";
|
||||
|
||||
HardwareControl.ReadSensors();
|
||||
Task.Run((Action)PeripheralsProvider.RefreshBatteryForAllDevices);
|
||||
@@ -829,6 +834,9 @@ namespace GHelper
|
||||
if (HardwareControl.cpuTemp > 0)
|
||||
cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C";
|
||||
|
||||
if (HardwareControl.batteryCapacity > 0)
|
||||
charge = Properties.Strings.BatteryCharge + ": " + Math.Round(HardwareControl.batteryCapacity, 1) + "% ";
|
||||
|
||||
if (HardwareControl.batteryRate < 0)
|
||||
battery = Properties.Strings.Discharging + ": " + Math.Round(-(decimal)HardwareControl.batteryRate, 1).ToString() + "W";
|
||||
else if (HardwareControl.batteryRate > 0)
|
||||
@@ -847,7 +855,8 @@ namespace GHelper
|
||||
if (HardwareControl.midFan is not null)
|
||||
labelMidFan.Text = "Mid " + HardwareControl.midFan;
|
||||
|
||||
if (!batteryMouseOver) labelBattery.Text = battery;
|
||||
labelBattery.Text = battery;
|
||||
if (!batteryMouseOver) labelCharge.Text = charge;
|
||||
});
|
||||
|
||||
string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user