Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Battery module doesn't work on desktop pc #24

Closed
lucashpandolfo opened this issue Jan 9, 2015 · 1 comment
Closed

Battery module doesn't work on desktop pc #24

lucashpandolfo opened this issue Jan 9, 2015 · 1 comment

Comments

@lucashpandolfo
Copy link

Ok, i know. But i share the same config between my desktop pc and notebook. current-battery-charge was signalling an error.

For it to behave properly i had to make some minor changes. A trivial fix would be:

--- battery.lisp.orig   2015-01-09 13:44:51.903697887 -0300
+++ battery.lisp        2014-12-30 10:01:10.207440102 -0300
@@ -33,7 +33,7 @@
             (let ((split (cl-ppcre:split ":\\s*" line)))
               (setf (gethash (string-trim '(#\Space) (car split)) fields)
                     (string-trim '(#\Space) (cadr split)))))
-          ""))))
+          (make-hash-table)))))

 (defun current-battery-charge ()
   "Calculate remaining battery charge. Don't make calculation more than once in 15 seconds."
@@ -45,11 +45,11 @@
         (if (string= "no" (gethash "present" battery-state))
             (setf *bat-state* nil)
             (let ((charge-state (gethash "charging state" battery-state))
-                  (remain (parse-integer (gethash "remaining capacity" battery-state)
+                  (remain (parse-integer (gethash "remaining capacity" battery-state "0")
                                          :junk-allowed t))
-                  (rate (/ (or (parse-integer (gethash "present rate" battery-state)
+                  (rate (/ (or (parse-integer (gethash "present rate" battery-state "0")
                                               :junk-allowed t) 0) 60))
-                  (full (parse-integer (gethash "last full capacity" battery-info)
+                  (full (parse-integer (gethash "last full capacity" battery-info "100")
                                        :junk-allowed t)))
               (setf *bat-remain* (round (/ (* 100 remain) full))
                     *bat-state* charge-state

Another possible solution would be to test the presence of a battery in fmt-bat-charge (maybe probing the file "/proc/acpi/battery/BAT0", the one the module uses), and then return an empty string (as to avoid the 'no battery' message on desktops modeline).

@dmb2
Copy link
Contributor

dmb2 commented Mar 25, 2015

sorry for the delay, can you resubmit this as a PR? I'm kind of allergic to patches.

dmb2 pushed a commit that referenced this issue Dec 12, 2016
@dmb2 dmb2 closed this as completed Dec 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants