From dd33a8a6c82cfc755829d6b6b2f89553869ed8a0 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sat, 19 Apr 2025 00:44:09 +0200 Subject: [PATCH] Polling touch handler --- appstore.mpy | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/appstore.mpy b/appstore.mpy index d2e875a2..5cb88787 100644 --- a/appstore.mpy +++ b/appstore.mpy @@ -117,10 +117,6 @@ display.set_rotation(lv.DISPLAY_ROTATION._90) display.set_backlight(100) -i2c_bus = i2c.I2C.Bus(host=0, scl=47, sda=48, freq=100000, use_locks=False) -touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x15, reg_bits=8) -indev = cst816s.CST816S(touch_dev) - th = task_handler.TaskHandler() scr = lv.screen_active() @@ -279,3 +275,44 @@ def create_notification_bar(): # Create the notification bar create_notification_bar() + + + +i2c_bus = i2c.I2C.Bus(host=0, scl=47, sda=48, freq=100000, use_locks=False) +touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x15, reg_bits=8) +#indev = cst816s.CST816S(touch_dev) +indev=cst816s.CST816S(touch_dev,startup_rotation=lv.DISPLAY_ROTATION._90) + +# gesture id: +# 0: press +# 1: swipe from left to USB port +# 2: swipe from USB port to left +# 3: top to bottom +# 4: bottom to top +# 5: release +# 12: long press +def check_swipe(timer): + indev._read_reg(0x01) + gesture_id=indev._rx_buf[0] + indev._read_reg(0x02) + finger_num=indev._rx_buf[0] + indev._read_reg(0x03) + x_h=indev._rx_buf[0] + indev._read_reg(0x04) + x_l=indev._rx_buf[0] + x=((x_h&0x0F)<<8)|x_l + indev._read_reg(0x05) + y_h=indev._rx_buf[0] + indev._read_reg(0x06) + y_l=indev._rx_buf[0] + y=((y_h&0x0F)<<8)|y_l + print(f"GestureID={gesture_id},FingerNum={finger_num},X={x},Y={y}") + if gesture_id==0x01:print("Swipe Up Detected") + elif gesture_id==0x02:print("Swipe Down Detected") + +lv.timer_create(check_swipe,100,None) + + +#indev._write_reg(0xEC,0x06) +#indev._write_reg(0xFA,0x50) +#irq_pin=machine.Pin(46,machine.Pin.IN,machine.Pin.PULL_UP)