pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Module USB

案例程序

初始化鼠标HID HOST, 接鼠标后读取光标x,y坐标和按键状态。
from m5stack import *
from m5ui import *
from uiflow import *
import module

import time
setScreenColor(0x222222)

usb = module.get(module.USBHOST)

usb.max3421e_init(sclk=18, mosi=23, miso=19, cs=5, irq=35)
usb.hid_init()
while True:
  usb.hid_poll()
  if usb.mouse_button_status(1):
    print('mouse button left click')
  if usb.mouse_button_status(2):
    print('mouse button right click')
  if usb.mouse_button_status(4):
    print('mouse button center click')
  print((str('X:') + str((usb.mouse_cursor_x))))
  print((str('Y:') + str((usb.mouse_cursor_y))))
  wait(1)
  wait_ms(2)

功能说明

import module
usb = module.get(module.USBHOST)
usb.max3421e_init(sclk=18, mosi=23, miso=19, cs=5, irq=35)
  • 初始化Module USB
usb.hid_init()
  • 初始化Mouse HID Host
usb.hid_poll()
  • 刷新输入设备状态
usb.mouse_button_status(status):
  • 获取按键状态:
    • status:
      • left:1
      • right:2
      • left+right:3
      • center:4
      • left+center:5
      • right+center:6
      • left+right+center:7
  • 返回值:
    • True/False
usb.mouse_cursor_x
usb.mouse_cursor_y
  • 获取输入设备光标位置
usb.write_output_pin(PIN,0)
  • 模块拓展输出IO, 控制输出电平
    • PIN:0-4
usb.read_input_pin(PIN)
  • 模块拓展输入IO, 读取输入电平
    • PIN:0-4
usb.read_output_pin(PIN)
  • 模块拓展输出组IO, 读取输出电平:
    • PIN:0-4
On This Page