Skip to content

Provide USB HID devices directly rather than implicitly. #981

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

Merged
merged 5 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Adafruit_pIRKey/NEC_keyboard_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import adafruit_dotstar
import pulseio
import board
import usb_hid

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

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

# our infrared pulse decoder helpers
Expand Down
3 changes: 2 additions & 1 deletion Adafruit_pIRKey/raw_code_keyboard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import adafruit_dotstar
import adafruit_irremote
import time
import usb_hid

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

led = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1)
Expand Down
3 changes: 2 additions & 1 deletion Arcade_Button_Control_Box/Arcade_Button_Control_Box.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import board
import usb_hid

# A simple neat keyboard demo in circuitpython

Expand All @@ -16,7 +17,7 @@
controlkey = Keycode.LEFT_CONTROL

# the keyboard object!
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# our array of button objects
buttons = []
leds = []
Expand Down
3 changes: 2 additions & 1 deletion CPX_GBoard/arcade_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from digitalio import DigitalInOut, Direction, Pull
Expand All @@ -28,7 +29,7 @@
button_b.direction = Direction.INPUT
button_b.pull = Pull.UP

kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)


def touch_a():
Expand Down
3 changes: 2 additions & 1 deletion CPX_GBoard/touch_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
All text above must be included in any redistribution.
"""

import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

DOT_DURATION = 0.25
DASH_DURATION = 0.5

kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)

# You can adjust this to get the level of sensitivity you want.
cpx.adjust_touch_threshold(100)
Expand Down
5 changes: 3 additions & 2 deletions CPX_GBoard/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
# from digitalio import DigitalInOut, Direction, Pull
# import board

# Uncomment the next 2 lines if you want to use HID output
# Uncomment the next 3 lines if you want to use HID output
# from adafruit_hid.keyboard import Keyboard
# from adafruit_hid.keycode import Keycode
# import usb_hid

DOT_DURATION = 0.20
DASH_DURATION = 0.5
Expand All @@ -40,7 +41,7 @@
# button_b.pull = Pull.UP

# Uncomment the next line if you want to use HID output
# kbd = Keyboard()
# kbd = Keyboard(usb_hid.devices)



Expand Down
3 changes: 2 additions & 1 deletion CircuitPython_Essentials/CircuitPython_HID_Keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import board
import digitalio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -20,7 +21,7 @@

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

# Make all pin objects inputs with pullups
Expand Down
3 changes: 2 additions & 1 deletion CircuitPython_Essentials/CircuitPython_HID_Mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import analogio
import board
import digitalio
import usb_hid
from adafruit_hid.mouse import Mouse

mouse = Mouse()
mouse = Mouse(usb_hid.devices)

x_axis = analogio.AnalogIn(board.A0)
y_axis = analogio.AnalogIn(board.A1)
Expand Down
8 changes: 5 additions & 3 deletions Crank_USB_HID/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
import neopixel
import usb_hid

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

# Used to do HID output, see below
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
consumer_control = ConsumerControl(usb_hid.devices)

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

# Check if rotary encoder went up
if encoder_direction == 1:
ConsumerControl().send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT) #Turn Down Volume
# kbd.press(Keycode.LEFT_ARROW)
# kbd.release_all()
# Check if rotary encoder went down
if encoder_direction == -1:
ConsumerControl().send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT) #Turn Up Volume
# kbd.press(Keycode.RIGHT_ARROW)
# kbd.release_all()
# Button was 'just pressed'
Expand Down
3 changes: 2 additions & 1 deletion Foul_Fowl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time

import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -30,7 +31,7 @@
buttons = []

# the keyboard object!
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)

Expand Down
3 changes: 2 additions & 1 deletion GemmaM0_Password_Vault/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import board
import touchio
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from digitalio import DigitalInOut, Direction
Expand All @@ -19,7 +20,7 @@
# the keyboard object
# sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)

while True:
Expand Down
3 changes: 2 additions & 1 deletion GemmaM0_Radio_Tuning_Knob/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from analogio import AnalogIn
Expand Down Expand Up @@ -41,7 +42,7 @@ def spamKey(code):
Keycode.LEFT_BRACKET]
spamRate = [0.01, 0.05, 0.125, 0.25, 0.5,
0.5, 0.5, 0.25, 0.125, 0.05, 0.01]
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
kbd.press(knobkeys[code]) # which keycode is entered
kbd.release_all()
time.sleep(spamRate[code]) # how fast the key is spammed
Expand Down
3 changes: 2 additions & 1 deletion Giant_Mechanical_Keyboard/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import board
import neopixel
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -34,7 +35,7 @@
buttonspressedlast = [False, False, False]

# the keyboard object!
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time

import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -21,7 +22,7 @@
# the keyboard object!
# sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)

Expand Down
3 changes: 2 additions & 1 deletion Introducing_Gemma_M0/Gemma_HIDkeyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time

import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -21,7 +22,7 @@
# the keyboard object!
# sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)

Expand Down
5 changes: 3 additions & 2 deletions Launch_Deck_Trellis_M4/launch_deck_trellis_m4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import random
import adafruit_trellism4
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
Expand Down Expand Up @@ -80,8 +81,8 @@

TOTAL_SNORE = SNORE_PAUSE + SNORE_UP + SNORE_DOWN

kbd = Keyboard()
cc = ConsumerControl()
kbd = Keyboard(usb_hid.devices)
cc = ConsumerControl(usb_hid.devices)

trellis = adafruit_trellism4.TrellisM4Express(rotation=ROTATION)
for button in keymap:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_A-Mouse/cpx-mouse-buttons.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse

m = Mouse()
m = Mouse(usb_hid.devices)

while True:
if cpx.button_a:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_A-Mouse/mouse-cursor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.mouse import Mouse

m = Mouse()
m = Mouse(usb_hid.devices)
cpx.adjust_touch_threshold(200)

while True:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_A_Keyboard/keyboard-multimedia.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode

cc = ConsumerControl()
cc = ConsumerControl(usb_hid.devices)

while True:
if cpx.button_a:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_A_Keyboard/keycodes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)

while True:
if cpx.button_a:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_A_Keyboard/strings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import usb_hid
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS

kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)

while True:
Expand Down
3 changes: 2 additions & 1 deletion Make_It_Log/time-light-temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from digitalio import DigitalInOut, Direction, Pull
import analogio
import board
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
Expand All @@ -26,7 +27,7 @@
# Set the keyboard object!
# Sleep for a bit to avoid a race condition on some systems
time.sleep(1)
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd) # US is only current option...

led = DigitalInOut(board.D13) # Set up red LED "D13"
Expand Down
5 changes: 3 additions & 2 deletions Minecraft_Gesture_Controller/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# General purpose libraries
import touchio
# Libraries for HID Keyboard & Mouse
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
Expand All @@ -37,11 +38,11 @@
# Keyboard & Mouse Setup

# The keyboard object!
kbd = Keyboard()
kbd = Keyboard(usb_hid.devices)
# we're americans :)
layout = KeyboardLayoutUS(kbd)
# The mouse object!
mouse = Mouse()
mouse = Mouse(usb_hid.devices)

# Accelerometer Setup

Expand Down
3 changes: 2 additions & 1 deletion Rotary_Encoder/rotary_encoder_volume.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import rotaryio
import board
import digitalio
import usb_hid
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode

Expand All @@ -10,7 +11,7 @@

encoder = rotaryio.IncrementalEncoder(board.D10, board.D9)

cc = ConsumerControl()
cc = ConsumerControl(usb_hid.devices)

button_state = None
last_position = encoder.position
Expand Down