WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Battery with watcher.tcz  (Read 8757 times)

Online polikuo

  • Hero Member
  • *****
  • Posts: 723
Battery with watcher.tcz
« on: August 31, 2017, 11:57:39 AM »
watcher.tcz.info
Quote
To start watcher on X start, add to .xsession:
[ $(which watcher) ] && watcher -g +0-0 -bat BAT0 &

Terminal output
Code: [Select]
$ 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 ?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #1 on: August 31, 2017, 12:15:46 PM »
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.

Online polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Battery with watcher.tcz
« Reply #2 on: August 31, 2017, 12:34:37 PM »
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.

Code: [Select]
$ 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.
Code: [Select]
$ expr "$(cat /sys/class/power_supply/BAT0/energy_now)"00 / $(cat /sys/class/power_supply/BAT0/energy_full)
49

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #3 on: August 31, 2017, 12:41:15 PM »
Hi polikuo
How about this:
Code: [Select]
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.

Online polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Battery with watcher.tcz
« Reply #4 on: August 31, 2017, 12:58:12 PM »
Nope, still won't link.
Also, nothing changed between the two.

Code: [Select]
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  :()

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Battery with watcher.tcz
« Reply #5 on: August 31, 2017, 01:01:02 PM »
Posted watcher source to https://github.com/clbr/watcher, if you want to add support for energy_now.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #6 on: August 31, 2017, 01:31:45 PM »
Hi polikuo
I worked out the change for you if you're interested. In the file  watcher.css  replace this:
Code: [Select]
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:
Code: [Select]
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);
}

Online polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Battery with watcher.tcz
« Reply #7 on: August 31, 2017, 01:56:45 PM »
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 ?
« Last Edit: August 31, 2017, 02:02:18 PM by polikuo »

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: Battery with watcher.tcz
« Reply #8 on: August 31, 2017, 02:30:52 PM »
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..

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #9 on: August 31, 2017, 02:34:59 PM »
Hi coreplayer2
I'm running an old version of Opera and code select works for me.

Offline coreplayer2

  • Hero Member
  • *****
  • Posts: 3020
Re: Battery with watcher.tcz
« Reply #10 on: August 31, 2017, 02:56:44 PM »
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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #11 on: August 31, 2017, 10:46:12 PM »
Hi polikuo
Quote
It works ! 
Glad to hear that.
Quote
(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.

Online polikuo

  • Hero Member
  • *****
  • Posts: 723
Re: Battery with watcher.tcz
« Reply #12 on: August 31, 2017, 10:56:55 PM »
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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: Battery with watcher.tcz
« Reply #13 on: September 01, 2017, 04:35:53 AM »
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.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11619
Re: Battery with watcher.tcz
« Reply #14 on: September 01, 2017, 10:17:05 AM »
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:
Code: [Select]
--- 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);