Does Core2 support touch event handlers in MicroPython?
I would like to define my own touch interface:
So far I only found the M5Btn class, but I can not use it to define transparent touch tiles.
from m5stack import *
from m5stack_ui import *
from uiflow import *
screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)
touch_button0 = M5Btn(text=None, x=0, y=0, w=100, h=80, bg_c=None, text_c=None, font=None, parent=None)
def touch_button0_pressed():
# global params
pass
touch_button0.pressed(touch_button0_pressed)
I tried to overwrite the button with my touch tiles, but after press the button is shown.
lcd.fillRect( 0, 0, 100, 80, 0xff0000 )
lcd.fillRect( 100, 0, 120, 80, 0x00ff00 )
lcd.fillRect( 220, 0, 100, 80, 0x0000ff )
lcd.fillRect( 0, 80, 100, 80, 0xaa0000 )
lcd.fillRect( 100, 80, 120, 80, 0x00aa00 )
lcd.fillRect( 220, 80, 100, 80, 0x0000aa )
lcd.fillRect( 0, 160, 100, 80, 0x550000 )
lcd.fillRect( 100, 160, 120, 80, 0x005500 )
lcd.fillRect( 220, 160, 100, 80, 0x000055 )
Or do I need to do this manually in a loop?
import time
from m5stack import *
def tile(x,y):
qx = 0
qy = 0
if x>=0 and x<100: qx = 1
if x>=100 and x<220: qx = 2
if x>=220 and x<320: qx = 3
if y>=0 and y<80: qy = 0
if y>=80 and y<160: qy = 3
if y>=160 and y<240: qy = 6
return qx + qy
def action(q):
if q == 0: lcd.clear(0xFFFFFF)
if q == 1: lcd.fillRect( 0, 0, 100, 80, 0xff0000 )
if q == 2: lcd.fillRect( 100, 0, 120, 80, 0x00ff00 )
if q == 3: lcd.fillRect( 220, 0, 100, 80, 0x0000ff )
if q == 4: lcd.fillRect( 0, 80, 100, 80, 0xaa0000 )
if q == 5: lcd.fillRect( 100, 80, 120, 80, 0x00aa00 )
if q == 6: lcd.fillRect( 220, 80, 100, 80, 0x0000aa )
if q == 7: lcd.fillRect( 0, 160, 100, 80, 0x550000 )
if q == 8: lcd.fillRect( 100, 160, 120, 80, 0x005500 )
if q == 9: lcd.fillRect( 220, 160, 100, 80, 0x000055 )
def loop():
x = -1
y = -1
while True:
if touch.status() == True:
t = touch.read()
tx = t[0]
ty = t[1]
if x != tx and y != ty:
x = tx
y = ty
q = tile(x, y)
action(q);
else:
x = -1
y = -1
action(0)
time.sleep(0.05)
loop()