Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HID devices not ready when main.py starts #13

Closed
dhalbert opened this issue Apr 6, 2018 · 1 comment
Closed

HID devices not ready when main.py starts #13

dhalbert opened this issue Apr 6, 2018 · 1 comment
Assignees

Comments

@dhalbert
Copy link
Collaborator

dhalbert commented Apr 6, 2018

On some hosts (reported on a Windows 10 machine), main.py can start before the HID devices are ready on the host side. Examples:
https://forums.adafruit.com/viewtopic.php?f=52&t=125560#p629406
https://forums.adafruit.com/viewtopic.php?f=52&t=130143
Also reported in Discord (thanks @PhunkMaster)

I added time.sleep(1) to some of the HID examples (e.g., https://learn.adafruit.com/adafruit-circuit-playground-express?view=all#circuitpython-hid-keyboard), but this should really be handled in the library or possibly in the native implementation. The creation operations like Mouse() and Keyboard() could sleep and retry after failure, possibly just once.

@PhunkMaster
Copy link

PhunkMaster commented Apr 6, 2018

Per @dhalbert 's request, here was the failing code.

import board
import time
import digitalio
import adafruit_dotstar
from adafruit_hid.mouse import Mouse

mouse = Mouse()
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
led2 = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

led2[0] = (129, 0, 250)
while True:
  led.value = False
  led2.brightness = 0.1
  mouse.move(x=1)
  time.sleep(.1)
  mouse.move(y=1)
  time.sleep(.1)
  mouse.move(x=-1)
  time.sleep(.1)
  mouse.move(y=-1)
  led2.brightness = 0.0
  time.sleep(1.0)

dhalbert added a commit to dhalbert/Adafruit_CircuitPython_HID that referenced this issue Apr 6, 2018
Try a simple operation in each constructor. If it fails, wait one second
and try again (once). Fixes adafruit#13.
2. Don't limit mouse movements to [-127, 127]. Use multiple reports
to move further if necessary. I believe this was suggested by Mike Barela
(@TheKitty).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants