mirror of
https://gitlab.freedesktop.org/upower/upower.git
synced 2025-12-20 04:20:04 +01:00
linux: up-device-supply-battery: Allow skipping start or end charging threshold setting
This allows the one of charge_control_start|end_threshold can be ignored by a "_" character. The udev hwdb can be set in the following format. - Skip charging start limit CHARGE_LIMIT=_,80 - Skip charging end limit CHARGE_LIMIT=30,_
This commit is contained in:
parent
4e8e8b43f8
commit
5882721f19
2 changed files with 31 additions and 11 deletions
|
|
@ -25,6 +25,11 @@
|
|||
# systemd-hwdb update
|
||||
# udevadm trigger -v -p /sys/class/power_supply/BAT
|
||||
# where BAT is the battery in question.
|
||||
#
|
||||
# CHARGE_LIMIT is in tuple format and each of the variables can be disabled by "_" character.
|
||||
# For example:
|
||||
# CHARGE_LIMIT=60,80 (charge_control_start_threshold is 60 and charge_control_end_threshold is 80.)
|
||||
# CHARGE_LIMIT=_,80 (charge_control_start_threshold will be skipped and charge_control_end_threshold is 80.)
|
||||
|
||||
battery:*:*:dmi:*
|
||||
CHARGE_LIMIT=60,80
|
||||
|
|
|
|||
|
|
@ -163,12 +163,18 @@ up_device_supply_battery_get_charge_control_limits (GUdevDevice *native, UpBatte
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!up_device_supply_battery_convert_to_double (pairs[0], &charge_control_start_threshold)) {
|
||||
if (g_strcmp0 (pairs[0], "_") == 0) {
|
||||
g_debug ("charge_control_start_threshold is disabled");
|
||||
charge_control_start_threshold = G_MAXUINT;
|
||||
} else if (!up_device_supply_battery_convert_to_double (pairs[0], &charge_control_start_threshold)) {
|
||||
g_warning ("failed to convert charge_control_start_threshold: %s", pairs[0]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!up_device_supply_battery_convert_to_double (pairs[1], &charge_control_end_threshold)) {
|
||||
if (g_strcmp0 (pairs[1], "_") == 0) {
|
||||
g_debug ("charge_control_end_threshold is disabled");
|
||||
charge_control_end_threshold = G_MAXUINT;
|
||||
} else if (!up_device_supply_battery_convert_to_double (pairs[1], &charge_control_end_threshold)) {
|
||||
g_warning ("failed to convert charge_control_start_threshold: %s", pairs[0]);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -401,16 +407,25 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
|
|||
start_filename = g_build_filename (native_path, "charge_control_start_threshold", NULL);
|
||||
end_filename = g_build_filename (native_path, "charge_control_end_threshold", NULL);
|
||||
|
||||
g_string_printf (start_str, "%d", CLAMP (start, 0, 100));
|
||||
g_string_printf (end_str, "%d", CLAMP (end, 0, 100));
|
||||
if (start != G_MAXUINT) {
|
||||
g_string_printf (start_str, "%d", CLAMP (start, 0, 100));
|
||||
if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len,
|
||||
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
g_debug ("Ignore charge_control_start_threshold setting");
|
||||
}
|
||||
|
||||
if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len,
|
||||
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error))
|
||||
return FALSE;
|
||||
|
||||
if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len,
|
||||
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error))
|
||||
return FALSE;
|
||||
if (end != G_MAXUINT) {
|
||||
g_string_printf (end_str, "%d", CLAMP (end, 0, 100));
|
||||
if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len,
|
||||
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) {
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
g_debug ("Ignore charge_control_end_threshold setting");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue