summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wasp/apps/clock.py17
-rw-r--r--wasp/apps/testapp.py4
-rw-r--r--wasp/demo.py7
-rw-r--r--wasp/draw565.py48
-rw-r--r--wasp/drivers/st7789.py35
-rw-r--r--wasp/widgets.py11
6 files changed, 67 insertions, 55 deletions
diff --git a/wasp/apps/clock.py b/wasp/apps/clock.py
index cde39a2..f99091a 100644
--- a/wasp/apps/clock.py
+++ b/wasp/apps/clock.py
@@ -56,10 +56,10 @@ class ClockApp(object):
def draw(self, effect=None):
"""Redraw the display from scratch."""
- display = watch.display
+ draw = watch.drawable
- display.fill(0)
- display.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6)
+ draw.fill()
+ draw.rleblit(digits.clock_colon, pos=(2*48, 80), fg=0xb5b6)
self.on_screen = ( -1, -1, -1, -1, -1, -1 )
self.update()
self.meter.draw()
@@ -77,14 +77,13 @@ class ClockApp(object):
self.on_screen = now
return False
- display = watch.display
- display.rleblit(DIGITS[now[4] % 10], pos=(4*48, 80))
- display.rleblit(DIGITS[now[4] // 10], pos=(3*48, 80), fg=0xbdb6)
- display.rleblit(DIGITS[now[3] % 10], pos=(1*48, 80))
- display.rleblit(DIGITS[now[3] // 10], pos=(0*48, 80), fg=0xbdb6)
+ draw = watch.drawable
+ draw.rleblit(DIGITS[now[4] % 10], pos=(4*48, 80))
+ draw.rleblit(DIGITS[now[4] // 10], pos=(3*48, 80), fg=0xbdb6)
+ draw.rleblit(DIGITS[now[3] % 10], pos=(1*48, 80))
+ draw.rleblit(DIGITS[now[3] // 10], pos=(0*48, 80), fg=0xbdb6)
self.on_screen = now
- draw = watch.drawable
month = now[1] - 1
month = MONTH[month*3:(month+1)*3]
draw.string('{} {} {}'.format(now[2], month, now[0]),
diff --git a/wasp/apps/testapp.py b/wasp/apps/testapp.py
index 56a3853..9f512f1 100644
--- a/wasp/apps/testapp.py
+++ b/wasp/apps/testapp.py
@@ -38,7 +38,7 @@ class TestApp():
draw.string('({}, {})'.format(event[1], event[2]),
0, 108, width=240)
elif self.test == 'String':
- watch.display.fill(0, 0, 30, 240, 240-30)
+ draw.fill(0, 0, 30, 240, 240-30)
t = machine.Timer(id=1, period=8000000)
t.start()
draw.string("The quick brown", 12, 24+24)
@@ -56,7 +56,7 @@ class TestApp():
def draw(self, effect=None):
"""Redraw the display from scratch."""
watch.display.mute(True)
- watch.display.fill(0)
+ watch.drawable.fill()
watch.drawable.string('{} test'.format(self.test),
0, 6, width=240)
watch.display.mute(False)
diff --git a/wasp/demo.py b/wasp/demo.py
index 66cc0c8..6d3f6f5 100644
--- a/wasp/demo.py
+++ b/wasp/demo.py
@@ -7,7 +7,7 @@
# len(colors) is not a multiple of 5 ;-) ).
#
-import watch, logo, time, gc, draw565
+import watch, logo, time, gc
colors = (
0xffff,
@@ -24,10 +24,9 @@ colors = (
0xf81f, # magenta
)
-draw = draw565.Draw565(watch.display)
-
def textdemo():
watch.display.fill(0)
+ draw = watch.drawable
draw.string("The quick brown", 12, 24)
draw.string("fox jumped over", 12, 48)
draw.string("the lazy dog.", 12, 72)
@@ -57,7 +56,7 @@ def run():
l = logo.pine64
watch.display.fill(0)
- watch.display.rleblit(l, fg=c)
+ watch.drawable.rleblit(l, fg=c)
time.sleep(2)
gc.collect()
diff --git a/wasp/draw565.py b/wasp/draw565.py
index a94b812..e1beb51 100644
--- a/wasp/draw565.py
+++ b/wasp/draw565.py
@@ -29,6 +29,16 @@ def _bitblit(bitbuf, pixels, bgfg: int, count: int):
bitselect = 0x80
pxp += 1
+@micropython.viper
+def _fill(mv, color: int, count: int, offset: int):
+ p = ptr8(mv)
+ colorhi = color >> 8
+ colorlo = color & 0xff
+
+ for x in range(count):
+ p[2*(x+offset) ] = colorhi
+ p[2*(x+offset) + 1] = colorlo
+
def _bounding_box(s, font):
w = 0
for ch in s:
@@ -66,6 +76,44 @@ class Draw565(object):
self.set_color(0xffff)
self.set_font(fonts.sans24)
+ def fill(self, bg=None, x=0, y=0, w=None, h=None):
+ """Draw a solid color rectangle.
+
+ If no arguments a provided the whole display will be filled with
+ the background color.
+ """
+ if bg is None:
+ bg = self._bgfg >> 16
+ self._display.fill(bg, x, y, w, h)
+
+ @micropython.native
+ def rleblit(self, image, pos=(0, 0), fg=0xffff, bg=0):
+ """Decode and draw a 1-bit RLE image."""
+ display = self._display
+ (sx, sy, rle) = image
+
+ display.set_window(pos[0], pos[1], sx, sy)
+
+ buf = memoryview(display.linebuffer)[0:2*sx]
+ bp = 0
+ color = bg
+
+ for rl in rle:
+ while rl:
+ count = min(sx - bp, rl)
+ _fill(buf, color, count, bp)
+ bp += count
+ rl -= count
+
+ if bp >= sx:
+ display.write_data(buf)
+ bp = 0
+
+ if color == bg:
+ color = fg
+ else:
+ color = bg
+
def set_color(self, color, bg=0):
"""Set the foreground (color) and background (bg) color.
diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py
index 5cc3946..b7edf2e 100644
--- a/wasp/drivers/st7789.py
+++ b/wasp/drivers/st7789.py
@@ -25,16 +25,6 @@ _RAMWR = const(0x2c)
_COLMOD = const(0x3a)
_MADCTL = const(0x36)
-@micropython.viper
-def fastfill(mv, color: int, count: int, offset: int):
- p = ptr8(mv)
- colorhi = color >> 8
- colorlo = color & 0xff
-
- for x in range(count):
- p[2*(x+offset) ] = colorhi
- p[2*(x+offset) + 1] = colorlo
-
class ST7789(object):
def __init__(self, width, height):
self.width = width
@@ -126,31 +116,6 @@ class ST7789(object):
for yi in range(h):
self.write_data(buf)
- @micropython.native
- def rleblit(self, image, pos=(0, 0), fg=0xffff, bg=0):
- (sx, sy, rle) = image
- self.set_window(pos[0], pos[1], sx, sy)
-
- buf = memoryview(self.linebuffer)[0:2*sx]
- bp = 0
- color = bg
-
- for rl in rle:
- while rl:
- count = min(sx - bp, rl)
- fastfill(buf, color, count, bp)
- bp += count
- rl -= count
-
- if bp >= sx:
- self.write_data(buf)
- bp = 0
-
- if color == bg:
- color = fg
- else:
- color = bg
-
class ST7789_SPI(ST7789):
def __init__(self, width, height, spi, cs, dc, res=None, rate=8000000):
self.spi = spi
diff --git a/wasp/widgets.py b/wasp/widgets.py
index ee06187..3b2d6e1 100644
--- a/wasp/widgets.py
+++ b/wasp/widgets.py
@@ -11,10 +11,11 @@ class BatteryMeter(object):
def update(self):
icon = icons.battery
+ draw = watch.drawable
if watch.battery.charging():
if self.level != -1:
- watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
+ draw.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
self.level = -1
else:
level = watch.battery.level()
@@ -33,16 +34,16 @@ class BatteryMeter(object):
if (level > 5) ^ (self.level > 5):
if level > 5:
- watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
+ draw.rleblit(icon, pos=(239-icon[0], 0), fg=0x7bef)
else:
rgb = 0xf800
- watch.display.rleblit(icon, pos=(239-icon[0], 0), fg=0xf800)
+ draw.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)
+ draw.fill(0, x, 14, w, 24 - h)
if h:
- watch.display.fill(rgb, x, 38 - h, w, h)
+ draw.fill(rgb, x, 38 - h, w, h)
self.level = level