comparison lisp/battery.el @ 63899:1f503fd2046d

(battery-linux-proc-apm): Fix typo in docstring. Catch errors with ignore-errors. Use temporary buffer. (battery-linux-proc-acpi): Fix typo in docstring. Document `%r'.
author Lute Kamstra <lute@gnu.org>
date Fri, 01 Jul 2005 11:02:16 +0000
parents abd0d265b4ba
children 6fb026ad601f
comparison
equal deleted inserted replaced
63898:0a239ad4f060 63899:1f503fd2046d
169 %I APM BIOS status (verbose) 169 %I APM BIOS status (verbose)
170 %L AC line status (verbose) 170 %L AC line status (verbose)
171 %B Battery status (verbose) 171 %B Battery status (verbose)
172 %b Battery status, empty means high, `-' means low, 172 %b Battery status, empty means high, `-' means low,
173 `!' means critical, and `+' means charging 173 `!' means critical, and `+' means charging
174 %p battery load percentage 174 %p Battery load percentage
175 %s Remaining time in seconds 175 %s Remaining time in seconds
176 %m Remaining time in minutes 176 %m Remaining time in minutes
177 %h Remaining time in hours 177 %h Remaining time in hours
178 %t Remaining time in the form `h:min'" 178 %t Remaining time in the form `h:min'"
179 (let (driver-version bios-version bios-interface line-status 179 (let (driver-version bios-version bios-interface line-status
180 battery-status battery-status-symbol load-percentage 180 battery-status battery-status-symbol load-percentage
181 seconds minutes hours remaining-time buffer tem) 181 seconds minutes hours remaining-time tem)
182 (unwind-protect 182 (with-temp-buffer
183 (save-excursion 183 (ignore-errors (insert-file-contents "/proc/apm"))
184 (setq buffer (get-buffer-create " *battery*")) 184 (when (re-search-forward battery-linux-proc-apm-regexp)
185 (set-buffer buffer) 185 (setq driver-version (match-string 1))
186 (erase-buffer) 186 (setq bios-version (match-string 2))
187 (insert-file-contents "/proc/apm") 187 (setq tem (string-to-number (match-string 3) 16))
188 (re-search-forward battery-linux-proc-apm-regexp) 188 (if (not (logand tem 2))
189 (setq driver-version (match-string 1)) 189 (setq bios-interface "not supported")
190 (setq bios-version (match-string 2)) 190 (setq bios-interface "enabled")
191 (setq tem (string-to-number (match-string 3) 16)) 191 (cond ((logand tem 16) (setq bios-interface "disabled"))
192 (if (not (logand tem 2)) 192 ((logand tem 32) (setq bios-interface "disengaged")))
193 (setq bios-interface "not supported") 193 (setq tem (string-to-number (match-string 4) 16))
194 (setq bios-interface "enabled") 194 (cond ((= tem 0) (setq line-status "off-line"))
195 (cond ((logand tem 16) (setq bios-interface "disabled")) 195 ((= tem 1) (setq line-status "on-line"))
196 ((logand tem 32) (setq bios-interface "disengaged"))) 196 ((= tem 2) (setq line-status "on backup")))
197 (setq tem (string-to-number (match-string 4) 16)) 197 (setq tem (string-to-number (match-string 6) 16))
198 (cond ((= tem 0) (setq line-status "off-line")) 198 (if (= tem 255)
199 ((= tem 1) (setq line-status "on-line")) 199 (setq battery-status "N/A")
200 ((= tem 2) (setq line-status "on backup"))) 200 (setq tem (string-to-number (match-string 5) 16))
201 (setq tem (string-to-number (match-string 6) 16)) 201 (cond ((= tem 0) (setq battery-status "high"
202 (if (= tem 255) 202 battery-status-symbol ""))
203 (setq battery-status "N/A") 203 ((= tem 1) (setq battery-status "low"
204 (setq tem (string-to-number (match-string 5) 16)) 204 battery-status-symbol "-"))
205 (cond ((= tem 0) (setq battery-status "high" 205 ((= tem 2) (setq battery-status "critical"
206 battery-status-symbol "")) 206 battery-status-symbol "!"))
207 ((= tem 1) (setq battery-status "low" 207 ((= tem 3) (setq battery-status "charging"
208 battery-status-symbol "-")) 208 battery-status-symbol "+")))
209 ((= tem 2) (setq battery-status "critical" 209 (setq load-percentage (match-string 7))
210 battery-status-symbol "!")) 210 (setq seconds (string-to-number (match-string 8)))
211 ((= tem 3) (setq battery-status "charging" 211 (and (string-equal (match-string 9) "min")
212 battery-status-symbol "+"))) 212 (setq seconds (* 60 seconds)))
213 (setq load-percentage (match-string 7)) 213 (setq minutes (/ seconds 60)
214 (setq seconds (string-to-number (match-string 8))) 214 hours (/ seconds 3600))
215 (and (string-equal (match-string 9) "min") 215 (setq remaining-time
216 (setq seconds (* 60 seconds))) 216 (format "%d:%02d" hours (- minutes (* 60 hours))))))))
217 (setq minutes (/ seconds 60)
218 hours (/ seconds 3600))
219 (setq remaining-time
220 (format "%d:%02d" hours (- minutes (* 60 hours))))))))
221 (list (cons ?v (or driver-version "N/A")) 217 (list (cons ?v (or driver-version "N/A"))
222 (cons ?V (or bios-version "N/A")) 218 (cons ?V (or bios-version "N/A"))
223 (cons ?I (or bios-interface "N/A")) 219 (cons ?I (or bios-interface "N/A"))
224 (cons ?L (or line-status "N/A")) 220 (cons ?L (or line-status "N/A"))
225 (cons ?B (or battery-status "N/A")) 221 (cons ?B (or battery-status "N/A"))
238 This function works only with the new `/proc/acpi/' format introduced 234 This function works only with the new `/proc/acpi/' format introduced
239 in Linux version 2.4.20 and 2.6.0. 235 in Linux version 2.4.20 and 2.6.0.
240 236
241 The following %-sequences are provided: 237 The following %-sequences are provided:
242 %c Current capacity (mAh) 238 %c Current capacity (mAh)
239 %r Current rate
243 %B Battery status (verbose) 240 %B Battery status (verbose)
244 %b Battery status, empty means high, `-' means low, 241 %b Battery status, empty means high, `-' means low,
245 `!' means critical, and `+' means charging 242 `!' means critical, and `+' means charging
246 %d Temperature (in degrees Celsius) 243 %d Temperature (in degrees Celsius)
247 %L AC line status (verbose) 244 %L AC line status (verbose)
248 %p battery load percentage 245 %p Battery load percentage
249 %m Remaining time in minutes 246 %m Remaining time in minutes
250 %h Remaining time in hours 247 %h Remaining time in hours
251 %t Remaining time in the form `h:min'" 248 %t Remaining time in the form `h:min'"
252 (let ((design-capacity 0) 249 (let ((design-capacity 0)
253 (warn 0) 250 (warn 0)