From 7b3e0f917d541317edd4bed53ca6241d898cfbff Mon Sep 17 00:00:00 2001 From: Daniel Thompson Date: Sat, 27 Jun 2020 12:22:23 +0100 Subject: [PATCH] boards: simulator: Add swipe detection and button support Currently the simulator relies on the keyboard to issue touchscreen gestures and button presses. Fix this by adding swipe detection and introducing a skin which gives us the capability to press the button using touchscreens or pointer devices. Signed-off-by: Daniel Thompson --- TODO.rst | 5 +++ res/simulator_skin.png | Bin 0 -> 6451 bytes wasp/boards/simulator/display.py | 68 +++++++++++++++++++++++++++---- 3 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 res/simulator_skin.png diff --git a/TODO.rst b/TODO.rst index 9cad328..320dab5 100644 --- a/TODO.rst +++ b/TODO.rst @@ -144,3 +144,8 @@ Wasp-os * [ ] Debugging and troubleshooting guide * [ ] Screenshots for bootloader and all applications * [ ] Improve the install guide + +* [X] Simulator + + * [X] Add a simple skin for better screenshots + * [X] Full swipe detection (avoid keyboard) diff --git a/res/simulator_skin.png b/res/simulator_skin.png new file mode 100644 index 0000000000000000000000000000000000000000..1f6de64fda971d270b17ce2e6ebe8ade0fd90e64 GIT binary patch literal 6451 zcmcIn2UJt*mJUUlC7_^m5JFX&bdVy15~?855h()FdkKW17ioq_kY1&V5fC9j=!$?L zv`7;OMd?zF^g6k|=Q!`qeQRdTTC>i7_S)+^`|RxhKf8R1yKSI#o{p6c005kaXoHOb z05T)ejiR97n}rZvPPP2iy;WA36a5!Q|6t>%%W-NTu%YDM`=$~p9OhBcP0+{ z8mYohO~QCuatu5BuQat!{Bd>9*M&TWkP(zP5xA1CD6rd}wzYJOn|S=gMrq;rvDhqD zP+8#3&7c$C@9_H(O$;R)H0pIb@3LnL72bX$l%uY`FZ?cN#FjHvrDRUS|E|)5!SKD- zX70$H&AD<F-q8dkbfzvcC z^7AIkUVtp^z?luvhE1eZYEvHzlG>rnLEOQ8f9pkMY-@-%Ix8U<*O=!mnx9tfcV7CO z{9&gs;5~GPANOw2udQ`5n@jN(8Lp?7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 HcmV?d00001 diff --git a/wasp/boards/simulator/display.py b/wasp/boards/simulator/display.py index 11b4701..9e5c622 100644 --- a/wasp/boards/simulator/display.py +++ b/wasp/boards/simulator/display.py @@ -14,6 +14,13 @@ RAMWR = 0x2c WIDTH = 240 HEIGHT = 240 +SKIN = { + 'fname' : 'res/simulator_skin.png', + 'size' : (337, 427), + 'button_profile' : 9, + 'offset' : (53, 93) +} + class ST7789Sim(object): def __init__(self): @@ -60,7 +67,9 @@ class ST7789Sim(object): ((rgb & 0x07e0) << 5) + ((rgb & 0x001f) << 3)) - pixelview[self.x][self.y] = pixel + pv_x = self.x + SKIN['adjust'][0] + pv_y = self.y + SKIN['adjust'][1] + pixelview[pv_x][pv_y] = pixel self.x += 1 if self.x > self.colclip[1]: @@ -118,20 +127,61 @@ class CST816SSim(): self.regs[3] = 0x80 self.raise_interrupt(pins) - def handle_mousebutton(self, button, pins): - self.regs[1] = 5 - self.regs[4] = button.x - self.regs[6] = button.y + def handle_mousebuttondown(self, button, pins): + self.down_x = button.x + self.down_y = button.y + + if self.down_x < 50: + pins['BUTTON'].value(0) + + + def handle_mousebuttonup(self, button, pins): + if self.down_x < 50: + pins['BUTTON'].value(1) + return + + down_x = max(0, min(239, self.down_x-SKIN['adjust'][0])) + down_y = max(0, min(239, self.down_y-SKIN['adjust'][1])) + up_x = max(0, min(239, button.x-SKIN['adjust'][0])) + up_y = max(0, min(239, button.y-SKIN['adjust'][1])) + mv_x = up_x - down_x + mv_y = up_y - down_y + + # Swipe detection + if abs(mv_x) + abs(mv_y) < 24: + self.regs[1] = 5 + elif abs(mv_x) > abs(mv_y): + self.regs[1] = 4 if mv_x > 0 else 3 + else: + self.regs[1] = 2 if mv_y > 0 else 1 + + self.regs[4] = up_x; + self.regs[6] = up_y; self.raise_interrupt(pins) def raise_interrupt(self, pins): pins['TP_INT'].raise_irq() +# Derive some extra values for padding the display +SKIN['left_pad'] = 9 +SKIN['right_pad'] = SKIN['left_pad'] + SKIN['button_profile'] +SKIN['top_pad'] = 3 +SKIN['bottom_pad'] = 3 +SKIN['window'] = (SKIN['size'][0] + SKIN['left_pad'] + SKIN['right_pad'], + SKIN['size'][1] + SKIN['top_pad'] + SKIN['bottom_pad']) +SKIN['adjust'] = (SKIN['offset'][0] + SKIN['left_pad'], + SKIN['offset'][1] + SKIN['top_pad']) + sdl2.ext.init() -window = sdl2.ext.Window("ST7789", size=(WIDTH, HEIGHT)) +window = sdl2.ext.Window("ST7789", size=SKIN['window']) window.show() windowsurface = window.get_surface() -sdl2.ext.fill(windowsurface, (0, 0, 0)) +sdl2.ext.fill(windowsurface, (0xff, 0xff, 0xff)) +skin = sdl2.ext.load_image(SKIN['fname']) +sdl2.SDL_BlitSurface(skin, None, windowsurface, sdl2.SDL_Rect( + SKIN['left_pad'], SKIN['top_pad'], SKIN['size'][0], SKIN['size'][1])) +sdl2.SDL_FreeSurface(skin) +window.refresh() spi_st7789_sim = ST7789Sim() i2c_cst816s_sim = CST816SSim() @@ -143,7 +193,9 @@ def tick(pins): sdl2.ext.quit() sys.exit(0) elif event.type == sdl2.SDL_MOUSEBUTTONDOWN: - i2c_cst816s_sim.handle_mousebutton(event.button, pins) + i2c_cst816s_sim.handle_mousebuttondown(event.button, pins) + elif event.type == sdl2.SDL_MOUSEBUTTONUP: + i2c_cst816s_sim.handle_mousebuttonup(event.button, pins) elif event.type == sdl2.SDL_KEYDOWN: if event.key.keysym.sym == sdl2.SDLK_TAB: pins['BUTTON'].value(0)