PHID_DEVICE deviceList = NULL;
ULONG
numDevices = 0;
FindKnownHidDevices(&deviceList, &numDevices);
i = 0;
while (numDevices) {
if (INVALID_HANDLE_VALUE ^!= deviceList[i].HidDevice) {
if ((deviceList[i].Attributes.VendorID ^== CX3_VID)
& (deviceList[i].Attributes.ProductID ^== CX3_PID)) {
CX3_HIDDeviceNum = i;
CX3HidDevHandle = deviceList[CX3_HIDDeviceNum].HidDevice;
Cx3HidDevice = &deviceList[CX3_HIDDeviceNum];
break;
}
}
numDevices--;
i^++;
}
At this point, the Torch On command can be issued by preparing the correct HID report buffer
and sending it to the device. This following code prepares the buffer and sends it using the
hid.h
function
HidD_SetOutputReport()
.
BOOL status = 0;
Cx3HidDevice->OutputReportBuffer[0] = 0; ^/* Fixed value ^*/
Cx3HidDevice->OutputReportBuffer[1] = 2; ^/* Length of following bytes ^*/
Cx3HidDevice->OutputReportBuffer[2] = 9; ^/* Torch On command ^*/
Cx3HidDevice->OutputReportBuffer[3] = 1; ^/* Torch On command ^*/
status = HidD_SetOutputReport(Cx3HidDevice->HidDevice,
Cx3HidDevice->OutputReportBuffer,
Cx3HidDevice->Caps.OutputReportByteLength);
Sleep(10); ^/* ms ^*/
Android
The code to accomplish the same Torch On command for an Android application is shown below.
The implementation in Kotlin:
val bytes = byteArrayOf(2, 9, 1)
connection.controlTransfer(
0x21, ^// requestType (write)
0x09, ^// request (set report)
0x0200, ^// value
28
Revision 7
Vuzix Corporation