Skip to content
Snippets Groups Projects
Commit 96b84fce authored by pharook's avatar pharook
Browse files

Updated to take care of more batteries, no fixed paths

parent 7e649e75
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ import datetime
import time
import select
import os.path as path
import glob
from operator import itemgetter
import ipc
import alsaaudio
......@@ -65,42 +66,65 @@ def main(argv=None):
# But Pulse shifts Alsa Master, so this is good enough
# However, Pulse does not use Alsa mute knob, so that will
# work only on Alsa
mixer = alsaaudio.Mixer()
mix_vol = mixer.getvolume()[0]
mix_mute = bool(mixer.getmute()[0])
mix_chars = u" ▁▂▃▄▅▆▇█"
mix_chars_scale = mix_vol*8//100
out.append({
u"name": u"volume",
u"full_text": u"♪%s" % mix_chars[mix_chars_scale],
u"color": u"#666666" if mix_mute else u"#6666FF"
})
# Battery
try:
batt_sys_path = "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0"
ac_sys_path = "/sys/bus/acpi/drivers/ac/ACPI0003:00/power_supply/AC"
batt_max = int(open(path.join(batt_sys_path, "charge_full"), "r").read())
batt_now = int(open(path.join(batt_sys_path, "charge_now"), "r").read())
batt_status = open(path.join(batt_sys_path, "status"), "r").read().strip()
ac_online = int(open(path.join(ac_sys_path, "online"), "r").read())
if batt_status=="Charging":
batt_char = u""
elif batt_status=="Discharging":
batt_char = u""
elif batt_status=="Full":
batt_char = u"F"
else:
batt_char = u" "
batt_perc = 100*batt_now//batt_max
batt_col = 255*batt_now//batt_max
for cardid in range(256):
try:
mixer = alsaaudio.Mixer(cardindex=cardid)
if mixer:
break
except alsaaudio.ALSAAudioError:
mixer = None
if mixer:
mix_vol = mixer.getvolume()[0]
mix_mute = bool(mixer.getmute()[0])
mix_chars = u" ▁▂▃▄▅▆▇█"
mix_chars_scale = mix_vol*8//100
out.append({
u"name": u"battery",
u"full_text": u"%s%s%3s" % (u"" if ac_online else u" ", batt_char, str(batt_perc)+"%" if batt_status!="Full" else "ull"),
u"color": u"#00FFFF" if batt_status=="Full" else u"#%2x%2x%%00" % (255-batt_col/2, batt_col)
u"name": u"volume",
u"full_text": u"♪%s" % mix_chars[mix_chars_scale],
u"color": u"#666666" if mix_mute else u"#6666FF"
})
except IOError:
pass
# Battery
for ac_sys_path in glob.glob("/sys/bus/acpi/drivers/ac/*/power_supply/*"):
try:
ac_online = int(open(path.join(ac_sys_path, "online"), "r").read())
if ac_online:
out.append({
u"name": ac_sys_path,
u"full_text": u"",
u"color": u"#00FFFF"
})
except IOError:
pass
for batt_sys_path in glob.glob("/sys/bus/acpi/drivers/battery/*/power_supply/*"):
try:
try:
batt_max = int(open(path.join(batt_sys_path, "charge_full"), "r").read())
batt_now = int(open(path.join(batt_sys_path, "charge_now"), "r").read())
except IOError:
batt_max = int(open(path.join(batt_sys_path, "energy_full"), "r").read())
batt_now = int(open(path.join(batt_sys_path, "energy_now"), "r").read())
batt_status = open(path.join(batt_sys_path, "status"), "r").read().strip()
ac_online = int(open(path.join(ac_sys_path, "online"), "r").read())
if batt_status=="Charging":
batt_char = u""
elif batt_status=="Discharging":
batt_char = u""
elif batt_status=="Full":
batt_char = u""
else:
batt_char = u" "
batt_perc = 100*batt_now//batt_max
batt_col = 255*batt_now//batt_max
battstr = u"%s%3s" % (batt_char, str(batt_perc)+"%" if batt_status!="Full" else "Full")
out.append({
u"name": batt_sys_path,
u"full_text": battstr,
u"color": u"#00FFFF" if batt_status=="Full" else u"#%2x%2x%%00" % (255-batt_col/2, batt_col)
})
except IOError:
pass
# Date/time
out.append({"name": "datetime", "full_text": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), "short_text": "short", "color": "%06x" % color})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment