You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Polling touch handler
This commit is contained in:
+41
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user