Open
Description
Current implementation of HID API is lacking important mechanism of the USB HID protocol, which allows host to request the parameters from the device as necessary, or update these parameters, thus implementing the host-to-device feedback and control.
The proposed modification would allow to declare a public variable in the Arduino sketch and pass its address to the HID library. The library stores the address along with HID feature ID. Once the host requests the feature, the HID library retrieves the feature by ID and address and passes the value back to the host. The feature value can be also updated by the host.
The code in the sketch implementing the feature can be very simple, for example:
// SomeHIDDevice can be Mouse, Keyboard, PowerDevice etc and usually is the place where we define the
// HID device descriptor.
#include <SomeHIDDevice.h>
uint16_t iPresentStatus = 0
void setup() {
SomeHIDDevice.begin();
// here we call the wrapper of the SetFeature method defined in the SomeHIDDevice and pass the
// address of the variable, which will hold the value of the feature, to the HID library
SomeHIDDevice.setFeature(HID_PRESENT_STATUS, &iPresentStatus, sizeof(iPresentStatus));
}
void loop() {
// iPresentStatus can be updated here at any point and the current value will be visible to the host.
// The host can also update this variable if the feature is declared as RW
iPresentStatus = 1;
}
Metadata
Metadata
Assignees
Labels
No labels