From 2079ef0ca273d2f4ea842ca88e62ceab48cb762f Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Mon, 23 Jul 2018 15:06:48 +0200 Subject: [PATCH] fix keyboard --- raspberry-environment/display.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/raspberry-environment/display.py b/raspberry-environment/display.py index d9befcb..819113b 100644 --- a/raspberry-environment/display.py +++ b/raspberry-environment/display.py @@ -117,10 +117,13 @@ def os_echo(filename, string): with open(filename, 'w') as f: f.write(string) +def os_echo_bin(filename, string): + with open(filename, 'wb') as f: + f.write(string) def send_keypress(): - with open('/dev/hidg0', 'w') as f: + with open('/dev/hidg0', 'wb') as f: f.write(bytearray(b'\x00\x00\x04\x00\x00\x00\x00\x00')) #press the A-button f.write(bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00')) #release all keys @@ -165,6 +168,12 @@ if __name__ == '__main__': os_echo(g+"strings/0x409/manufacturer", "IUL TU Dortmund") os_echo(g+"strings/0x409/product", "Raspberry Screenshot Gadget") + subprocess.run(['mkdir', g+"configs/c.1"], shell=False, check=True) + subprocess.run(['mkdir', g+"configs/c.1/strings/0x409"], shell=False, check=True) # english + os_echo(g+"configs/c.1/bmAttributes", "0x80") # bus powered + os_echo(g+"configs/c.1/MaxPower", "500") + os_echo(g+"configs/c.1/strings/0x409/configuration", "Config 1") + # config usb_mass_storage subprocess.run(['mkdir', g+"functions/mass_storage.usb0"], shell=False, check=True) os_echo(g+"functions/mass_storage.usb0/stall", "0") @@ -174,19 +183,16 @@ if __name__ == '__main__': os_echo(g+"functions/mass_storage.usb0/lun.0/removable", "1") os_echo(g+"functions/mass_storage.usb0/lun.0/file", "/tmp/usbdisk.img") - subprocess.run(['mkdir', g+"configs/c.1"], shell=False, check=True) - subprocess.run(['mkdir', g+"configs/c.1/strings/0x409"], shell=False, check=True) # english - os_echo(g+"configs/c.1/bmAttributes", "0x80") # bus powered - os_echo(g+"configs/c.1/MaxPower", "250") - os_echo(g+"configs/c.1/strings/0x409/configuration", "Storage configuration") subprocess.run(['ln', '-s', g+"functions/mass_storage.usb0", g+"configs/c.1"], shell=False, check=True) # config keyboard subprocess.run(['mkdir', g+"functions/hid.usb0"], shell=False, check=True) + time.sleep(0.2) os_echo(g+"functions/hid.usb0/protocol", "1") os_echo(g+"functions/hid.usb0/subclass", "1") os_echo(g+"functions/hid.usb0/report_length", "8") - os_echo(g+"functions/hid.usb0/report_desc", bytearray(b'\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0').encode()) + os_echo_bin(g+"functions/hid.usb0/report_desc", bytes(b'\x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0')) +# subprocess.run('echo -ne \\x05\\x01\\x09\\x06\\xa1\\x01\\x05\\x07\\x19\\xe0\\x29\\xe7\\x15\\x00\\x25\\x01\\x75\\x01\\x95\\x08\\x81\\x02\\x95\\x01\\x75\\x08\\x81\\x03\\x95\\x05\\x75\\x01\\x05\\x08\\x19\\x01\\x29\\x05\\x91\\x02\\x95\\x01\\x75\\x03\\x91\\x03\\x95\\x06\\x75\\x08\\x15\\x00\\x25\\x65\\x05\\x07\\x19\\x00\\x29\\x65\\x81\\x00\\xc0 > functions/hid.usb0/report_desc', shell=True) subprocess.run(['ln', '-s', g+"functions/hid.usb0", g+"configs/c.1"], shell=False, check=True)