Simple test

Ensure your device works with this simple test.

examples/usb_host_mouse_simpletest.py
 1# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3"""
 4This example is made for a basic boot mouse with
 5two buttons and a wheel that can be pressed.
 6"""
 7
 8import supervisor
 9import terminalio
10from adafruit_display_text.bitmap_label import Label
11from displayio import Group
12
13from adafruit_usb_host_mouse import find_and_init_boot_mouse
14
15display = supervisor.runtime.display
16
17# group to hold visual elements
18main_group = Group()
19
20# make the group visible on the display
21display.root_group = main_group
22
23mouse = find_and_init_boot_mouse()
24if mouse is None:
25    raise RuntimeError("No mouse found connected to USB Host")
26
27# text label to show the x, y coordinates on the screen
28output_lbl = Label(terminalio.FONT, text=f"{mouse.x},{mouse.y}", color=0xFFFFFF, scale=1)
29
30# move it to the upper left corner
31output_lbl.anchor_point = (0, 0)
32output_lbl.anchored_position = (1, 1)
33
34# add it to the main group
35main_group.append(output_lbl)
36
37# add the mouse tile grid to the main group
38main_group.append(mouse.tilegrid)
39
40# main loop
41while True:
42    # update mouse
43    pressed_btns = mouse.update()
44
45    # string with updated coordinates for the text label
46    out_str = f"{mouse.x},{mouse.y}"
47
48    # add pressed buttons to out str
49    if pressed_btns is not None and len(pressed_btns) > 0:
50        out_str += f" {' '.join(pressed_btns)}"
51
52    # update the text label with the new coordinates
53    # and buttons being pressed
54    output_lbl.text = out_str