From: Joakim Jalap <joakim.jalap@fastmail.com>
To: Ignacio Torres <i@itorres.net>
Cc: 24919@debbugs.gnu.org
Subject: bug#24919: 24.5; battery.el not working in FreeBSD
Date: Fri, 11 Nov 2016 18:58:39 +0100 [thread overview]
Message-ID: <86twbd525s.fsf@fastmail.com> (raw)
In-Reply-To: <86lgyq2k1l.fsf@gaia.hq.xin.cat> (Ignacio Torres's message of "Sun, 18 Sep 2016 01:17:26 +0200")
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
Ignacio Torres <i@itorres.net> writes:
> Running M-x battery in FreeBSD returns:
>
> Power disconnected, battery high (illegal% load, remaining time 0:00)
>
Here's a patch witch makes it return something else :)
Unfortunately I can't tets it on an actual laptop atm, but I /think/ it
might work.
-- Joakim
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 2472 bytes --]
From 8af54346db52ce1939632a60cac0cbd5c5f77063 Mon Sep 17 00:00:00 2001
From: Joakim Jalap <joakim.jalap@fastmail.com>
Date: Fri, 11 Nov 2016 18:00:22 +0100
Subject: [PATCH] Fix M-x battery on FreeBSD
* lisp/battery.el (battery-bsd-apm): Fix to work with FreeBSD's apm(8)
---
lisp/battery.el | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/lisp/battery.el b/lisp/battery.el
index e6e79b0..ddb0114 100644
--- a/lisp/battery.el
+++ b/lisp/battery.el
@@ -552,30 +552,40 @@ battery-bsd-apm
%t Remaining battery charge time in the form `h:min'"
(let* ((os-name (car (split-string
(shell-command-to-string "/usr/bin/uname"))))
- (apm-flag (if (equal os-name "OpenBSD") "P" "s"))
- (apm-cmd (concat "/usr/sbin/apm -ablm" apm-flag))
+ (os-freebsd (string= os-name "FreeBSD"))
+ (os-openbsd (string= os-name "OpenBSD"))
+ (battery-status-idx (if os-freebsd 1 0))
+ (percentage-idx (if os-freebsd 2 1))
+ (life-idx (if os-freebsd 4 2))
+ (line-status-idx (if os-freebsd 0 3))
+ (mode-idx (if os-freebsd 3 4))
+ (apm-flags
+ (cond (os-freebsd "-ablts")
+ (os-openbsd "-ablmP")
+ (t "-ablms")))
+ (apm-cmd (concat "/usr/sbin/apm " apm-flags))
(apm-output (split-string (shell-command-to-string apm-cmd)))
;; Battery status
(battery-status
- (let ((stat (string-to-number (nth 0 apm-output))))
+ (let ((stat (string-to-number (nth battery-status-idx apm-output))))
(cond ((eq stat 0) '("high" . ""))
((eq stat 1) '("low" . "-"))
((eq stat 2) '("critical" . "!"))
((eq stat 3) '("charging" . "+"))
((eq stat 4) '("absent" . nil)))))
;; Battery percentage
- (battery-percentage (nth 1 apm-output))
+ (battery-percentage (nth percentage-idx apm-output))
;; Battery life
- (battery-life (nth 2 apm-output))
+ (battery-life (nth life-idx apm-output))
;; AC status
(line-status
- (let ((ac (string-to-number (nth 3 apm-output))))
+ (let ((ac (string-to-number (nth line-status-idx apm-output))))
(cond ((eq ac 0) "disconnected")
((eq ac 1) "connected")
((eq ac 2) "backup power"))))
;; Advanced power savings mode
(apm-mode
- (let ((apm (string-to-number (nth 4 apm-output))))
+ (let ((apm (string-to-number (nth mode-idx apm-output))))
(if (string= os-name "OpenBSD")
(cond ((eq apm 0) "manual")
((eq apm 1) "automatic")
--
2.9.2
next prev parent reply other threads:[~2016-11-11 17:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-17 23:17 bug#24919: 24.5; battery.el not working in FreeBSD Ignacio Torres
2016-11-11 17:58 ` Joakim Jalap [this message]
2017-03-08 13:58 ` Alan Third
2019-10-14 20:16 ` Joseph Mingrone
2019-10-15 6:45 ` Stefan Kangas
2019-11-11 3:26 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86twbd525s.fsf@fastmail.com \
--to=joakim.jalap@fastmail.com \
--cc=24919@debbugs.gnu.org \
--cc=i@itorres.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.