Last active
August 29, 2015 13:56
-
-
Save whyrusleeping/9130317 to your computer and use it in GitHub Desktop.
Possible implementation of my chromebook battery widget for awesome 3.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| batwidget = widget({ type = "textbox" }) | |
| function readnumber(path) | |
| local f = io.open(path,"r") | |
| return tonumber(f:read("*number")) | |
| end | |
| function batwidget.updateDisplay() | |
| local timeleft = readnumber("/sys/class/power_supply/sbs-4-000b/time_to_empty_avg") | |
| timeleft = timeleft / 60 | |
| local percent = readnumber("/sys/class/power_supply/sbs-4-000b/charge_now") / readnumber("/sys/class/power_supply/sbs-4-000b/charge_full") | |
| local timestr = "" | |
| if timeleft > 2000 then | |
| timestr = "charging" | |
| else | |
| timestr = string.format(timeleft .. "mins") | |
| end | |
| batwidget.text = "Batt: " .. string.format("%.2f",(100 * percent)) .. "% " .. timestr | |
| end | |
| battimer = timer({timeout = 10}) | |
| battimer:connect_signal("timeout", batwidget.updateDisplay) | |
| battimer:start() | |
| batwidget.updateDisplay() | |
| . | |
| . | |
| . | |
| -- Wherever you are adding widgets: add batwidget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment