unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#41542: Implement %b status to battery-linux-sysfs in emacs 26.3 (with better percentage-now treatment)
@ 2020-05-26 14:22 Ellington Santos
  2020-05-26 14:37 ` bug#41542: Diff patch wrong in my last post. Follow right one Ellington Santos
  0 siblings, 1 reply; 3+ messages in thread
From: Ellington Santos @ 2020-05-26 14:22 UTC (permalink / raw)
  To: 41542

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

This patch implements %b battery status to battery-linux-sysfs in 
emacs-26.3 battery.el


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: battery_sysfs_b_status.patch --]
[-- Type: text/x-patch, Size: 1766 bytes --]

diff --git a/lisp/battery.el b/lisp/battery.el
index e23dab4c91..b5c12653e1 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -433,13 +433,15 @@ The following %-sequences are provided:
 %c Current capacity (mAh or mWh)
 %r Current rate
 %B Battery status (verbose)
+%b Battery status, empty means high, `-' means low,
+   `!' means critical, and `+' means charging
 %d Temperature (in degrees Celsius)
 %p Battery load percentage
 %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 temperature hours
+  (let (charging-state temperature hours percentage-now
         ;; Some batteries report charges and current, other energy and power.
         ;; In order to reliably be able to combine those data, we convert them
         ;; all to energy/power (since we can't combine different charges if
@@ -522,10 +524,13 @@ The following %-sequences are provided:
 		     "N/A"))
 	  (cons ?d (or temperature "N/A"))
 	  (cons ?B (or charging-state "N/A"))
-	  (cons ?p (cond ((and (> energy-full 0) (> energy-now 0))
-			  (format "%.1f"
-				  (/ (* 100 energy-now) energy-full)))
-			 (t "N/A")))
+	  (cons ?b (or (and (string= charging-state "Charging") "+")
+		       (and percentage-now (< percentage-now battery-load-critical) "!")
+		       (and percentage-now (< percentage-now battery-load-low) "-")
+		       ""))
+	  (cons ?p (cond
+                    ((and percentage-now (format "%.1f" percentage-now)))
+                    (t "N/A")))
 	  (cons ?L (cond
                     ((battery-search-for-one-match-in-files
                       (list "/sys/class/power_supply/AC/online"

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



-- 

Atenciosamente,

Ellington Santos

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

* bug#41542: Diff patch wrong in my last post. Follow right one
  2020-05-26 14:22 bug#41542: Implement %b status to battery-linux-sysfs in emacs 26.3 (with better percentage-now treatment) Ellington Santos
@ 2020-05-26 14:37 ` Ellington Santos
  2020-06-06  7:58   ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Ellington Santos @ 2020-05-26 14:37 UTC (permalink / raw)
  To: 41542

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: battery_sysfs_b_status.patch --]
[-- Type: text/x-patch, Size: 2188 bytes --]

diff --git a/lisp/battery.el b/lisp/battery.el
index e23dab4c91..309f43f8cd 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -433,13 +433,15 @@ The following %-sequences are provided:
 %c Current capacity (mAh or mWh)
 %r Current rate
 %B Battery status (verbose)
+%b Battery status, empty means high, `-' means low,
+   `!' means critical, and `+' means charging
 %d Temperature (in degrees Celsius)
 %p Battery load percentage
 %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 temperature hours
+  (let (charging-state temperature hours percentage-now
         ;; Some batteries report charges and current, other energy and power.
         ;; In order to reliably be able to combine those data, we convert them
         ;; all to energy/power (since we can't combine different charges if
@@ -509,6 +511,8 @@ The following %-sequences are provided:
 				 energy-now
 			       (- energy-full energy-now))))
 	      (setq hours (/ remaining power-now)))))))
+    (when (and (> energy-full 0) (> energy-now 0))
+      (setq percentage-now (/ (* 100 energy-now) energy-full)))
     (list (cons ?c (cond ((or (> energy-full 0) (> energy-now 0))
 			  (number-to-string (/ energy-now voltage-now)))
 			 (t "N/A")))
@@ -522,10 +526,13 @@ The following %-sequences are provided:
 		     "N/A"))
 	  (cons ?d (or temperature "N/A"))
 	  (cons ?B (or charging-state "N/A"))
-	  (cons ?p (cond ((and (> energy-full 0) (> energy-now 0))
-			  (format "%.1f"
-				  (/ (* 100 energy-now) energy-full)))
-			 (t "N/A")))
+	  (cons ?b (or (and (string= charging-state "Charging") "+")
+		       (and percentage-now (< percentage-now battery-load-critical) "!")
+		       (and percentage-now (< percentage-now battery-load-low) "-")
+		       ""))
+	  (cons ?p (cond
+                    ((and percentage-now (format "%.1f" percentage-now)))
+                    (t "N/A")))
 	  (cons ?L (cond
                     ((battery-search-for-one-match-in-files
                       (list "/sys/class/power_supply/AC/online"

[-- Attachment #2: Type: text/plain, Size: 40 bytes --]


-- 

Atenciosamente,

Ellington Santos

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

* bug#41542: Diff patch wrong in my last post. Follow right one
  2020-05-26 14:37 ` bug#41542: Diff patch wrong in my last post. Follow right one Ellington Santos
@ 2020-06-06  7:58   ` Eli Zaretskii
  0 siblings, 0 replies; 3+ messages in thread
From: Eli Zaretskii @ 2020-06-06  7:58 UTC (permalink / raw)
  To: Ellington Santos; +Cc: 41542-done

> From: Ellington Santos <ellingtonsantos@gmail.com>
> Date: Tue, 26 May 2020 11:37:04 -0300
> 
> diff --git a/lisp/battery.el b/lisp/battery.el
> index e23dab4c91..309f43f8cd 100644
> --- a/lisp/battery.el
> +++ b/lisp/battery.el

Thanks, I installed this on the master branch.

In the future, please also provide a ChangeLog-style commit log
message, as described in CONTRIBUTE.





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

end of thread, other threads:[~2020-06-06  7:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 14:22 bug#41542: Implement %b status to battery-linux-sysfs in emacs 26.3 (with better percentage-now treatment) Ellington Santos
2020-05-26 14:37 ` bug#41542: Diff patch wrong in my last post. Follow right one Ellington Santos
2020-06-06  7:58   ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).