# SPDX-License-Identifier: LGPL-3.0-or-later # Copyright (C) 2020 Daniel Thompson import machine import wasp import icons class TestApp(): """Simple test application. """ NAME = 'Self Test' ICON = icons.app # 2-bit RLE, generated from res/app_icon.png, 457 bytes RLE_2BIT = ( 96, 64, b'\x1e@md= len(tests): i = 0 else: i -= 1 if i < 0: i = len(tests) - 1 self.test = tests[i] self.draw() def touch(self, event): if self.test == 'Touch': wasp.watch.drawable.string('({}, {})'.format( event[1], event[2]), 0, 108, width=240) elif self.test == 'String': self.benchmark_string() elif self.test == '1-bit RLE': self.benchmark_rle_1bit() elif self.test == '2-bit RLE': self.benchmark_rle_2bit() def benchmark_rle_1bit(self): draw = wasp.watch.drawable draw.fill(0, 0, 30, 240, 240-30) self.scroll.draw() t = machine.Timer(id=1, period=8000000) t.start() for i in range(0, 128, 16): draw.rleblit(self.ICON, (i, 30 + i)) elapsed = t.time() t.stop() del t draw.string('{}s'.format(elapsed / 1000000), 12, 24+192) def benchmark_rle_2bit(self): draw = wasp.watch.drawable draw.fill(0, 0, 30, 240, 240-30) self.scroll.draw() t = machine.Timer(id=1, period=8000000) t.start() for i in range(0, 128, 16): draw.rle2bit(self.RLE_2BIT, i, 30 + i) elapsed = t.time() t.stop() del t draw.string('{}s'.format(elapsed / 1000000), 12, 24+192) def benchmark_string(self): draw = wasp.watch.drawable draw.fill(0, 0, 30, 240, 240-30) self.scroll.draw() t = machine.Timer(id=1, period=8000000) t.start() draw.string("The quick brown", 12, 24+24) draw.string("fox jumped over", 12, 24+48) draw.string("the lazy dog.", 12, 24+72) draw.string("0123456789", 12, 24+120) draw.string('!"£$%^&*()', 12, 24+144) elapsed = t.time() t.stop() del t draw.string('{}s'.format(elapsed / 1000000), 12, 24+192) def draw(self): """Redraw the display from scratch.""" wasp.watch.display.mute(True) draw = wasp.watch.drawable draw.fill() draw.string('{} test'.format(self.test), 0, 6, width=240) self.scroll.draw() if self.test == 'Crash': draw.string("Press button to", 12, 24+24) draw.string("throw exception.", 12, 24+48) elif self.test == '1-bit RLE': draw.rleblit(self.ICON, (120-48, 120-32)) elif self.test == '2-bit RLE': draw.rle2bit(self.RLE_2BIT, 120-48, 120-32) wasp.watch.display.mute(False)