summaryrefslogtreecommitdiff
path: root/wasp
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-04 08:43:49 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-04 08:43:49 (GMT)
commit1d8b900d404a7cee8f44b74bf286d5fd21aab5c3 (patch)
tree84bddc716ef7d1841a32516d87c035a5a72beecd /wasp
parent3e0cb4eed5a5ad75ec5c56e3603d4c48f609da41 (diff)
waps: widgets: Improve the battery meter athtetics
Add some extra internal padding and draw the battery in red when power is critically low.
Diffstat (limited to 'wasp')
-rw-r--r--wasp/widgets.py40
1 files changed, 20 insertions, 20 deletions
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