From 127e113f398ee5ad06dbd0ef3a3728c71541d27b Mon Sep 17 00:00:00 2001 From: David Glaude Date: Fri, 22 May 2020 02:06:03 +0200 Subject: [PATCH 1/2] Something must have change in CircuitPython Your code was not working for me on CircuitPython 5.3+ (maybe before). Need to import usb_hid to later use that to create the keyboard object. Then, I could not find send_code function anymore, so I did this in two step, set the code, then send. This is working for me, but I don't know exactly what I am doing. I would advise to test yourself before accepting this PR. Regards. --- circuitpython/kbdhid.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/circuitpython/kbdhid.py b/circuitpython/kbdhid.py index 5c8b6d0..4d9cf20 100644 --- a/circuitpython/kbdhid.py +++ b/circuitpython/kbdhid.py @@ -10,6 +10,7 @@ import board import busio +import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS from adafruit_hid.keycode import Keycode @@ -19,7 +20,7 @@ uart = busio.UART(board.TX, board.RX, baudrate=115200) -keyboard = Keyboard() +keyboard = Keyboard(usb_hid.devices) keyboard_layout = KeyboardLayoutUS(keyboard) while True: @@ -27,7 +28,8 @@ if data is not None: if (len(data) == 11) and (data[0] == STX) and (data[1] == 0x08) and (data[10] == ETX): - keyboard.hid_keyboard.send_report(data[2:10]) + keyboard.report=bytearray(data[2:10]) + keyboard.send() else: # Scan for STX ... ETX to resync print(data) From 526ba30bc82117d445b970e3ebf6d107f0463f7a Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sat, 23 May 2020 09:58:16 +0200 Subject: [PATCH 2/2] Another keyboard.hid_keyboard.send_report to fix There was another usage of keyboard.hid_keyboard.send_report that needed to be fixed. --- circuitpython/kbdhid.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/circuitpython/kbdhid.py b/circuitpython/kbdhid.py index 4d9cf20..ec5b932 100644 --- a/circuitpython/kbdhid.py +++ b/circuitpython/kbdhid.py @@ -39,4 +39,5 @@ report = data[i:len(data)] + uart.read(11-(len(data)-i)) print(report) if (len(report) == 11) and (report[0] == STX) and (report[1] == 0x08) and (report[10] == ETX): - keyboard.hid_keyboard.send_report(report[2:10]) + keyboard.report=bytearray(report[2:10]) + keyboard.send()