1
0
Fork 0

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 <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-06-27 12:22:23 +01:00
parent b7e7164d59
commit 7b3e0f917d
3 changed files with 65 additions and 8 deletions

View file

@ -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)

BIN
res/simulator_skin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

@ -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)