Files
lotherkandClaude Opus 5.5 a6c21a4f89 mcde: the battery in the bar
McdeSys gets mcde_sys_battery: all batteries as one, charging, mains,
minutes left.  NetBSD reads the envsys(4) dictionary of /dev/sysmon as
envstat(8) does (acpibat "present", "charge", "charging", "discharge
rate"; acpiacad "connected"), Linux /sys/class/power_supply (energy_* or
charge_*, status, Mains/USB online).  The sources are in
docs/reference/battery.txt.

dtbar shows a fourth icon, only when there is a battery: full, half, low
(red), charging; its menu says the charge, the power source and the time
left.  The status bar is 30 pixels an icon.

Measured: on the Linux host test_sysinfo says "battery 76% ac", as
/sys/class/power_supply/BAT0/capacity and AC/online do; the menu on Xvfb
(build/mcde-shots/battery-menu.png) says "Battery: 76 %", "Power Source:
Power Adapter".  The NetBSD backend compiles and runs in the build VM,
which has no battery (envstat: no drivers registered): only the
no-battery case is measured there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 07:01:18 +00:00

142 lines
5.5 KiB
Plaintext

Battery state: where the systems publish it. Collected 2026-11-11 for McdeSys
mcde_sys_battery (ext/src/mcde/lib/McdeSys/{netbsd,linux}.c).
== Linux: refs/linux/7.0.0/Documentation/ABI/testing/sysfs-class-power
-- lines 30-50 (type)
What: /sys/class/power_supply/<supply_name>/type
Date: May 2010
Contact: linux-pm@vger.kernel.org
Description:
Describes the main type of the supply.
Access: Read
Valid values: "Battery", "UPS", "Mains", "USB", "Wireless"
**Battery and USB properties**
What: /sys/class/power_supply/<supply_name>/current_avg
Date: May 2007
Contact: linux-pm@vger.kernel.org
Description:
Battery:
Reports an average IBAT current reading for the battery, over
a fixed period. Normally devices will provide a fixed interval
in which they average readings to smooth out the reported
value.
-- lines 263-280 (capacity)
What: /sys/class/power_supply/<supply_name>/capacity
Date: May 2007
Contact: linux-pm@vger.kernel.org
Description:
Fine grain representation of battery capacity.
Access: Read
Valid values: 0 - 100 (percent)
What: /sys/class/power_supply/<supply_name>/capacity_alert_max
Date: July 2012
Contact: linux-pm@vger.kernel.org
Description:
Maximum battery capacity trip-wire value where the supply will
notify user-space of the event. This is normally used for the
battery discharging scenario where user-space needs to know the
battery has dropped to an upper level so it can take
-- lines 488-505 (status)
What: /sys/class/power_supply/<supply_name>/status
Date: May 2007
Contact: linux-pm@vger.kernel.org
Description:
Represents the charging status of the battery. Normally this
is read-only reporting although for some supplies this can be
used to enable/disable charging to the battery.
Access: Read, Write
Valid values:
"Unknown", "Charging", "Discharging",
"Not charging", "Full"
What: /sys/class/power_supply/<supply_name>/charge_behaviour
Date: November 2021
Contact: linux-pm@vger.kernel.org
Description:
== Linux: refs/linux/7.0.0/Documentation/power/power_supply_class.rst (ENERGY_*, CHARGE_*, POWER_NOW, units)
51: All voltages, currents, charges, energies, time and temperatures in µV,
52: µA, µAh, µWh, seconds and tenths of degree Celsius unless otherwise
63:| **Because both "charge" (µAh) and "energy" (µWh) represents "capacity" |
67:| attributes represents capacity in µAh only. |
68:| - `ENERGY_*` |
69:| attributes represents capacity in µWh only. |
127:ENERGY_FULL_DESIGN, ENERGY_EMPTY_DESIGN
130:CHARGE_FULL, CHARGE_EMPTY
136:ENERGY_FULL, ENERGY_EMPTY
140: the current charge counter (in µAh). This could easily
== NetBSD: src/sys/dev/acpi/acpi_bat.c:710-725 (sensor names and flags)
INITDATA(ACPIBAT_PRESENT, ENVSYS_INDICATOR, "present");
INITDATA(ACPIBAT_DCAPACITY, ENVSYS_SWATTHOUR, "design cap");
INITDATA(ACPIBAT_LFCCAPACITY, ENVSYS_SWATTHOUR, "last full cap");
INITDATA(ACPIBAT_DVOLTAGE, ENVSYS_SVOLTS_DC, "design voltage");
INITDATA(ACPIBAT_VOLTAGE, ENVSYS_SVOLTS_DC, "voltage");
INITDATA(ACPIBAT_CHARGERATE, ENVSYS_SWATTS, "charge rate");
INITDATA(ACPIBAT_DISCHARGERATE, ENVSYS_SWATTS, "discharge rate");
INITDATA(ACPIBAT_CAPACITY, ENVSYS_SWATTHOUR, "charge");
INITDATA(ACPIBAT_CHARGING, ENVSYS_BATTERY_CHARGE, "charging");
INITDATA(ACPIBAT_CHARGE_STATE, ENVSYS_BATTERY_CAPACITY, "charge state");
#undef INITDATA
sc->sc_sensor[ACPIBAT_CHARGE_STATE].value_cur =
ENVSYS_BATTERY_CAPACITY_NORMAL;
-- acpi_bat.c:545-566 (rates in uW, charge in uWh, charging 0/1)
state = elm[ACPIBAT_BST_STATE].Integer.Value;
if ((state & ACPIBAT_ST_CHARGING) != 0) {
/* XXX rate can be invalid */
rate = elm[ACPIBAT_BST_RATE].Integer.Value;
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SVALID;
sc->sc_sensor[ACPIBAT_CHARGERATE].value_cur = rate * 1000;
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 1;
} else if ((state & ACPIBAT_ST_DISCHARGING) != 0) {
rate = elm[ACPIBAT_BST_RATE].Integer.Value;
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SVALID;
sc->sc_sensor[ACPIBAT_DISCHARGERATE].value_cur = rate * 1000;
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 0;
} else {
sc->sc_sensor[ACPIBAT_CHARGING].state = ENVSYS_SVALID;
sc->sc_sensor[ACPIBAT_CHARGING].value_cur = 0;
sc->sc_sensor[ACPIBAT_CHARGERATE].state = ENVSYS_SINVALID;
sc->sc_sensor[ACPIBAT_DISCHARGERATE].state = ENVSYS_SINVALID;
}
/* Remaining capacity. */
val = elm[ACPIBAT_BST_CAPACITY].Integer.Value;
sc->sc_sensor[ACPIBAT_CAPACITY].value_cur = val * 1000;
sc->sc_sensor[ACPIBAT_CAPACITY].state = ACPIBAT_VAL_ISVALID(val);
== NetBSD: src/sys/dev/acpi/acpi_acad.c:262
(void)strlcpy(sc->sc_sensor.desc, "connected", ENVSYS_DESCLEN);
== NetBSD: how envstat(8) reads them, src/usr.sbin/envstat/envstat.c:527, 660-730
rval = prop_dictionary_recv_ioctl(fd, ENVSYS_GETDICTIONARY, &dict);
/* get current value */
obj1 = prop_dictionary_get(obj, "cur-value");
if (obj1)
sensor->cur_value = prop_number_signed_value(obj1);
/* get max value */
obj1 = prop_dictionary_get(obj, "max-value");
if (obj1)
sensor->max_value = prop_number_signed_value(obj1);
-- state strings, src/sys/dev/sysmon/sysmon_envsys_tables.c:64-65
{ ENVSYS_SVALID, -1, "valid" },
{ ENVSYS_SINVALID, -1, "invalid" },