Toggle Navigation
Hatchery
Eggs
fiee planner
battery.py
Users
Badges
Login
Register
MCH2022 badge?
go to mch2022.badge.team
battery.py
raw
Content
""" by lortas """ import os import power BATTERY_COLOR_GOOD = [0, 230, 0] BATTERY_COLOR_OK = [255, 215, 0] BATTERY_COLOR_BAD = [255, 0, 0] def get_bat_color(v): if v > 3.8: return BATTERY_COLOR_GOOD if v > 3.6: return BATTERY_COLOR_OK return BATTERY_COLOR_BAD def render_battery(d, pos_x=140, pos_y=72): v = os.read_battery() c = get_bat_color(v) if not c: return d.rect(pos_x, pos_y, pos_x + 15, pos_y + 7, filled=True, col=c) d.rect(pos_x + 15, pos_y + 2, pos_x + 17, pos_y + 5, filled=True, col=c) if v < 4.0: d.rect(pos_x + 11, pos_y + 1, pos_x + 14, pos_y + 6, filled=True, col=[0, 0, 0]) if v < 3.8: d.rect(pos_x + 6, pos_y + 1, pos_x + 11, pos_y + 6, filled=True, col=[0, 0, 0]) if v < 3.6: d.rect(pos_x + 1, pos_y + 1, pos_x + 6, pos_y + 6, filled=True, col=[0, 0, 0]) render_charging(d, pos_x + 6, pos_y) def render_charging(d, pos_x, pos_y): v_in = power.read_chargein_voltage() if v_in > 4.0: c = [0, 0, 0] c_shade = [120, 120, 120] d.pixel(pos_x + 1, pos_y, col=c) d.pixel(pos_x + 1, pos_y, col=c) d.pixel(pos_x + 2, pos_y, col=c_shade) d.pixel(pos_x + 1, pos_y + 1, col=c) d.pixel(pos_x, pos_y + 1, col=c_shade) d.pixel(pos_x + 1, pos_y + 2, col=c) d.pixel(pos_x, pos_y + 2, col=c) d.pixel(pos_x, pos_y + 3, col=c) d.pixel(pos_x + 1, pos_y + 3, col=c) d.pixel(pos_x + 2, pos_y + 3, col=c) d.pixel(pos_x + 3, pos_y + 3, col=c_shade) d.pixel(pos_x + 2, pos_y + 4, col=c) d.pixel(pos_x + 3, pos_y + 4, col=c) d.pixel(pos_x + 4, pos_y + 4, col=c) d.pixel(pos_x + 1, pos_y + 4, col=c_shade) d.pixel(pos_x + 3, pos_y + 5, col=c) d.pixel(pos_x + 4, pos_y + 5, col=c) d.pixel(pos_x + 3, pos_y + 6, col=c) d.pixel(pos_x + 4, pos_y + 6, col=c_shade) d.pixel(pos_x + 3, pos_y + 7, col=c) d.pixel(pos_x + 2, pos_y + 7, col=c_shade)