all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#25074: Very fast battery status function using upowerd
@ 2016-11-30 11:53 Evgeny Zajcev
  2016-11-30 16:46 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeny Zajcev @ 2016-11-30 11:53 UTC (permalink / raw)
  To: 25074

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

Hello, here is very fast dbus based battery status function, implemented
using upower interface.  Could you please include it in battery.el ?

https://github.com/zevlg/emacs/commit/fdd371ca88e55895b1cf8b93165b6680dd1ec9f0


Thanks

-- 
lg

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

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

* bug#25074: Very fast battery status function using upowerd
  2016-11-30 11:53 bug#25074: Very fast battery status function using upowerd Evgeny Zajcev
@ 2016-11-30 16:46 ` Eli Zaretskii
  2016-11-30 16:50   ` Evgeny Zajcev
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2016-11-30 16:46 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: 25074

> From: Evgeny Zajcev <lg.zevlg@gmail.com>
> Date: Wed, 30 Nov 2016 14:53:16 +0300
> 
> Hello, here is very fast dbus based battery status function, implemented
> using upower interface. Could you please include it in battery.el ?
> 
> https://github.com/zevlg/emacs/commit/fdd371ca88e55895b1cf8b93165b6680dd1ec9f0

Thanks, but could you please include the patch with your message
posted here?  "git format-patch" is fine.  That would make applying
the patch easier.





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

* bug#25074: Very fast battery status function using upowerd
  2016-11-30 16:46 ` Eli Zaretskii
@ 2016-11-30 16:50   ` Evgeny Zajcev
  2016-12-02 10:19     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Evgeny Zajcev @ 2016-11-30 16:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 25074


[-- Attachment #1.1: Type: text/plain, Size: 576 bytes --]

2016-11-30 19:46 GMT+03:00 Eli Zaretskii <eliz@gnu.org>:

> > From: Evgeny Zajcev <lg.zevlg@gmail.com>
> > Date: Wed, 30 Nov 2016 14:53:16 +0300
> >
> > Hello, here is very fast dbus based battery status function, implemented
> > using upower interface. Could you please include it in battery.el ?
> >
> > https://github.com/zevlg/emacs/commit/fdd371ca88e55895b1cf8b93165b66
> 80dd1ec9f0
>
> Thanks, but could you please include the patch with your message
> posted here?  "git format-patch" is fine.  That would make applying
> the patch easier.
>

aha, here you are

-- 
lg

[-- Attachment #1.2: Type: text/html, Size: 1230 bytes --]

[-- Attachment #2: 0001-lisp-battery.el-Add-battery-upower-very-fast-battery.patch --]
[-- Type: text/x-patch, Size: 3762 bytes --]

From fdd371ca88e55895b1cf8b93165b6680dd1ec9f0 Mon Sep 17 00:00:00 2001
From: Zajcev Evgeny <zevlg@yandex.ru>
Date: Wed, 30 Nov 2016 14:49:29 +0300
Subject: [PATCH] * lisp/battery.el: Add `battery-upower' - very fast battery
 status   function using upowerd

---
 lisp/battery.el | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/lisp/battery.el b/lisp/battery.el
index 24eb8a5..8e1e7e0 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -45,6 +45,11 @@
   :type 'regexp
   :group 'battery)
 
+(defcustom battery-upower-device "battery_BAT1"
+  "*Upower battery device name."
+  :type 'string
+  :group 'battery)
+
 (defcustom battery-status-function
   (cond ((and (eq system-type 'gnu/linux)
 	      (file-readable-p "/proc/apm"))
@@ -536,6 +541,69 @@ The following %-sequences are provided:
                     (t "N/A"))))))
 
 \f
+;;; `upowerd' interface.
+(defsubst battery-upower-prop (pname &optional device)
+  (dbus-get-property
+   :system
+   "org.freedesktop.UPower"
+   (concat "/org/freedesktop/UPower/devices/" (or device battery-upower-device))
+   "org.freedesktop.UPower"
+   pname))
+
+(defun battery-upower ()
+  "Get battery status from dbus Upower interface.
+This function works only in systems with `upowerd' daemon
+running.
+
+The following %-sequences are provided:
+%c Current capacity (mWh)
+%p Battery load percentage
+%r Current rate
+%B Battery status (verbose)
+%L AC line status (verbose)
+%s Remaining time (to charge or discharge) in seconds
+%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 ((percents (battery-upower-prop "Percentage"))
+        (time-to-empty (battery-upower-prop "TimeToEmpty"))
+        (time-to-full (battery-upower-prop "TimeToFull"))
+        (state (battery-upower-prop "State"))
+        (online (battery-upower-prop "Online" "line_power_ACAD"))
+        (energy (battery-upower-prop "Energy"))
+        (energy-rate (battery-upower-prop "EnergyRate"))
+        (battery-states '((0 . "unknown") (1 . "charging")
+                          (2 . "discharging") (3 . "empty")
+                          (4 . "fully-charged") (5 . "pending-charge")
+                          (6 . "pending-discharge")))
+        seconds minutes hours remaining-time)
+    (cond ((and online time-to-full)
+           (setq seconds time-to-full))
+          ((and (not online) time-to-empty)
+           (setq seconds time-to-empty)))
+    (when seconds
+      (setq minutes (/ seconds 60)
+            hours (/ minutes 60)
+            remaining-time
+            (format "%d:%02d" (truncate hours)
+                    (- (truncate minutes) (* 60 (truncate hours))))))
+    (list (cons ?c (or (and energy
+                            (number-to-string (round (* 1000 energy))))
+                       "N/A"))
+          (cons ?p (or (and percents (number-to-string (round percents)))
+                       "N/A"))
+          (cons ?r (or (and energy-rate
+                            (concat (number-to-string energy-rate) " W"))
+                       "N/A"))
+          (cons ?B (or (and state (cdr (assoc state battery-states)))
+                       "unknown"))
+          (cons ?L (or (and online "on-line") "off-line"))
+          (cons ?s (or (and seconds (number-to-string seconds)) "N/A"))
+          (cons ?m (or (and minutes (number-to-string minutes)) "N/A"))
+          (cons ?h (or (and hours (number-to-string hours)) "N/A"))
+          (cons ?t (or remaining-time "N/A")))))
+
+\f
 ;;; `apm' interface for BSD.
 (defun battery-bsd-apm ()
   "Get APM status information from BSD apm binary.
-- 
2.7.4


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

* bug#25074: Very fast battery status function using upowerd
  2016-11-30 16:50   ` Evgeny Zajcev
@ 2016-12-02 10:19     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2016-12-02 10:19 UTC (permalink / raw)
  To: Evgeny Zajcev; +Cc: 25074-done

> From: Evgeny Zajcev <lg.zevlg@gmail.com>
> Date: Wed, 30 Nov 2016 19:50:58 +0300
> Cc: 25074@debbugs.gnu.org
> 
> 2016-11-30 19:46 GMT+03:00 Eli Zaretskii <eliz@gnu.org>:
> 
>  > From: Evgeny Zajcev <lg.zevlg@gmail.com>
>  > Date: Wed, 30 Nov 2016 14:53:16 +0300
>  >
>  > Hello, here is very fast dbus based battery status function, implemented
>  > using upower interface. Could you please include it in battery.el ?
>  >
>  > https://github.com/zevlg/emacs/commit/fdd371ca88e55895b1cf8b93165b6680dd1ec9f0
> 
>  Thanks, but could you please include the patch with your message
>  posted here? "git format-patch" is fine. That would make applying
>  the patch easier.
> 
> aha, here you are

Thanks, pushed to master.

In the future, please remember to put the ':version' tag in the new
defcustoms you introduce.





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

end of thread, other threads:[~2016-12-02 10:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-30 11:53 bug#25074: Very fast battery status function using upowerd Evgeny Zajcev
2016-11-30 16:46 ` Eli Zaretskii
2016-11-30 16:50   ` Evgeny Zajcev
2016-12-02 10:19     ` Eli Zaretskii

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.