Skip to content

batterymonitor@pdcurtis: battery percent calculation, fix for ageing batteries #7330

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

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,22 @@ MyApplet.prototype = {
try {
// Try to get the battery capacity as an int
let capacityPath = this.batteryPath + '/capacity';
let capacityValue = GLib.file_get_contents(capacityPath)[1];
let capacityValueString = ByteArray.toString(capacityValue);
this.batteryPercentage = parseInt(capacityValueString);

// Original code doesn't account for battery capacity drop due to ageing
// let capacityValue = GLib.file_get_contents(capacityPath)[1];
// let capacityValueString = ByteArray.toString(capacityValue);
// this.batteryPercentage = parseInt(capacityValueString);
// this.batteryPercentage = 50;

// New battery percentage calculated from actual attainable charge vs current charge
let batteryFullChargePath = this.batteryPath + '/charge_full';
let batteryFullChargeValue = GLib.file_get_contents(batteryFullChargePath)[1];
let batteryNowChargePath = this.batteryPath + '/charge_now';
let batteryNowChargeValue = GLib.file_get_contents(batteryNowChargePath)[1];
let chargeFullString = ByteArray.toString(batteryFullChargeValue);
let chargeNowString = ByteArray.toString(batteryNowChargeValue);
this.batteryPercentage = Math.round(100*parseInt(chargeNowString)/parseInt(chargeFullString));


// Try to get the battery state as a lowercase string
let statePath = this.batteryPath + '/status';
Expand Down