diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-08 23:16:30 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-03-08 23:16:30 (GMT) |
| commit | 5413d826d7ffe825b759cd013f9f68e9311aee01 (patch) | |
| tree | b4d111931455dffc8a3ea7e4bab219ad856072c3 /wasp/boards/simulator | |
| parent | 24438ad05daae80c4d27c6e8d0345bfd61d5578b (diff) | |
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.
Diffstat (limited to 'wasp/boards/simulator')
| -rw-r--r-- | wasp/boards/simulator/display.py | 2 | ||||
| -rw-r--r-- | wasp/boards/simulator/watch.py | 36 |
2 files changed, 20 insertions, 18 deletions
diff --git a/wasp/boards/simulator/display.py b/wasp/boards/simulator/display.py index 41d9512..3d7d388 100644 --- a/wasp/boards/simulator/display.py +++ b/wasp/boards/simulator/display.py @@ -101,7 +101,7 @@ class CST816SSim(): self.raise_interrupt() def raise_interrupt(self): - print('#INT') + pass sdl2.ext.init() window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT)) diff --git a/wasp/boards/simulator/watch.py b/wasp/boards/simulator/watch.py index 91be914..f38d7a1 100644 --- a/wasp/boards/simulator/watch.py +++ b/wasp/boards/simulator/watch.py @@ -3,6 +3,8 @@ def sleep_ms(ms): time.sleep(ms / 1000) time.sleep_ms = sleep_ms +import draw565 + from machine import I2C from machine import Pin from machine import SPI @@ -11,30 +13,22 @@ from drivers.cst816s import CST816S from drivers.st7789 import ST7789_SPI from drivers.vibrator import Vibrator -button = Pin('BUTTON', Pin.IN, quiet=True) class Backlight(object): def __init__(self, level=1): - self.set(level) + pass 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}') 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): def __init__(self): self.voltage = 3.9 @@ -93,10 +87,18 @@ class RTC(object): def get_uptime_ms(self): return int(time.time() * 1000) -display = Display() -touch = CST816S(I2C(0)) 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() +button = Pin('BUTTON', Pin.IN, quiet=True) rtc = RTC() +touch = CST816S(I2C(0)) vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True) |
