better battery monitor
This commit is contained in:
parent
186ae68b40
commit
ff34c93c1e
|
@ -4,37 +4,41 @@
|
||||||
(ql:quickload :serapeum)
|
(ql:quickload :serapeum)
|
||||||
|
|
||||||
(defun get-value (file)
|
(defun get-value (file)
|
||||||
"Read a file and get it's value as a list of lines"
|
"Read a file and get it's value as a string"
|
||||||
(with-open-file (in file)
|
(serapeum:trim-whitespace (uiop:read-file-string file)))
|
||||||
(loop for line = (read-line in nil nil)
|
|
||||||
while line
|
|
||||||
collect line)))
|
|
||||||
|
|
||||||
(defun close-eww ()
|
(defun close-eww ()
|
||||||
(uiop:run-program "eww close battery" :ignore-error-status t))
|
(run-program "eww" '("close" "battery") :search "/run/current-system/sw/bin/"))
|
||||||
(defun open-eww ()
|
(defun open-eww ()
|
||||||
(uiop:run-program "eww open battery" :ignore-error-status t))
|
(run-program "eww" '("open" "battery") :search "/run/current-system/sw/bin/"))
|
||||||
|
|
||||||
(defun clear-file (file)
|
(defun clear-file (file)
|
||||||
(with-open-file (out file :direction :output :if-exists :overwrite :if-does-not-exist :create)
|
(with-open-file (out file :direction :output :if-exists :supersede)
|
||||||
(write-sequence " " out))
|
(write-sequence " " out))
|
||||||
(uiop:println "Clearing killed"))
|
(format t "~&Clearing killed"))
|
||||||
|
|
||||||
(setf capacity (parse-integer (car (get-value "/sys/class/power_supply/BAT1/capacity"))))
|
(defun main ()
|
||||||
(setf status (car (get-value "/sys/class/power_supply/BAT1/status")))
|
(loop do (let ((capacity (parse-integer
|
||||||
|
(get-value "/sys/class/power_supply/BAT1/capacity")
|
||||||
(loop do (progn
|
:junk-allowed t))
|
||||||
(sleep 10)
|
(status (get-value "/sys/class/power_supply/BAT1/status")))
|
||||||
(format t "~&Charge: ~a, Status: ~a" capacity status)
|
(format t "~&Charge: ~a, Status: ~a" capacity status)
|
||||||
(if (string= "Charging" status)
|
(if (string= "Charging" status)
|
||||||
(progn (format t "~&Charging, closing EWW") (close-eww))
|
(progn
|
||||||
|
(format t "~&Charging, closing EWW")
|
||||||
|
(close-eww))
|
||||||
(if (<= capacity 30)
|
(if (<= capacity 30)
|
||||||
(progn (setf killed (serapeum:trim-whitespace (car (get-value "/tmp/ewwbattery"))))
|
(let ((killed (get-value "/tmp/ewwbattery")))
|
||||||
(if killed
|
(if (string= "killed" killed)
|
||||||
(progn (format t "~&EWW has been killed, waiting 3 minutes")
|
(progn
|
||||||
|
(format t "~&EWW has been killed, waiting 3 minutes")
|
||||||
(clear-file #p"/tmp/ewwbattery")
|
(clear-file #p"/tmp/ewwbattery")
|
||||||
(sleep 360)))
|
(sleep 350)))
|
||||||
(format t "~&Opening EWW")
|
(format t "~&Opening EWW")
|
||||||
(open-eww))
|
(open-eww))
|
||||||
(progn (format t "~&Charged more than 30%, Closing EWW")
|
(progn (format t "~&Charged more than 30%, Closing EWW")
|
||||||
(close-eww))))))
|
(clear-file #p"/tmp/ewwbattery")
|
||||||
|
(close-eww))))
|
||||||
|
(sleep 10))))
|
||||||
|
|
||||||
|
(main)
|
||||||
|
|
Loading…
Reference in a new issue