Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add full support for acpi #12

Merged
merged 1 commit into from
Mar 14, 2021
Merged

Add full support for acpi #12

merged 1 commit into from
Mar 14, 2021

Conversation

Freed-Wu
Copy link
Contributor

Not all acpi client of linux use /sys/class/power_supply/AC*/online to show
if the battery is charging (at least my distribution).
/sys/class/power_supply/BAT*/status can did the same function.

after this change, now it can work in my linux.

Screenshot from 2021-03-10 15-40-12

And not only /sys/class/power_supply/BAT*/status, refer https://github.com/romkatv/powerlevel10k/blob/master/internal/p10k.zsh#L1326:

      local -a bats=( /sys/class/power_supply/(CMB*|BAT*|battery)/(FN) )

for example, my android use /sys/class/power_supply/battery/status
not /sys/class/power_supply/BAT*/status.

the backend can also work for android which work for root user (in android,
only root can have privilege to read /sys). for android work for non-root
user, the #9 is also a
valid substitution.

thanks for your review.

@Freed-Wu
Copy link
Contributor Author

oops! i found although my linux don't have
/sys/class/power_supply/AC*/online, however,
/sys/class/power_supply/ADP*/online exists. and in my android,
/sys/class/power_supply/ac/online, /sys/class/power_supply/usb/online
and /sys/class/power_supply/pc_port/online exist. so the
/sys/class/power_supply/*/online only display the method of charging: use
usb, ac charger, dc charger, not if the device is charging. so i advice use
/sys/class/power_supply/(CMB*|BAT*|battery)/status to replace
/sys/class/power_supply/*/online.

@Freed-Wu
Copy link
Contributor Author

so i advice use
/sys/class/power_supply/(CMB*|BAT*|battery)/status to replace
/sys/class/power_supply/*/online.

because we just only wanna know if the battery is charging, not the method of
charging.

@Freed-Wu Freed-Wu mentioned this pull request Mar 10, 2021
@Freed-Wu
Copy link
Contributor Author

https://github.com/lambdalisue/battery.vim/blob/master/autoload/battery/backend/linux.vim#L2

let s:Job = vital#battery#import('System.Job')

s:Job is not be used in this script. what is its use? can this line be
deleted?

@lambdalisue lambdalisue self-requested a review March 10, 2021 13:28
@lambdalisue
Copy link
Owner

I'll check it in this weekend. Ping me if I've not replied even after the weekend.

@lambdalisue
Copy link
Owner

#12 (comment)

Well... What is the conclusion? It seems the code tried to glob from /sys/class/power_supply/{CMD*,BAT*,battery}/{status, capacity}. I'd like to review the final code.

Additionally, do you have documentation about each path? It seems /sys/class/power_supply/BAT*/online does not exist (#7)

#12 (comment)

Yes, it's not used here.

@Freed-Wu
Copy link
Contributor Author

Yes, it's not used here.

thanks. i have deleted this line which is not used.

It seems the code tried to glob

you are right. now i have rewrited it.

do you have documentation about each path

According to
https://github.com/romkatv/powerlevel10k/blob/master/internal/p10k.zsh#L1324-L1326

    Linux|Android)
      # See https://sourceforge.net/projects/acpiclient.
      local -a bats=( /sys/class/power_supply/(CMB*|BAT*|battery)/(FN) )

the original documents can be found in
https://sourceforge.net/projects/acpiclient.

Comment on lines 2 to 4
let s:bat_files = glob('/sys/class/power_supply/{CMD*,BAT*,battery}/{status,capacity}', 0, 1)
let s:bat_status = get(s:bat_files, 0, '')
let s:bat_capacity = get(s:bat_files, 1, '')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s:bat_capacity might get wrong path when there are several match on the first pattern.

Assume that you have

├── a
│   ├── a
│   ├── b
│   └── c
└── b
    ├── a
    ├── b
    └── c

And then

:echo glob('./{a,b}/{a,b}', 0, 1)
['./a/a/', './a/b/', './b/a/', './b/b/']

Probably, it's better to use glob in each variables like

Suggested change
let s:bat_files = glob('/sys/class/power_supply/{CMD*,BAT*,battery}/{status,capacity}', 0, 1)
let s:bat_status = get(s:bat_files, 0, '')
let s:bat_capacity = get(s:bat_files, 1, '')
let s:bat_status = get(glob('/sys/class/power_supply/{CMD*,BAT*,battery}/status', 0, 1), 0, '')
let s:bat_capacity = get(glob('/sys/class/power_supply/{CMD*,BAT*,battery}/capacity', 0, 1), 0, '')

@Freed-Wu
Copy link
Contributor Author

great. now it can work.

@lambdalisue lambdalisue merged commit e40ef66 into lambdalisue:master Mar 14, 2021
@lambdalisue
Copy link
Owner

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants