41 lines
1.6 KiB
Common Lisp
Executable file
41 lines
1.6 KiB
Common Lisp
Executable file
#!/usr/bin/env -S sbcl --script
|
|
(require "uiop")
|
|
(load "/home/chris/.sbclrc")
|
|
(ql:quickload :serapeum)
|
|
|
|
(defun get-value (file)
|
|
"Read a file and get it's value as a list of lines"
|
|
(with-open-file (in file)
|
|
(loop for line = (read-line in nil nil)
|
|
while line
|
|
collect line)))
|
|
|
|
(defun close-eww ()
|
|
(uiop:run-program "eww close battery" :ignore-error-status t))
|
|
(defun open-eww ()
|
|
(uiop:run-program "eww open battery" :ignore-error-status t))
|
|
|
|
(defun clear-file (file)
|
|
(with-open-file (out file :direction :output :if-exists :overwrite :if-does-not-exist :create)
|
|
(write-sequence " " out))
|
|
(uiop:println "Clearing killed"))
|
|
|
|
(setf capacity (parse-integer (car (get-value "/sys/class/power_supply/BAT1/capacity"))))
|
|
(setf status (car (get-value "/sys/class/power_supply/BAT1/status")))
|
|
|
|
(loop do (progn
|
|
(sleep 10)
|
|
(format t "~&Charge: ~a, Status: ~a" capacity status)
|
|
(if (string= "Charging" status)
|
|
(progn (format t "~&Charging, closing EWW") (close-eww))
|
|
(if (<= capacity 30)
|
|
(progn (setf killed (serapeum:trim-whitespace (car (get-value "/tmp/ewwbattery"))))
|
|
(if killed
|
|
(progn (format t "~&EWW has been killed, waiting 3 minutes")
|
|
(clear-file #p"/tmp/ewwbattery")
|
|
(sleep 360)))
|
|
(format t "~&Opening EWW")
|
|
(open-eww))
|
|
(progn (format t "~&Charged more than 30%, Closing EWW")
|
|
(close-eww))))))
|