HID Keyboard Packets

Hello,

I’m trying to use Particle Photon as a replacement of a USB card reader connected to a printer, the reader I’m replacing works as a keyboard emulator, when connected a computer both the Photon and the Card Reader behave the same, but when connected to the printer the Photon is recognized and registered as a card reader but the key strokes are not recognized by the printer.

I used USB analyzer to compare the packets sent from both devices as well as a USB Keyboard, I notice the Photon sends each key as 9 bytes, while the reader and my keyboard send 8 bytes.

Here is an example of KEY_1 packet:
02 00 00 1E 00 00 00 00 00 from Photon
00 00 1E 00 00 00 00 00 from Keyboard & Card Reader

It’s the same packet but photons always adds 02 at the start!

Is there any way to change that?

Thanks

Ameen

@azekie, I think you mean to refer to “packets” not “pockets” so I changed these in your post.

@azekie,

Interesting finding!

How are you sending KEY_1?

@UMB I’m sending key strokes using Keyboard.click, I also tried Keyboard.press and Keyboard.release methods with the same result.

Keyboard.click(KEY_1);

Looks like your printer does not correctly parse the HID report descriptor that Photon provides. Due to the fact that we are limited in the number of endpoints available, mouse and keyboard data is transmitted over a single USB endpoint (i.e. the Photon does not report itself as having two separate HID interfaces (keyboard and mouse) and instead reports a single compound HID interface: a mouse, keyboard and digitizer), however if your printer is USB HID-compliant, it should be able to understand that format.

There are some plans to support custom user-configurable HID devices (https://github.com/spark/firmware/issues/1294), but that’ll probably not happen in the nearest future.

If you’re OK with building locally and modifying the system firmware, here is a patch that shows a basic idea of what changes are required to report only the keyboard data (untested): https://gist.github.com/avtolstoy/8a5c0f78693cc6d1843d19040adaff52

3 Likes

@avtolstoy I applied the keyboard only patch last night, the packet now include 8 bytes for each key stroke, however the photon doesn’t seem to work as a keyboard anymore, nothing happens when I send keystrokes to the host computer.

1 Like