Tiny Core Linux
Tiny Core Extensions => TCE Bugs => Topic started by: polikuo on August 31, 2017, 11:57:39 AM
-
watcher.tcz.info
To start watcher on X start, add to .xsession:
[ $(which watcher) ] && watcher -g +0-0 -bat BAT0 &
Terminal output
$ watcher -g -0-0 -bat BAT0
Error opening batinfo /sys/class/power_supply/BAT0/charge_now
$ ls /sys/class/power_supply/BAT0
alarm
capacity
cycle_count
device
energy_full
energy_full_design
energy_now
manufacturer
model_name
power/
power_now
present
serial_number
status
subsystem
technology
type
uevent
voltage_min_design
voltage_now
Is there any way to tell the status of a laptop battery ?
-
Hi polikuo
Searching online I found references to charge_full, charge_full_design, and charge_now. I'm wondering if somewhere
along the line charge was changed to energy. Try creating a link to energy_now and see if that works.
-
Hi polikuo
Searching online I found references to charge_full, charge_full_design, and charge_now. I'm wondering if somewhere
along the line charge was changed to energy. Try creating a link to energy_now and see if that works.
$ sudo ln -s /sys/class/power_supply/BAT0/energy_now /sys/class/power_supply/BAT0/charge_now
ln: /sys/class/power_supply/BAT0/charge_now: Operation not permitted
I don't think it's possible to do that.
Anyway, I guess this line may do the trick.
$ expr "$(cat /sys/class/power_supply/BAT0/energy_now)"00 / $(cat /sys/class/power_supply/BAT0/energy_full)
49
-
Hi polikuo
How about this:
sudo su
ln -s /sys/class/power_supply/BAT0/energy_now /sys/class/power_supply/BAT0/charge_now
exit
I also found this:
https://bbs.archlinux.org/viewtopic.php?id=131025
Users noted that depending on whether or not the AC adapter was plugged in determined if charge or energy was listed
in that directory.
-
Nope, still won't link.
Also, nothing changed between the two.
tc@box:~$ sudo su
root@box:/home/tc# ln -s /sys/class/power_supply/BAT0/energy_now /sys/class/power_supply/BAT0/charge_now
ln: /sys/class/power_supply/BAT0/charge_now: Operation not permitted
### Without the power cable ###
root@box:/home/tc# ls /sys/class/power_supply/BAT0
alarm energy_full_design present uevent
capacity energy_now serial_number voltage_min_design
capacity_level manufacturer status voltage_now
cycle_count model_name subsystem
device power technology
energy_full power_now type
### Charging ###
root@box:/home/tc# ls /sys/class/power_supply/BAT0
alarm energy_full_design present uevent
capacity energy_now serial_number voltage_min_design
capacity_level manufacturer status voltage_now
cycle_count model_name subsystem
device power technology
energy_full power_now type
Anyway, I believe the source code of the watcher needs to be adjusted and recompiled.
Running TC x86 8.1rc3
(I don't have a 64-bit laptop to test on :()
-
Posted watcher source to https://github.com/clbr/watcher, if you want to add support for energy_now.
-
Hi polikuo
I worked out the change for you if you're interested. In the file watcher.css replace this:
static void batcheckup() {
FILE *batinfo;
sprintf(longpath, "/sys/class/power_supply/%s/charge_now", batname);
if ((batinfo = fopen(longpath, "r")) == NULL) {
fprintf(stderr, "Error opening batinfo %s\n", longpath);
exit(1);
}
fscanf(batinfo, "%f", &batnow);
fclose(batinfo);
sprintf(longpath, "/sys/class/power_supply/%s/charge_full", batname);
if ((batinfo = fopen(longpath, "r")) == NULL) {
fprintf(stderr, "Error opening batinfo %s\n", longpath);
exit(1);
}
fscanf(batinfo, "%f", &batfull);
fclose(batinfo);
sprintf(batmsg, " %.1f%%B", (float)(batnow / batfull) * 100);
}
with this:
static void batcheckup() {
FILE *batinfo;
sprintf(longpath, "/sys/class/power_supply/%s/energy_now", batname);
if ((batinfo = fopen(longpath, "r")) == NULL)
{
fprintf(stderr, "Error opening batinfo %s\n", longpath);
sprintf(longpath, "/sys/class/power_supply/%s/charge_now", batname);
if ((batinfo = fopen(longpath, "r")) == NULL)
{
fprintf(stderr, "Error opening batinfo %s\n", longpath);
exit(1);
}
}
fscanf(batinfo, "%f", &batnow);
fclose(batinfo);
sprintf(longpath, "/sys/class/power_supply/%s/energy_full", batname);
if ((batinfo = fopen(longpath, "r")) == NULL)
{
fprintf(stderr, "Error opening batinfo %s\n", longpath);
sprintf(longpath, "/sys/class/power_supply/%s/charge_full", batname);
if ((batinfo = fopen(longpath, "r")) == NULL)
{
fprintf(stderr, "Error opening batinfo %s\n", longpath);
exit(1);
}
}
fscanf(batinfo, "%f", &batfull);
fclose(batinfo);
sprintf(batmsg, " %.1f%%B", (float)(batnow / batfull) * 100);
}
-
Hi polikuo
I worked out the change for you if you're interested. In the file watcher.cxx replace this:
....
It works ! :)
(Much better than my sed -i 's/charge/energy/g' watcher.cxx solution)
@curaga, would you apply the patch to the source ? Thanks :)
P.S.
Is it just me or the "Code: [Select]" button of the forum no longer works with the latest firefox ?
-
P.S.
Is it just me or the "Code: [Select]" button of the forum no longer works with the latest firefox ?
"Select" Doesn't work for me either in Firefox 55.0.3, but am not sure if that is a result of an update in Firefox or SMF?
But then I never used the "Select" feature anyhow..
-
Hi coreplayer2
I'm running an old version of Opera and code select works for me.
-
Hi Rich, I used "firefox_getLatest.sh -m" to install an earlier version (in this case v52.0) and the select button works as expected; the plot thickens..
;p
-
Hi polikuo
It works !
Glad to hear that.
(Much better than my sed -i 's/charge/energy/g' watcher.cxx solution)
Simply replacing charge with energy might have broken the application for someone else. Adding a test
for the other directory entries maintains backward compatibility.
-
Simply replacing charge with energy might have broken the application for someone else. Adding a test
for the other directory entries maintains backward compatibility.
Ahh ...
Learn something new today. :)
Thanks for the tip.
-
The code looks good, Rich if you want to send a patch or a github pull request I can apply it. Manual copypaste is bad.
-
Hi curaga
Manual copypaste is bad.
Well, I certainly don't want to be bad. ::)
As per the patch guidelines:
http://forum.tinycorelinux.net/index.php/topic,9007.msg48926.html#msg48926
I ran diff -u on the original and modified files and uploaded the result as watcher.patch to:
http://patches.tinycorelinux.net/
Hope I got it right. This is what it looks like:
--- watcher.cxx 2017-09-01 09:49:50.217102408 +0000
+++ watcher_new.cxx 2017-09-01 09:54:29.833764739 +0000
@@ -34,18 +34,30 @@
FILE *batinfo;
- sprintf(longpath, "/sys/class/power_supply/%s/charge_now", batname);
- if ((batinfo = fopen(longpath, "r")) == NULL) {
+ sprintf(longpath, "/sys/class/power_supply/%s/energy_now", batname);
+ if ((batinfo = fopen(longpath, "r")) == NULL)
+ {
fprintf(stderr, "Error opening batinfo %s\n", longpath);
- exit(1);
+ sprintf(longpath, "/sys/class/power_supply/%s/charge_now", batname);
+ if ((batinfo = fopen(longpath, "r")) == NULL)
+ {
+ fprintf(stderr, "Error opening batinfo %s\n", longpath);
+ exit(1);
+ }
}
fscanf(batinfo, "%f", &batnow);
fclose(batinfo);
- sprintf(longpath, "/sys/class/power_supply/%s/charge_full", batname);
- if ((batinfo = fopen(longpath, "r")) == NULL) {
+ sprintf(longpath, "/sys/class/power_supply/%s/energy_full", batname);
+ if ((batinfo = fopen(longpath, "r")) == NULL)
+ {
fprintf(stderr, "Error opening batinfo %s\n", longpath);
- exit(1);
+ sprintf(longpath, "/sys/class/power_supply/%s/charge_full", batname);
+ if ((batinfo = fopen(longpath, "r")) == NULL)
+ {
+ fprintf(stderr, "Error opening batinfo %s\n", longpath);
+ exit(1);
+ }
}
fscanf(batinfo, "%f", &batfull);
fclose(batinfo);
-
Applied, thanks.