USB HID mode

Discussion related to "under the hood" OpenMV topics.
haar_matey
Posts: 5
Joined: Mon Jun 18, 2018 12:01 am

USB HID mode

Postby haar_matey » Mon Jun 18, 2018 12:11 am

Is it possible to use USB HID mode with OpenMV? It's mentioned on this page, but I can't seem to get it to work

http://docs.openmv.io/library/pyb.USB_HID.html

Here's the code I'm using

Code: Select all

import sensor, image, time, math
import pyb

# I've tried both modes here but neither works, so moved it to a separate boot.py script
#pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard)
#pyb.usb_mode('CDC+HID', hid=pyb.hid_keyboard)
hid = pyb.USB_HID()

red_led = pyb.LED(1)
green_led = pyb.LED(2)
blue_led = pyb.LED(3)
ir_leds = pyb.LED(4)
red_led.off();
green_led.off();
blue_led.off();
ir_leds.off();

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA) # High Res!
sensor.set_windowing((640, 10)) # V Res of 80 == less work (40 for 2X the speed).
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    codes = img.find_barcodes()
    for code in codes:
        img.draw_rectangle(code.rect())
        print_args = (code.type(), code.payload(), (180 * code.rotation()) / math.pi, code.quality(), clock.fps())
        print("Barcode {}, Payload \"{}\", rotation {} (degrees), quality {}, FPS {}".format(*print_args))
        green_led.on()
        for c in code.payload():
            buf = bytearray(8)
            buf[0] = 0x00 # no modifier keys
            buf[2] = 0x17 # just send char 'T' for now
            hid.send(buf)
            pyb.delay(5)
            buf[0] = 0x00 # no modifier keys
            buf[2] = 0x00 # release key
            hid.send(buf)
            pyb.delay(5)
    if not codes:
        green_led.off()

And I've also tried it in boot.py

Code: Select all

import pyb
#pyb.usb_mode('HID', hid=pyb.hid_keyboard)
pyb.usb_mode('VCP+HID', hid=pyb.hid_keyboard)
#pyb.usb_mode('CDC+HID', hid=pyb.hid_keyboard)
I've got both of these files on an SD card with the thinking that I'd need to remove it to get back access to the internal flash.

The green light flashes when a barcode is detected, so the script seems to run fine without errors (although I'm not sure if boot.py is running beforehand), but it's not passing an HID data to my laptop (Mac OS)

Thanks
User avatar
iabdalkader
Posts: 482
Joined: Sun May 24, 2015 3:53 pm

Re: USB HID mode

Postby iabdalkader » Mon Jun 18, 2018 12:27 am

HID mode is not enabled, I'll see if I can enable it before the next release.

Note: main.py and boot.py can run from SD or Flash the same, but we don't use boot.py so it's ignored.
haar_matey
Posts: 5
Joined: Mon Jun 18, 2018 12:01 am

Re: USB HID mode

Postby haar_matey » Mon Jun 18, 2018 12:41 am

Thanks that would be awesome!
User avatar
kwagyeman
Posts: 2045
Joined: Sun May 24, 2015 2:10 pm

Re: USB HID mode

Postby kwagyeman » Mon Jun 18, 2018 1:39 pm

Mmm, the documentation generator included that file in the doc tree even though there are no links to it.

Not sure how to hide these files. I disabled them in the index but they still show up.
Nyamekye,
User avatar
iabdalkader
Posts: 482
Joined: Sun May 24, 2015 3:53 pm

Re: USB HID mode

Postby iabdalkader » Tue Jun 19, 2018 7:53 pm

I re-enabled boot.py, you'll be able to use it as usual (note only VCP+MSC and VCP+HID are tested and working, I wouldn't try anything else).
haar_matey
Posts: 5
Joined: Mon Jun 18, 2018 12:01 am

Re: USB HID mode

Postby haar_matey » Tue Jun 19, 2018 9:04 pm

Thanks iabdalkader, do I need to update firmware for this to take effect?
User avatar
iabdalkader
Posts: 482
Joined: Sun May 24, 2015 3:53 pm

Re: USB HID mode

Postby iabdalkader » Tue Jun 19, 2018 9:39 pm

Yes from github if u don't want to wait for the next release.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 5 guests