openbsd: read hw.battery.chargemode/start/stop and update charge thresholds properties

This commit is contained in:
Landry Breuil 2025-06-02 07:07:31 +02:00
parent ec6631a11e
commit 6b00118e16

View file

@ -399,6 +399,8 @@ up_backend_update_acpibat_state(UpDevice* device, struct sensordev s)
/* gdouble bif_dvolt; */
struct sensor sens;
size_t slen = sizeof(sens);
int chargemode=-2, chargestart=-1, chargestop=-1;
size_t ilen = sizeof(chargemode);
int mib[] = {CTL_HW, HW_SENSORS, 0, 0, 0};
mib[2] = s.num;
@ -444,6 +446,35 @@ up_backend_update_acpibat_state(UpDevice* device, struct sensordev s)
capacity = 100.0f;
}
mib[0] = CTL_HW;
mib[1] = HW_BATTERY;
mib[2] = HW_BATTERY_CHARGEMODE;
mib[3] = 0;
mib[4] = 0;
if (sysctl(mib, 3, &chargemode, &ilen, NULL, 0) < 0)
g_error("failed to get hw.battery.chargemode sysctl node");
mib[2] = HW_BATTERY_CHARGESTART;
if (sysctl(mib, 3, &chargestart, &ilen, NULL, 0) < 0)
g_error("failed to get hw.battery.chargestart sysctl node");
mib[2] = HW_BATTERY_CHARGESTOP;
if (sysctl(mib, 3, &chargestop, &ilen, NULL, 0) < 0)
g_error("failed to get hw.battery.chargestop sysctl node");
//g_debug("chargestop=%d, chargestart=%d, chargemode=%d", chargestop, chargestart,chargemode);
if (chargestop >= 0) {
g_object_set(device,
"charge-threshold-supported", TRUE,
"charge-end-threshold", chargestop,
(void*) NULL);
if (chargemode >= -1)
g_object_set(device,
"charge-threshold-enabled", chargemode == 1,
(void*) NULL);
if (chargestart >= 0)
g_object_set(device,
"charge-start-threshold", chargestart,
(void*) NULL);
}
g_object_set (device,
"energy", bst_cap,
"energy-full", bif_lastfullcap,