Skip to content

Commit a35f3a1

Browse files
committed
Use adafruit_imageload instead of displayio.OnDiskBitmap
1 parent 11f463a commit a35f3a1

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

adafruit_usb_host_mouse/__init__.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
import array
3333
from traceback import print_exception
3434

35+
import adafruit_imageload
3536
import adafruit_usb_host_descriptors
3637
import usb
37-
from displayio import OnDiskBitmap, TileGrid
38+
from displayio import Bitmap, Palette, TileGrid
3839

3940
__version__ = "0.0.0+auto.0"
4041
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_USB_Host_Mouse.git"
@@ -119,13 +120,15 @@ def find_and_init_mouse(cursor_image=DEFAULT_CURSOR, subclass=SUBCLASS_BOOT):
119120
# load the mouse cursor bitmap
120121
mouse_tg = None
121122
if isinstance(cursor_image, str):
122-
mouse_bmp = OnDiskBitmap(cursor_image)
123+
mouse_bmp, mouse_palette = adafruit_imageload.load(
124+
cursor_image, bitmap=Bitmap, palette=Palette
125+
)
123126

124127
# make the background pink pixels transparent
125-
mouse_bmp.pixel_shader.make_transparent(0)
128+
mouse_palette.make_transparent(0)
126129

127130
# create a TileGrid for the mouse, using its bitmap and pixel_shader
128-
mouse_tg = TileGrid(mouse_bmp, pixel_shader=mouse_bmp.pixel_shader)
131+
mouse_tg = TileGrid(mouse_bmp, pixel_shader=mouse_palette)
129132

130133
return (
131134
(mouse_device, mouse_interface_index, mouse_endpoint_address, mouse_was_attached),
@@ -268,7 +271,10 @@ def release(self):
268271
# an empty list if no interfaces were detached
269272
for intf in self.was_attached:
270273
if not self.device.is_kernel_driver_active(intf):
271-
self.device.attach_kernel_driver(intf)
274+
try:
275+
self.device.attach_kernel_driver(intf)
276+
except usb.core.USBError:
277+
pass
272278

273279
def update(self):
274280
"""

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
# SPDX-License-Identifier: MIT
44

55
Adafruit-Blinka
6+
adafruit-circuitpython-imageload
67
adafruit-circuitpython-usb-host-descriptors

0 commit comments

Comments
 (0)