d4nj1 / TLPUI

A GTK user interface for TLP written in Python
GNU General Public License v2.0
1.08k stars 83 forks source link

#102 Amend values for battery conservation to support all vendors #146

Closed d4nj1 closed 6 months ago

d4nj1 commented 6 months ago

In regards to #102 and #134 I would change the thresholds for

START_CHARGE_THRESH_BAT0/1 and STOP_CHARGE_THRESH_BAT0/1

as documented in https://linrunner.de/tlp/faq/battery.html#are-thinkpads-with-coreboot-supported

Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  0(off)..96(default)..99
* STOP_CHARGE_THRESH_BAT0/1:   1..100(default)

Also from the config file itself:

# - Vendor specific parameter value ranges are shown by tlp-stat -b
# - If your hardware supports a start *and* a stop threshold, you must
#   specify both, otherwise TLP will refuse to apply the single threshold
# - If your hardware supports only a stop threshold, set the start value to 0
anaximeno commented 6 months ago

Hi @d4nj1,

I believe it wouldn't completely work because the STOP_CHARGE_THRESH_BAT0 should be able to accept 0 to determine to not use a stop threshold at all and charge up to 100% in non-ThinkPad series, as specified in https://linrunner.de/tlp/settings/bc-vendors.html#lenovo-non-thinkpad-series

d4nj1 commented 6 months ago

Hi @anaximeno , thanks for sharing. After looking through the vendors list it only makes sense to allow 0...99 for START and 0...100 for STOP values. As described in #102 it would be nicer to evaluate which plugin is actively used and then apply the supported values or to only show toggles. Sadly for calling tlp-stat -b root privileges are required. I guess this would confuse users to first enter their password before actually being able to use TLP-UI.

@linrunner Do you know a way how this can be extracted without root privileges? Doesn't every vendor plugin in TLP require a specific kernel module to be loaded? If yes, then in theory it could be looked up via lsmod or similar.

+++ Battery Care
Plugin: VENDOR -> VENDOR-kernel-module ?

Thanks in advance

linrunner commented 6 months ago

@d4nj1 Unfortunately, you can't just check for loaded modules. The process has up to three steps.

In every bat.d plugin there is a "method" batdrv_init(). This (1) checks if the specific platform kernel module is loaded. (2) it looks for the specific sysfiles. (3) In the case of ThinkPads, depending on the exact constellation, additional external kernel modules are loaded.

During detection, all plugins are run through until one matches. Because of (3), root is mandatory.

I made a note in my backlog to check if I can write the active plugin to a file below /run/tlp/.

But that alone is not enough: a plugin may be active based on the recognized vendor-specific kernel module, even though the hardware does not support charge thresholds. The entire logic is contained in batdrv_init().

d4nj1 commented 6 months ago

Hi @linrunner , thanks a lot for your instant feedback. I will merge the PR now and hopefully the vendor specific visualization can be optimized in future.

linrunner commented 3 weeks ago

Hi @d4nj1, currently preparing the 1.7 beta I suddenly remembered that I promised something here ... :-)

Proposal: TLP writes a file /run/tlp/batd.yaml containing a scheme like yours. I would leave out parameters that are not available for the target hardware e.g. plugin.

Example 1:

---
categories:
  - name: Battery Care
    plugin: system76
    hardware: System76 laptops
    configs:
      - group: CHARGE_THRESH_BAT0
        ids:
          - id: START_CHARGE_THRESH_BAT0
            type: numeric
            values: 0-99
          - id: STOP_CHARGE_THRESH_BAT0
            type: numeric
            values: 1-100

Example 2:

---
categories:
  - name: Battery Care
    plugin: asus
    hardware: ASUS laptops
    configs:
      - group: CHARGE_THRESH_BAT0
        ids:
          - id: STOP_CHARGE_THRESH_BAT0
            type: numeric
            values: 0-100
            hint: Batteries BAT0, BATC and BATT share this parameter
      - group: CHARGE_THRESH_BAT1
        ids:
          - id: STOP_CHARGE_THRESH_BAT1
            type: numeric
            values: 0-100
            hint: Battery BAT1 uses this parameter

Example 3:

---
categories:
  - name: Battery Care
    plugin: generic
    hardware: Laptop with no battery care support

I didn't bother with correct YAML syntax and indentation, please correct my suggestions.