Skip to content

Commit 90c4da8

Browse files
authored
Merge pull request adafruit#981 from tannewt/swap_hid_api
Provide USB HID devices directly rather than implicitly.
2 parents 1fe1e15 + 0dd7ea3 commit 90c4da8

File tree

24 files changed

+54
-29
lines changed

24 files changed

+54
-29
lines changed

Adafruit_pIRKey/NEC_keyboard_example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import adafruit_dotstar
1111
import pulseio
1212
import board
13+
import usb_hid
1314

1415
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
1516

1617
# The keyboard object!
1718
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
18-
keyboard = Keyboard()
19+
keyboard = Keyboard(usb_hid.devices)
1920
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
2021

2122
# our infrared pulse decoder helpers

Adafruit_pIRKey/raw_code_keyboard/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import adafruit_dotstar
99
import adafruit_irremote
1010
import time
11+
import usb_hid
1112

1213
# The keyboard object!
1314
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
14-
keyboard = Keyboard()
15+
keyboard = Keyboard(usb_hid.devices)
1516
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
1617

1718
led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)

Arcade_Button_Control_Box/Arcade_Button_Control_Box.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from adafruit_hid.keyboard import Keyboard
55
from adafruit_hid.keycode import Keycode
66
import board
7+
import usb_hid
78

89
# A simple neat keyboard demo in circuitpython
910

@@ -16,7 +17,7 @@
1617
controlkey = Keycode.LEFT_CONTROL
1718

1819
# the keyboard object!
19-
kbd = Keyboard()
20+
kbd = Keyboard(usb_hid.devices)
2021
# our array of button objects
2122
buttons = []
2223
leds = []

CPX_GBoard/arcade_hid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"""
1414

1515
import board
16+
import usb_hid
1617
from adafruit_hid.keyboard import Keyboard
1718
from adafruit_hid.keycode import Keycode
1819
from digitalio import DigitalInOut, Direction, Pull
@@ -28,7 +29,7 @@
2829
button_b.direction = Direction.INPUT
2930
button_b.pull = Pull.UP
3031

31-
kbd = Keyboard()
32+
kbd = Keyboard(usb_hid.devices)
3233

3334

3435
def touch_a():

CPX_GBoard/touch_hid.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
All text above must be included in any redistribution.
1313
"""
1414

15+
import usb_hid
1516
from adafruit_circuitplayground.express import cpx
1617
from adafruit_hid.keyboard import Keyboard
1718
from adafruit_hid.keycode import Keycode
1819

1920
DOT_DURATION = 0.25
2021
DASH_DURATION = 0.5
2122

22-
kbd = Keyboard()
23+
kbd = Keyboard(usb_hid.devices)
2324

2425
# You can adjust this to get the level of sensitivity you want.
2526
cpx.adjust_touch_threshold(100)

CPX_GBoard/universal.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
# from digitalio import DigitalInOut, Direction, Pull
2121
# import board
2222

23-
# Uncomment the next 2 lines if you want to use HID output
23+
# Uncomment the next 3 lines if you want to use HID output
2424
# from adafruit_hid.keyboard import Keyboard
2525
# from adafruit_hid.keycode import Keycode
26+
# import usb_hid
2627

2728
DOT_DURATION = 0.20
2829
DASH_DURATION = 0.5
@@ -40,7 +41,7 @@
4041
# button_b.pull = Pull.UP
4142

4243
# Uncomment the next line if you want to use HID output
43-
# kbd = Keyboard()
44+
# kbd = Keyboard(usb_hid.devices)
4445

4546

4647

CircuitPython_Essentials/CircuitPython_HID_Keyboard.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import board
66
import digitalio
7+
import usb_hid
78
from adafruit_hid.keyboard import Keyboard
89
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
910
from adafruit_hid.keycode import Keycode
@@ -20,7 +21,7 @@
2021

2122
# The keyboard object!
2223
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
23-
keyboard = Keyboard()
24+
keyboard = Keyboard(usb_hid.devices)
2425
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
2526

2627
# Make all pin objects inputs with pullups

CircuitPython_Essentials/CircuitPython_HID_Mouse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import analogio
44
import board
55
import digitalio
6+
import usb_hid
67
from adafruit_hid.mouse import Mouse
78

8-
mouse = Mouse()
9+
mouse = Mouse(usb_hid.devices)
910

1011
x_axis = analogio.AnalogIn(board.A0)
1112
y_axis = analogio.AnalogIn(board.A1)

Crank_USB_HID/code.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from adafruit_hid.consumer_control import ConsumerControl
1212
from adafruit_hid.consumer_control_code import ConsumerControlCode
1313
import neopixel
14+
import usb_hid
1415

1516
DOT_COLOR = 0xFF0000 # set to your favorite webhex color
1617
PRESSED_DOT_COLOR = 0x008080 # set to your second-favorite color
@@ -35,7 +36,8 @@
3536
rot_b.pull = Pull.UP
3637

3738
# Used to do HID output, see below
38-
kbd = Keyboard()
39+
kbd = Keyboard(usb_hid.devices)
40+
consumer_control = ConsumerControl(usb_hid.devices)
3941

4042
# time keeper, so we know when to turn off the LED
4143
timestamp = time.monotonic()
@@ -111,12 +113,12 @@
111113

112114
# Check if rotary encoder went up
113115
if encoder_direction == 1:
114-
ConsumerControl().send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
116+
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
115117
# kbd.press(Keycode.LEFT_ARROW)
116118
# kbd.release_all()
117119
# Check if rotary encoder went down
118120
if encoder_direction == -1:
119-
ConsumerControl().send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
121+
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
120122
# kbd.press(Keycode.RIGHT_ARROW)
121123
# kbd.release_all()
122124
# Button was 'just pressed'

Foul_Fowl/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import time
1010

1111
import board
12+
import usb_hid
1213
from adafruit_hid.keyboard import Keyboard
1314
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
1415
from adafruit_hid.keycode import Keycode
@@ -30,7 +31,7 @@
3031
buttons = []
3132

3233
# the keyboard object!
33-
kbd = Keyboard()
34+
kbd = Keyboard(usb_hid.devices)
3435
# we're americans :)
3536
layout = KeyboardLayoutUS(kbd)
3637

0 commit comments

Comments
 (0)