Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
30710442
Commit
30710442
authored
Jan 02, 2012
by
Richard M. Stallman
Browse files
Handle battery capacity on Lemote Yeeloong.
parent
f75bfc33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
2 deletions
+99
-2
lisp/ChangeLog
lisp/ChangeLog
+8
-0
lisp/battery.el
lisp/battery.el
+91
-2
No files found.
lisp/ChangeLog
View file @
30710442
2012-01-02 Richard Stallman <rms@gnu.org>
* battery.el (battery-status-function):
Detect when to use battery-yeeloong-sysfs.
(battery-echo-area-format): Add string for Yeeloong.
(battery-linux-proc-apm, battery-linux-proc-acpi): Doc fixes.
(battery-yeeloong-sysfs): New function.
2012-01-02 Chong Yidong <cyd@gnu.org>
* dirtrack.el (dirtrack-list): Eliminate unused third element.
...
...
lisp/battery.el
View file @
30710442
...
...
@@ -50,6 +50,10 @@
(
file-directory-p
"/sys/class/power_supply/"
)
(
directory-files
"/sys/class/power_supply/"
nil
"BAT[0-9]$"
))
'battery-linux-sysfs
)
((
and
(
eq
system-type
'gnu/linux
)
(
file-directory-p
"/sys/class/power_supply/yeeloong-bat/"
)
(
directory-files
"/sys/class/power_supply/yeeloong-bat/"
nil
"charge_"
))
'battery-yeeloong-sysfs
)
((
and
(
eq
system-type
'darwin
)
(
condition-case
nil
(
with-temp-buffer
...
...
@@ -77,6 +81,8 @@ introduced by a `%' character in a control string."
"Power %L, battery %B (%p%% load)"
)
((
eq
battery-status-function
'battery-pmset
)
"%L power, battery %B (%p%% load, remaining time %t)"
)
((
eq
battery-status-function
'battery-yeeloong-sysfs
)
"%L power, battery %B (%p%% load, remaining time %t)"
)
(
battery-status-function
"Power %L, battery %B (%p%% load, remaining time %t)"
))
"Control string formatting the string to display in the echo area.
...
...
@@ -226,7 +232,7 @@ seconds."
"Regular expression matching contents of `/proc/apm'."
)
(
defun
battery-linux-proc-apm
()
"Get APM status information from Linux kernel.
"Get APM status information from Linux
(the
kernel
)
.
This function works only with the new `/proc/apm' format introduced
in Linux version 1.3.58.
...
...
@@ -297,7 +303,7 @@ The following %-sequences are provided:
;;; `/proc/acpi/' interface for Linux.
(
defun
battery-linux-proc-acpi
()
"Get ACPI status information from Linux kernel.
"Get ACPI status information from Linux
(the
kernel
)
.
This function works only with the `/proc/acpi/' format introduced
in Linux version 2.4.20 and 2.6.0.
...
...
@@ -518,7 +524,90 @@ The following %-sequences are provided:
"BAT"
)
"N/A"
)))))
(
defun
battery-yeeloong-sysfs
()
"Get ACPI status information from Linux (the kernel).
This function works only on the Lemote Yeeloong.
The following %-sequences are provided:
%c Current capacity (mAh)
%r Current rate
%B Battery status (verbose)
%b Battery status, empty means high, `-' means low,
`!' means critical, and `+' means charging
%L AC line status (verbose)
%p Battery load percentage
%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
(
capacity
capacity-level
status
ac-online
hours
current-now
charge-full
charge-now
)
(
with-temp-buffer
(
ignore-errors
(
insert-file-contents
"/sys/class/power_supply/yeeloong-bat/uevent"
)
(
goto-char
1
)
(
search-forward
"POWER_SUPPLY_CHARGE_NOW="
)
(
setq
charge-now
(
read
(
current-buffer
)))
(
goto-char
1
)
(
search-forward
"POWER_SUPPLY_CHARGE_FULL="
)
(
setq
charge-full
(
read
(
current-buffer
)))
(
goto-char
1
)
(
search-forward
"POWER_SUPPLY_CURRENT_NOW="
)
(
setq
current-now
(
read
(
current-buffer
)))
(
goto-char
1
)
(
search-forward
"POWER_SUPPLY_CAPACITY_LEVEL="
)
(
setq
capacity-level
(
buffer-substring
(
point
)
(
line-end-position
)))
(
goto-char
1
)
(
search-forward
"POWER_SUPPLY_STATUS="
)
(
setq
status
(
buffer-substring
(
point
)
(
line-end-position
))))
(
erase-buffer
)
(
ignore-errors
(
insert-file-contents
"/sys/class/power_supply/yeeloong-ac/online"
)
(
goto-char
1
)
(
setq
ac-online
(
read
(
current-buffer
)))
(
erase-buffer
)))
(
setq
capacity
(
round
(
/
(
*
charge-now
100.0
)
charge-full
)))
(
when
(
and
current-now
(
not
(
=
current-now
0
)))
(
if
(
<
current-now
0
)
;; Charging
(
setq
hours
(
/
(
-
charge-now
charge-full
)
(
+
0.0
current-now
)))
;; Discharging
(
setq
hours
(
/
charge-now
(
+
0.0
current-now
)))))
(
list
(
cons
?c
(
if
charge-now
(
number-to-string
charge-now
)
"N/A"
))
(
cons
?r
current-now
)
(
cons
?B
(
cond
((
equal
capacity-level
"Full"
)
"full"
)
((
equal
status
"Charging"
)
"charging"
)
((
equal
capacity-level
"Low"
)
"low"
)
((
equal
capacity-level
"Critical"
)
"critical"
)
(
t
"high"
)))
(
cons
?b
(
cond
((
equal
capacity-level
"Full"
)
" "
)
((
equal
status
"Charging"
)
"+"
)
((
equal
capacity-level
"Low"
)
"-"
)
((
equal
capacity-level
"Critical"
)
"!"
)
(
t
" "
)))
(
cons
?h
(
if
hours
(
number-to-string
hours
)
"N/A"
))
(
cons
?m
(
if
hours
(
number-to-string
(
*
60
hours
))
"N/A"
))
(
cons
?t
(
if
hours
(
format
"%d:%d"
(
/
(
round
(
*
60
hours
))
60
)
(
%
(
round
(
*
60
hours
))
60
))
"N/A"
))
(
cons
?p
(
if
capacity
(
number-to-string
capacity
)
"N/A"
))
(
cons
?L
(
if
(
eq
ac-online
1
)
"AC"
"BAT"
)))))
;;; `pmset' interface for Darwin (OS X).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment