From 1d8b900d404a7cee8f44b74bf286d5fd21aab5c3 Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Tue, 4 Feb 2020 08:43:49 +0000 Subject: waps: widgets: Improve the battery meter athtetics Add some extra internal padding and draw the battery in red when power is critically low. diff --git a/wasp/widgets.py b/wasp/widgets.py index 90e98ea..ee06187 100644 --- a/wasp/widgets.py +++ b/wasp/widgets.py @@ -3,46 +3,46 @@ import watch class BatteryMeter(object): def __init__(self): - self.level = None + self.level = -2 def draw(self): - display = watch.display - icon = icons.battery - - watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef) - self.level = -1 + self.level = -2 self.update() def update(self): + icon = icons.battery + if watch.battery.charging(): if self.level != -1: - icon = icons.battery watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef) self.level = -1 else: level = watch.battery.level() if level == self.level: return - self.level = level - x = 239 - 31 - w = 18 - - # Use the level to work out the correct height - if level == 100: - h = 26 - else: - h = level // 4 - # Use the level to figure out the right color if level > 96: + h = 24 rgb = 0x07e0 else: + h = level // 4 + green = level // 3 red = 31-green rgb = (red << 11) + (green << 6) - if 26 - h: - watch.display.fill(0, x, 13, 18, 26 - h) + if (level > 5) ^ (self.level > 5): + if level > 5: + watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef) + else: + rgb = 0xf800 + watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0xf800) + + x = 239 - 30 + w = 16 + if 24 - h: + watch.display.fill(0, x, 14, w, 24 - h) if h: - watch.display.fill(rgb, x, 39 - h, 18, h) + watch.display.fill(rgb, x, 38 - h, w, h) + self.level = level -- cgit v0.10.2