Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added estimated remaining time on battery #3408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 46 additions & 7 deletions app/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public partial class SettingsForm : RForm

bool isGpuSection = true;

bool rateMouseOver = false;
bool batteryMouseOver = false;
bool batteryFullMouseOver = false;

Expand Down Expand Up @@ -236,6 +237,8 @@ public SettingsForm()
labelCharge.MouseEnter += PanelBattery_MouseEnter;
labelCharge.MouseLeave += PanelBattery_MouseLeave;
labelBattery.Click += LabelBattery_Click;
labelBattery.MouseEnter += LabelBattery_MouseEnter;
labelBattery.MouseLeave += LabelBattery_MouseLeave;

buttonPeripheral1.Click += ButtonPeripheral_Click;
buttonPeripheral2.Click += ButtonPeripheral_Click;
Expand Down Expand Up @@ -292,6 +295,18 @@ private void LabelBattery_Click(object? sender, EventArgs e)
RefreshSensors(true);
}

private void LabelBattery_MouseEnter(object? sender, EventArgs e)
{
rateMouseOver = true;
RefreshSensors(true);
}

private void LabelBattery_MouseLeave(object? sender, EventArgs e)
{
rateMouseOver = false;
RefreshSensors(true);
}

private void ButtonDonate_Click(object? sender, EventArgs e)
{
AppConfig.Set("donate_click", AppConfig.Get("start_count"));
Expand Down Expand Up @@ -1412,6 +1427,22 @@ private void ButtonStopGPU_Click(object? sender, EventArgs e)
gpuControl.KillGPUApps();
}

private string BatteryTime()
{
decimal limit = 1;
if (!BatteryControl.chargeFull) limit = (decimal)AppConfig.Get("charge_limit") / 100;
decimal? remaining = HardwareControl.batteryRate < 0 ? HardwareControl.chargeCapacity : (HardwareControl.fullCapacity * limit) - HardwareControl.chargeCapacity;
try
{
double hoursRemaining = Math.Abs((double)((remaining / 1000) / HardwareControl.batteryRate));
return String.Format("Time Remaining: {0}h {1}m", Math.Floor(hoursRemaining), Math.Round((hoursRemaining % 1) * 60, 0));
}
catch
{
return "Time Remaining: Unknown";
}
}

public async void RefreshSensors(bool force = false)
{

Expand All @@ -1426,19 +1457,26 @@ public async void RefreshSensors(bool force = false)
HardwareControl.ReadSensors();
Task.Run((Action)PeripheralsProvider.RefreshBatteryForAllDevices);

string battTime = BatteryTime();

if (HardwareControl.cpuTemp > 0)
cpuTemp = ": " + Math.Round((decimal)HardwareControl.cpuTemp).ToString() + "°C";

if (HardwareControl.batteryCapacity > 0)
{
charge = Properties.Strings.BatteryCharge + ": " + HardwareControl.batteryCharge;
}

if (HardwareControl.batteryRate < 0)
battery = Properties.Strings.Discharging + ": " + Math.Round(-(decimal)HardwareControl.batteryRate, 1).ToString() + "W";
else if (HardwareControl.batteryRate > 0)
battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W";

if (rateMouseOver)
{
battery = battTime;
}
else
{
if (HardwareControl.batteryRate < 0)
battery = Properties.Strings.Discharging + ": " + Math.Round(-(decimal)HardwareControl.batteryRate, 1).ToString() + "W";
else if (HardwareControl.batteryRate > 0)
battery = Properties.Strings.Charging + ": " + Math.Round((decimal)HardwareControl.batteryRate, 1).ToString() + "W";
}

if (HardwareControl.gpuTemp > 0)
{
Expand All @@ -1447,7 +1485,8 @@ public async void RefreshSensors(bool force = false)

string trayTip = "CPU" + cpuTemp + " " + HardwareControl.cpuFan;
if (gpuTemp.Length > 0) trayTip += "\nGPU" + gpuTemp + " " + HardwareControl.gpuFan;
if (battery.Length > 0) trayTip += "\n" + battery;
if (battery.Length > 0) trayTip += "\n" + battery + "\n" + battTime;


if (Program.settingsForm.IsHandleCreated)
Program.settingsForm.BeginInvoke(delegate
Expand Down