all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] battery.el Retrieve more information from sysfs
@ 2011-12-18 18:53 Jérémy Compostella
  2011-12-21 10:03 ` Jérémy Compostella
  2011-12-22 22:52 ` Stefan Monnier
  0 siblings, 2 replies; 10+ messages in thread
From: Jérémy Compostella @ 2011-12-18 18:53 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

All,

I just bought a new laptop and installed a fresh Debian on it. I used to
look at my current battery status using Emacs. I like to look at the
current rate too since this laptop will be used during a long trip and I
want to take care of the consumption in real time.

The issue is that with the 2.6.32 kernel from Debian for this laptop I
do not have the /proc/acpi/battery part. However, the sysfs is able to
report all the data I need. The current Emacs battery module is not able
to retrieve the information I need from sysfs but it does from
/proc/acpi/battery. So I made a small evolution to enable the following:

- Get the current rate
- Get the current temperature (does not work on my laptop but the
  power_supply interface is able to provide it, so I added it too.
- Do the time remaining estimation using the current voltage, the
  remaining capacity and the current rate. It works on both charging and
  discharging state.

I attached the patch but I warn you that it has been generated using git
since I was unable to retrieve the bazar repository for the last two
days (it hangs during the download process). By the way, do you have any
advice which could help me ?

Please merge it or review it.

Best regards,

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: battery.el: Retrieve more information from sysfs patch --]
[-- Type: text/x-diff, Size: 3556 bytes --]

From 905c2ccd805bb6be0ed11e4f85f9baf316106da1 Mon Sep 17 00:00:00 2001
From: Jeremy Compostella <jeremy.compostella@gmail.com>
Date: Sun, 18 Dec 2011 19:38:29 +0100
Subject: [PATCH] battery.el: Retrieve more information from sysfs

The sysfs power_supply interface provides more information than the
ones retrieved for now. This patch adds the rate and temperature
properties. It provides the ability to estimate the remaining time too
using the current rate, the current voltage and the remaining capacity.
The time remaining estimation works on both charging and discharging
states.
---
 lisp/battery.el |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lisp/battery.el b/lisp/battery.el
index 3b245ed..b6b98d5 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -420,11 +420,16 @@ This function works only with the new `/sys/class/power_supply/'
 format introduced in Linux version 2.4.25.
 
 The following %-sequences are provided:
+%r Current rate
+%d Temperature (in degrees Celsius)
 %c Current capacity (mAh or mWh)
 %B Battery status (verbose)
 %p Battery load percentage
-%L AC line status (verbose)"
-  (let (charging-state
+%L AC line status (verbose)
+%m Remaining time (to charge or discharge) in minutes
+%h Remaining time (to charge or discharge) in hours
+%t Remaining time (to charge or discharge) in the form `h:min'"
+  (let (charging-state rate temperature hours
 	(charge-full 0.0)
 	(charge-now 0.0)
 	(energy-full 0.0)
@@ -444,6 +449,11 @@ The following %-sequences are provided:
 	  (and (re-search-forward "POWER_SUPPLY_STATUS=\\(.*\\)$" nil t)
 	       (member charging-state '("Unknown" "Full" nil))
 	       (setq charging-state (match-string 1)))
+	  (when (or (re-search-forward "POWER_SUPPLY_CURRENT_NOW=\\([0-9]*\\)$" nil t)
+		    (re-search-forward "POWER_SUPPLY_POWER_NOW=\\([0-9]*\\)$" nil t))
+	    (setq rate (float (string-to-number (match-string 1)))))
+	  (when (re-search-forward "POWER_SUPPLY_TEMP=\\([0-9]*\\)$" nil t)
+	    (setq temperature (match-string 1)))
 	  (let (full-string now-string)
 	    ;; Sysfs may list either charge (mAh) or energy (mWh).
 	    ;; Keep track of both, and choose which to report later.
@@ -466,12 +476,33 @@ The following %-sequences are provided:
 		   (setq energy-full (+ energy-full
 					(string-to-number full-string))
 			 energy-now  (+ energy-now
-					(string-to-number now-string)))))))))
+					(string-to-number now-string))))))
+	  (goto-char (point-min))
+	  (when (and energy-now rate (not (zerop rate))
+		     (re-search-forward "POWER_SUPPLY_VOLTAGE_NOW=\\([0-9]*\\)$" nil t))
+	    (let ((remaining (if (string= charging-state "Discharging")
+				 energy-now
+			       (- energy-full energy-now))))
+	      (setq hours (/ (/ (* remaining (string-to-number (match-string 1))) rate)
+			     10000000.0)))))))
     (list (cons ?c (cond ((or (> charge-full 0) (> charge-now 0))
 			  (number-to-string charge-now))
 			 ((or (> energy-full 0) (> energy-now 0))
 			  (number-to-string energy-now))
 			 (t "N/A")))
+	  (cons ?r (if rate
+		        (format "%.1f" (/ rate 1000000.0))
+		     "N/A"))
+	  (cons ?m (if hours
+		       (format "%d" (* hours 60))
+		     "N/A"))
+	  (cons ?h (if hours
+		       (format "%d" hours)
+		     "N/A"))
+	  (cons ?t (if hours
+		       (format "%d:%02d" hours (* (- hours (floor hours)) 60))
+		     "N/A"))
+	  (cons ?d (or temperature "N/A"))
 	  (cons ?B (or charging-state "N/A"))
 	  (cons ?p (cond ((> charge-full 0)
 			  (format "%.1f"
-- 
1.7.2.5


[-- Attachment #3: Type: text/plain, Size: 97 bytes --]


Jeremy

PS: I signed my Emacs assignment and post it by mail 10 days ago.
--
Sent from my Emacs

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-18 18:53 [PATCH] battery.el Retrieve more information from sysfs Jérémy Compostella
@ 2011-12-21 10:03 ` Jérémy Compostella
  2011-12-21 19:30   ` Karl Fogel
  2011-12-22 22:52 ` Stefan Monnier
  1 sibling, 1 reply; 10+ messages in thread
From: Jérémy Compostella @ 2011-12-21 10:03 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1757 bytes --]

All again,

I did not received any answers so I'm answering myself about :
- Do I miss something in the "submit" process,
- Is this patch is a mess ?
- Or maybe everybody is busy ...

So let me know,

Thanks,

Jeremy

2011/12/18 Jérémy Compostella <jeremy.compostella@gmail.com>

> All,
>
> I just bought a new laptop and installed a fresh Debian on it. I used to
> look at my current battery status using Emacs. I like to look at the
> current rate too since this laptop will be used during a long trip and I
> want to take care of the consumption in real time.
>
> The issue is that with the 2.6.32 kernel from Debian for this laptop I
> do not have the /proc/acpi/battery part. However, the sysfs is able to
> report all the data I need. The current Emacs battery module is not able
> to retrieve the information I need from sysfs but it does from
> /proc/acpi/battery. So I made a small evolution to enable the following:
>
> - Get the current rate
> - Get the current temperature (does not work on my laptop but the
>  power_supply interface is able to provide it, so I added it too.
> - Do the time remaining estimation using the current voltage, the
>  remaining capacity and the current rate. It works on both charging and
>  discharging state.
>
> I attached the patch but I warn you that it has been generated using git
> since I was unable to retrieve the bazar repository for the last two
> days (it hangs during the download process). By the way, do you have any
> advice which could help me ?
>
> Please merge it or review it.
>
> Best regards,
>
>
> Jeremy
>
> PS: I signed my Emacs assignment and post it by mail 10 days ago.
> --
> Sent from my Emacs
>
>
-- 
One Emacs to rule them all

[-- Attachment #2: Type: text/html, Size: 2118 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-21 10:03 ` Jérémy Compostella
@ 2011-12-21 19:30   ` Karl Fogel
  2011-12-22  0:08     ` Kan-Ru Chen
  2011-12-22 11:30     ` Roland Winkler
  0 siblings, 2 replies; 10+ messages in thread
From: Karl Fogel @ 2011-12-21 19:30 UTC (permalink / raw)
  To: Jérémy Compostella; +Cc: emacs-devel

Jérémy Compostella <jeremy.compostella@gmail.com> writes:
>I did not received any answers so I'm answering myself about :
>- Do I miss something in the "submit" process,
>- Is this patch is a mess ?
>- Or maybe everybody is busy ...

Jérémy, thanks for the patch.  I think it's just #3: everyone is busy.
Sometimes it can take a while.  In some cases, if the feature is not
compelling enough to others, there may be no useful response at all.
This doesn't mean it's a bad idea, it just means no one's convinced it's
needed.

Most people see battery status in an icon on their GUI toolbar, I
think.  Can you describe the use case(s) for battery.el?  Is it easier
for the visually impaired, for example?  Maybe for people who are
running their machine in text-console mode?

When do you use it?

Best,
-Karl

>So let me know,
>
>Thanks,
>
>Jeremy
>
>2011/12/18 Jérémy Compostella <jeremy.compostella@gmail.com>
>
>    All,
>    
>    I just bought a new laptop and installed a fresh Debian on it. I
>    used to
>    look at my current battery status using Emacs. I like to look at
>    the
>    current rate too since this laptop will be used during a long trip
>    and I
>    want to take care of the consumption in real time.
>    
>    The issue is that with the 2.6.32 kernel from Debian for this
>    laptop I
>    do not have the /proc/acpi/battery part. However, the sysfs is
>    able to
>    report all the data I need. The current Emacs battery module is
>    not able
>    to retrieve the information I need from sysfs but it does from
>    /proc/acpi/battery. So I made a small evolution to enable the
>    following:
>    
>    - Get the current rate
>    - Get the current temperature (does not work on my laptop but the
>     power_supply interface is able to provide it, so I added it too.
>    - Do the time remaining estimation using the current voltage, the
>     remaining capacity and the current rate. It works on both
>    charging and
>     discharging state.
>    
>    I attached the patch but I warn you that it has been generated
>    using git
>    since I was unable to retrieve the bazar repository for the last
>    two
>    days (it hangs during the download process). By the way, do you
>    have any
>    advice which could help me ?
>    
>    Please merge it or review it.
>    
>    Best regards,
>    
>    
>    Jeremy
>    
>    PS: I signed my Emacs assignment and post it by mail 10 days ago.
>    --
>    Sent from my Emacs



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-21 19:30   ` Karl Fogel
@ 2011-12-22  0:08     ` Kan-Ru Chen
  2011-12-22 10:18       ` Jérémy Compostella
  2011-12-22 11:30     ` Roland Winkler
  1 sibling, 1 reply; 10+ messages in thread
From: Kan-Ru Chen @ 2011-12-22  0:08 UTC (permalink / raw)
  To: Karl Fogel; +Cc: Jérémy Compostella, emacs-devel

Karl Fogel <kfogel@red-bean.com> writes:

> Jérémy Compostella <jeremy.compostella@gmail.com> writes:
>>I did not received any answers so I'm answering myself about :
>>- Do I miss something in the "submit" process,
>>- Is this patch is a mess ?
>>- Or maybe everybody is busy ...
>
> Jérémy, thanks for the patch.  I think it's just #3: everyone is busy.
> Sometimes it can take a while.  In some cases, if the feature is not
> compelling enough to others, there may be no useful response at all.
> This doesn't mean it's a bad idea, it just means no one's convinced it's
> needed.
>
> Most people see battery status in an icon on their GUI toolbar, I
> think.  Can you describe the use case(s) for battery.el?  Is it easier
> for the visually impaired, for example?  Maybe for people who are
> running their machine in text-console mode?

FYI, I have a script

--8<---------------cut here---------------start------------->8---
#!/bin/sh

if [ -S "/tmp/emacs`id -u`/server" ]; then
    emacsclient -n --eval '(battery)'
else
    echo "Cannot find emacs server socket";
fi
--8<---------------cut here---------------end--------------->8---

that I always use it to get the battery info. I'm using a minimalism
window manager that doesn't have battery widget by default.
 
-- 
Kanru



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-22  0:08     ` Kan-Ru Chen
@ 2011-12-22 10:18       ` Jérémy Compostella
  0 siblings, 0 replies; 10+ messages in thread
From: Jérémy Compostella @ 2011-12-22 10:18 UTC (permalink / raw)
  To: Kan-Ru Chen; +Cc: Karl Fogel, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2063 bytes --]

2011/12/22 Kan-Ru Chen <kanru@kanru.info>

> Karl Fogel <kfogel@red-bean.com> writes:
>
> > Jérémy Compostella <jeremy.compostella@gmail.com> writes:
> >>I did not received any answers so I'm answering myself about :
> >>- Do I miss something in the "submit" process,
> >>- Is this patch is a mess ?
> >>- Or maybe everybody is busy ...
> >
> > Jérémy, thanks for the patch.  I think it's just #3: everyone is busy.
> > Sometimes it can take a while.  In some cases, if the feature is not
> > compelling enough to others, there may be no useful response at all.
> > This doesn't mean it's a bad idea, it just means no one's convinced it's
> > needed.
> >
> > Most people see battery status in an icon on their GUI toolbar, I
> > think.  Can you describe the use case(s) for battery.el?  Is it easier
> > for the visually impaired, for example?  Maybe for people who are
> > running their machine in text-console mode?
>
> FYI, I have a script
>
> --8<---------------cut here---------------start------------->8---
> #!/bin/sh
>
> if [ -S "/tmp/emacs`id -u`/server" ]; then
>    emacsclient -n --eval '(battery)'
> else
>    echo "Cannot find emacs server socket";
> fi
> --8<---------------cut here---------------end--------------->8---
>
> that I always use it to get the battery info. I'm using a minimalism
> window manager that doesn't have battery widget by default.
>
> --
> Kanru
>

On my side, I used to be as independent as possible with the Window
Manager I use. Indeed, I run Emacs in real fullscreen mode doing almost
everything with it (code editing, compilation, debugging, jabber, web,
mail, ...). So, I do not have visibility on the potential battery
widget.

Moreover, for this laptop, I really do care about the instantaneous
consumption and this information is not retrieved from sysfs for
now. Only from the /proc/acpi part I do not have. Even with a fresh
3.2.0-rc6 freshly compiled, patched and optimized for my power
consumption needs.

Thanks,

Jeremy
-- 
One Emacs to rule them all

[-- Attachment #2: Type: text/html, Size: 2731 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-21 19:30   ` Karl Fogel
  2011-12-22  0:08     ` Kan-Ru Chen
@ 2011-12-22 11:30     ` Roland Winkler
  1 sibling, 0 replies; 10+ messages in thread
From: Roland Winkler @ 2011-12-22 11:30 UTC (permalink / raw)
  To: emacs-devel

On Wed, Dec 21 2011, Karl Fogel wrote:
> Most people see battery status in an icon on their GUI toolbar, I
> think.  Can you describe the use case(s) for battery.el?  Is it easier
> for the visually impaired, for example?  Maybe for people who are
> running their machine in text-console mode?
>
> When do you use it?

I am using battery.el all the time. Even though I have some icon for
this in the GUI toolbar, I would miss it too often. So the more
prominent display in the emacs mode line is the perfect place for me.

Roland




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-18 18:53 [PATCH] battery.el Retrieve more information from sysfs Jérémy Compostella
  2011-12-21 10:03 ` Jérémy Compostella
@ 2011-12-22 22:52 ` Stefan Monnier
  2011-12-23  3:59   ` Richard Stallman
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2011-12-22 22:52 UTC (permalink / raw)
  To: Jérémy Compostella; +Cc: emacs-devel

> The issue is that with the 2.6.32 kernel from Debian for this laptop I
> do not have the /proc/acpi/battery part. However, the sysfs is able to
> report all the data I need. The current Emacs battery module is not able
> to retrieve the information I need from sysfs but it does from
> /proc/acpi/battery. So I made a small evolution to enable the following:

Thanks, I installed it with a few cosmetic changes,


        Stefan



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-22 22:52 ` Stefan Monnier
@ 2011-12-23  3:59   ` Richard Stallman
  2011-12-23  4:38     ` Karl Fogel
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Stallman @ 2011-12-23  3:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: jeremy.compostella, emacs-devel

If this code keeps breaking, and we have to keep fixing it,
is that similar to the Greek myth of sysfs?

-- 
Dr Richard Stallman
President, Free Software Foundation
51 Franklin St
Boston MA 02110
USA
www.fsf.org  www.gnu.org
Skype: No way! That's nonfree (freedom-denying) software.
  Use free telephony http://directory.fsf.org/category/tel/



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-23  3:59   ` Richard Stallman
@ 2011-12-23  4:38     ` Karl Fogel
  2011-12-23  7:10       ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Karl Fogel @ 2011-12-23  4:38 UTC (permalink / raw)
  To: rms; +Cc: jeremy.compostella, Stefan Monnier, emacs-devel

Richard Stallman <rms@gnu.org> writes:
>If this code keeps breaking, and we have to keep fixing it,
>is that similar to the Greek myth of sysfs?

Well, under Hercules [1] it's stable, but only if you redirect the River
Styx through it...

Oh my.  I'm afraid this thread could go on for a very, very long time.

-Karl

[1] http://en.wikipedia.org/wiki/Hercules_%28emulator%29



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] battery.el Retrieve more information from sysfs
  2011-12-23  4:38     ` Karl Fogel
@ 2011-12-23  7:10       ` Bastien
  0 siblings, 0 replies; 10+ messages in thread
From: Bastien @ 2011-12-23  7:10 UTC (permalink / raw)
  To: Karl Fogel; +Cc: emacs-devel, jeremy.compostella, rms, Stefan Monnier

Karl Fogel <kfogel@red-bean.com> writes:

> Oh my.  I'm afraid this thread could go on for a very, very long time.

Especially if nothing pays attention to your prediction, Cassandra!

-- 
 Bastien



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-12-23  7:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-18 18:53 [PATCH] battery.el Retrieve more information from sysfs Jérémy Compostella
2011-12-21 10:03 ` Jérémy Compostella
2011-12-21 19:30   ` Karl Fogel
2011-12-22  0:08     ` Kan-Ru Chen
2011-12-22 10:18       ` Jérémy Compostella
2011-12-22 11:30     ` Roland Winkler
2011-12-22 22:52 ` Stefan Monnier
2011-12-23  3:59   ` Richard Stallman
2011-12-23  4:38     ` Karl Fogel
2011-12-23  7:10       ` Bastien

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.