wasp: Re-factor how Draw565 is used.
Moving it from applications into the watch is useful for two reasons. Firstly it means applications don't need to know as much about the display color depth and secondly it makes it easier to replace the drawing routines with wasptool.
This commit is contained in:
parent
24438ad05d
commit
5413d826d7
6 changed files with 26 additions and 28 deletions
|
@ -3,8 +3,6 @@ import watch
|
||||||
import widgets
|
import widgets
|
||||||
import manager
|
import manager
|
||||||
|
|
||||||
from draw565 import Draw565
|
|
||||||
|
|
||||||
DIGITS = (
|
DIGITS = (
|
||||||
digits.clock_0,
|
digits.clock_0,
|
||||||
digits.clock_1,
|
digits.clock_1,
|
||||||
|
@ -86,7 +84,7 @@ class ClockApp(object):
|
||||||
display.rleblit(DIGITS[now[3] // 10], pos=(0*48, 80), fg=0xbdb6)
|
display.rleblit(DIGITS[now[3] // 10], pos=(0*48, 80), fg=0xbdb6)
|
||||||
self.on_screen = now
|
self.on_screen = now
|
||||||
|
|
||||||
draw = Draw565(display)
|
draw = watch.drawable
|
||||||
month = now[1] - 1
|
month = now[1] - 1
|
||||||
month = MONTH[month*3:(month+1)*3]
|
month = MONTH[month*3:(month+1)*3]
|
||||||
draw.string('{} {} {}'.format(now[2], month, now[0]),
|
draw.string('{} {} {}'.format(now[2], month, now[0]),
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import watch
|
import watch
|
||||||
import manager
|
import manager
|
||||||
|
|
||||||
from draw565 import Draw565
|
|
||||||
|
|
||||||
class FlashlightApp(object):
|
class FlashlightApp(object):
|
||||||
"""Trivial flashlight application.
|
"""Trivial flashlight application.
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,6 @@ import widgets
|
||||||
import manager
|
import manager
|
||||||
import machine
|
import machine
|
||||||
|
|
||||||
from draw565 import Draw565
|
|
||||||
|
|
||||||
class TestApp():
|
class TestApp():
|
||||||
"""Simple test application.
|
"""Simple test application.
|
||||||
"""
|
"""
|
||||||
|
@ -12,7 +10,6 @@ class TestApp():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tests = ('Touch', 'String')
|
self.tests = ('Touch', 'String')
|
||||||
self.test = self.tests[0]
|
self.test = self.tests[0]
|
||||||
self.drawable = Draw565(watch.display)
|
|
||||||
|
|
||||||
def foreground(self, system, effect=None):
|
def foreground(self, system, effect=None):
|
||||||
"""Activate the application."""
|
"""Activate the application."""
|
||||||
|
@ -36,7 +33,7 @@ class TestApp():
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
def touch(self, event):
|
def touch(self, event):
|
||||||
draw = self.drawable
|
draw = watch.drawable
|
||||||
if self.test == 'Touch':
|
if self.test == 'Touch':
|
||||||
draw.string('({}, {})'.format(event[1], event[2]),
|
draw.string('({}, {})'.format(event[1], event[2]),
|
||||||
0, 108, width=240)
|
0, 108, width=240)
|
||||||
|
@ -60,6 +57,6 @@ class TestApp():
|
||||||
"""Redraw the display from scratch."""
|
"""Redraw the display from scratch."""
|
||||||
watch.display.mute(True)
|
watch.display.mute(True)
|
||||||
watch.display.fill(0)
|
watch.display.fill(0)
|
||||||
self.drawable.string('{} test'.format(self.test),
|
watch.drawable.string('{} test'.format(self.test),
|
||||||
0, 6, width=240)
|
0, 6, width=240)
|
||||||
watch.display.mute(False)
|
watch.display.mute(False)
|
||||||
|
|
|
@ -7,6 +7,8 @@ rtc.counter.start()
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import draw565
|
||||||
|
|
||||||
from machine import I2C
|
from machine import I2C
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
#from machine import Signal
|
#from machine import Signal
|
||||||
|
@ -51,6 +53,7 @@ display = ST7789_SPI(240, 240, spi,
|
||||||
cs=Pin("DISP_CS", Pin.OUT),
|
cs=Pin("DISP_CS", Pin.OUT),
|
||||||
dc=Pin("DISP_DC", Pin.OUT),
|
dc=Pin("DISP_DC", Pin.OUT),
|
||||||
res=Pin("DISP_RST", Pin.OUT))
|
res=Pin("DISP_RST", Pin.OUT))
|
||||||
|
drawable = draw565.Draw565(display)
|
||||||
|
|
||||||
# Setup the last few bits and pieces
|
# Setup the last few bits and pieces
|
||||||
battery = Battery(
|
battery = Battery(
|
||||||
|
|
|
@ -101,7 +101,7 @@ class CST816SSim():
|
||||||
self.raise_interrupt()
|
self.raise_interrupt()
|
||||||
|
|
||||||
def raise_interrupt(self):
|
def raise_interrupt(self):
|
||||||
print('#INT')
|
pass
|
||||||
|
|
||||||
sdl2.ext.init()
|
sdl2.ext.init()
|
||||||
window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT))
|
window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT))
|
||||||
|
|
|
@ -3,6 +3,8 @@ def sleep_ms(ms):
|
||||||
time.sleep(ms / 1000)
|
time.sleep(ms / 1000)
|
||||||
time.sleep_ms = sleep_ms
|
time.sleep_ms = sleep_ms
|
||||||
|
|
||||||
|
import draw565
|
||||||
|
|
||||||
from machine import I2C
|
from machine import I2C
|
||||||
from machine import Pin
|
from machine import Pin
|
||||||
from machine import SPI
|
from machine import SPI
|
||||||
|
@ -11,30 +13,22 @@ from drivers.cst816s import CST816S
|
||||||
from drivers.st7789 import ST7789_SPI
|
from drivers.st7789 import ST7789_SPI
|
||||||
from drivers.vibrator import Vibrator
|
from drivers.vibrator import Vibrator
|
||||||
|
|
||||||
button = Pin('BUTTON', Pin.IN, quiet=True)
|
|
||||||
|
|
||||||
class Backlight(object):
|
class Backlight(object):
|
||||||
def __init__(self, level=1):
|
def __init__(self, level=1):
|
||||||
self.set(level)
|
pass
|
||||||
|
|
||||||
def set(self, level):
|
def set(self, level):
|
||||||
|
"""Set the simulated backlight level.
|
||||||
|
|
||||||
|
This function contains a subtle trick. As soon as the backlight is
|
||||||
|
turned off (e.g. the watch goes to sleep) then we will simulate
|
||||||
|
a button press in order to turn the watch back on again.
|
||||||
|
"""
|
||||||
print(f'BACKLIGHT: {level}')
|
print(f'BACKLIGHT: {level}')
|
||||||
|
|
||||||
button.value(bool(level))
|
button.value(bool(level))
|
||||||
|
|
||||||
class Display(ST7789_SPI):
|
|
||||||
def __init__(self):
|
|
||||||
spi = SPI(0)
|
|
||||||
# Mode 3, maximum clock speed!
|
|
||||||
spi.init(polarity=1, phase=1, baudrate=8000000)
|
|
||||||
|
|
||||||
# Configure the display
|
|
||||||
cs = Pin("DISP_CS", Pin.OUT, quiet=True)
|
|
||||||
dc = Pin("DISP_DC", Pin.OUT, quiet=True)
|
|
||||||
rst = Pin("DISP_RST", Pin.OUT, quiet=True)
|
|
||||||
|
|
||||||
super().__init__(240, 240, spi, cs=cs, dc=dc, res=rst)
|
|
||||||
|
|
||||||
class Battery(object):
|
class Battery(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.voltage = 3.9
|
self.voltage = 3.9
|
||||||
|
@ -93,10 +87,18 @@ class RTC(object):
|
||||||
def get_uptime_ms(self):
|
def get_uptime_ms(self):
|
||||||
return int(time.time() * 1000)
|
return int(time.time() * 1000)
|
||||||
|
|
||||||
display = Display()
|
|
||||||
touch = CST816S(I2C(0))
|
|
||||||
backlight = Backlight()
|
backlight = Backlight()
|
||||||
|
spi = SPI(0)
|
||||||
|
spi.init(polarity=1, phase=1, baudrate=8000000)
|
||||||
|
display = ST7789_SPI(240, 240, spi,
|
||||||
|
cs=Pin("DISP_CS", Pin.OUT, quiet=True),
|
||||||
|
dc=Pin("DISP_DC", Pin.OUT, quiet=True),
|
||||||
|
res=Pin("DISP_RST", Pin.OUT, quiet=True))
|
||||||
|
drawable = draw565.Draw565(display)
|
||||||
|
|
||||||
battery = Battery()
|
battery = Battery()
|
||||||
|
button = Pin('BUTTON', Pin.IN, quiet=True)
|
||||||
rtc = RTC()
|
rtc = RTC()
|
||||||
|
touch = CST816S(I2C(0))
|
||||||
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue