I am trying to have my photon press key buttons through usb (USB HID) and I read that it is possible, however, I cannot find documentation or example code on how to do it. Maybe someone here can help me?
Itâs not officially implemented in the current firmware but will be in the upcoming 0.6.0.
If you feel comfortable with building the firmware with a local toolchain, you can already use these features.
@scruffr, out of interest, is there pre-release documentation for the USB HID interface?
Not that I know of, but I think Iâve seen something on GitHub either as an issue/pull request discussion.
I guess the feature branch back in 2014 and the related threads on here are a bit outdated.
@ScruffR, I understand that issue #528, âPhoton can function as a HID deviceâ, https://github.com/spark/firmware/issues/528, has been closed and due for release 0.6.0 as you have said.
Was really just wondering how HID USB was going to be implemented in relation to key make and break, control keys, function keys and the like.
In lieu of documentation, I took the leap and downloaded the firmware source code from Git and found these files:
./wiring/inc/spark_wiring_usbkeyboard.cpp
and
./wiring/inc/spark_wiring_usbkeyboard.h
which declared the USBKeyboard class and defines like:
KEY_LEFT_CTRL 0x80
KEY_LEFT_SHIFT 0x81
So this is good news.
The scary bit is that the source files were dated 31 March 2014âŚ
So, @Nimonster, it (hopefully) looks like just a little bit more patience is required!
These files from 2014 did already work back then and didnât need any alterations since they mainly deal with the standard/abstracted side of things.
The tricky part - which has changed since then - is the way how the USB HID descriptors were put together and how the respective HID objects would be exposed/made available for application code.
So no worries if the Wiring files donât change, as this end of the chain has to stay pretty much unaltered to keep Arduino compatibility.
Ok, thanks for the info
Is there any update on documentation so far?
There is no update on the feature for the current release either, so no point updating the docs for a non-present feature
So does that work or not?
https://github.com/spark/firmware/issues/528 is closed, Pull request is merged https://github.com/spark/firmware/pull/902 however using in Web IDE brings "âKeyboardâ was not declared in this scope"
Only available when compiling manually from develop branch?
Is Keyboard.begin()
included in current 0.6.0rc2? Still produces error when included in WEB IDE
My bad, havenât properly switched firmware version. Still currently 0.6.0 fails in WEBIDE with âServer failed to process requestâ, will try later
Yes, still no âKeyboardâ in 0.6.0rc2
'Keyboard' was not declared in this scope
But I thought it was merged in develop quite long time ago
That is very confusing. Git tag 0.6.0rc2 even has unit tests for Keyboard and Mouse, but they are not avaiable in Web IDE
There is, the only thing is that previously installed Particle drivers do interfere with the system HID drivers.
There is an elaborate info how to uninstall the old ones correctly with the respective pull request, but I also got it working by removing all Particle COM devices (including the drivers on the harddrive).
To do that you need DEVMGR_DISPLAY_NONPRESENT_DEVICES=1
in your environment variables and Show hidden devices
in DevMgr
Is 0.6.0-rc.2 related to 0.6.0-rc.2 tag in GIT? Iâm trying to use âKeyboard.begin()â and âMouse.begin()â that should already exist there, but Web IDE fails to use them. Git even has unit tests for them on that tag, so Iâd expect them working, but they are not
I moved this here since it didnât actually fit the other thread
See my post above
Why does it throws an error in Web IDE if it is there? See screenshot
I donât know.
This builds fine for me
void setup() {
Keyboard.begin();
Mouse.begin();
}
void loop() {
Keyboard.print("Hello");
Mouse.move(5,-5,0);
delay(1000);
}
Have you actually selected 0.6.0-rc.2 as target?
Keyboard is working fine for me too on 0.6.0-rc.2