commit eb1717021d3d0addbaf82375fb8f978792891e06
parent b646036ca3c11745293c5c961145b5e8b0973846
Author: bsandro <email@bsandro.tech>
Date: Tue, 31 May 2022 01:07:01 +0300
Kohjinsha (AMD Geode) laptop support - battery percentage and status, temperature
Diffstat:
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/dwmstatus.c b/dwmstatus.c
@@ -162,13 +162,14 @@ getbattery()
struct sensor temp;
size_t len;
float percentage = 0.0;
+ float cap_value = 0.0;
char charger_state = ' ';
mib[0] = CTL_HW;
mib[1] = HW_SENSORS;
- mib[2] = 1; // cwfg0
- mib[3] = SENSOR_PERCENT;
- mib[4] = 0;
+ mib[2] = 2; // acpibat0
+ mib[3] = SENSOR_WATTHOUR;
+ mib[4] = 4; // design capacity
len = sizeof(temp);
@@ -176,17 +177,25 @@ getbattery()
if (sysctl(mib, 5, &temp, &len, NULL, 0) == -1) {
return smprintf("sysctl error: %s\n", strerror(errno));
} else {
- percentage = (float)temp.value / 1000.0;
+ cap_value = (float)temp.value;
+ }
+
+ mib[4] = 3; // remaining capacity
+
+ if (sysctl(mib, 5, &temp, &len, NULL, 0) == -1) {
+ smprintf("sysctl error: %s\n", strerror(errno));
+ } else {
+ percentage = ((float)temp.value / cap_value) * 100.0;
}
// charger state
- mib[2] = 3;
- mib[3] = SENSOR_INDICATOR;
+ mib[3] = SENSOR_INTEGER;
+ mib[4] = 0;
if (sysctl(mib, 5, &temp, &len, NULL, 0) == -1) {
smprintf("sysctl error: %s\n", strerror(errno));
} else {
- charger_state = temp.value == 1 ? '+' : '-';
+ charger_state = temp.value == 1 ? '-' : '+';
}
return smprintf("%.1f%%%c", percentage, charger_state);
@@ -201,7 +210,7 @@ gettemperature()
mib[0] = CTL_HW;
mib[1] = HW_SENSORS;
- mib[2] = 0; // bcmtmon0
+ mib[2] = 3; // bcmtmon0
mib[3] = SENSOR_TEMP;
mib[4] = 0; // temp0