2021-12-30 12:50 AM
In the official example(Ux_Device_HID_CDC_ACM),HID devices as mouse
/* Mouse event. Length is fixed to . */
hid_event->ux_device_class_hid_event_length = 3;
/* Set X position. */
hid_event->ux_device_class_hid_event_buffer[0] = x;
/* Set Y position. */
hid_event->ux_device_class_hid_event_buffer[1] = y;
hid_event->ux_device_class_hid_event_buffer[2] = 0;
/* Send an event to the hid */
ux_device_class_hid_event_set(hid, &hid_event);
but i want send key(right key or left key) to pc.
so i view google
Follow the above method,i Modified code
this is
/* Mouse event. Length is fixed to . */
hid_event->ux_device_class_hid_event_length = 4;
/* Set X position. */
hid_event->ux_device_class_hid_event_buffer[0] = 2;
/* Set Y position. */
hid_event->ux_device_class_hid_event_buffer[1] = x;
hid_event->ux_device_class_hid_event_buffer[2] = y;
hid_event->ux_device_class_hid_event_buffer[3] = 0x00;
/* Send an event to the hid */
ux_device_class_hid_event_set(hid, &hid_event);
i tested,finded not send key to pc.
so i ask how to do send a right or left key to pc?
2024-06-13 05:11 AM
hello!
The problem is that hid_mouse->ux_device_class_hid_report_id is setted to UX_TRUE (i don't known why).
That flag it as to be used if you have a report descriptor with more the one ID so the library attach at the front of the data array the byte hid_event->ux_device_class_hid_event_report_id
in your case you have a report descriptor with a unic ID (actually without an ID)
your interpretations of the buffer are correct:
hid_event->ux_device_class_hid_event_buffer[0] ---> buttons
hid_event->ux_device_class_hid_event_buffer[1] ---> X
hid_event->ux_device_class_hid_event_buffer[2] ---> Y
hid_event->ux_device_class_hid_event_buffer[3] ---> wheel
BUT with the flag setted to UX_TRUE the actual buffer become:
hid_event->ux_device_class_hid_event_buffer[0] ---> hid_event->ux_device_class_hid_event_report_id (that is 0)
hid_event->ux_device_class_hid_event_buffer[1] ---> buttons
hid_event->ux_device_class_hid_event_buffer[2] ---> X
hid_event->ux_device_class_hid_event_buffer[3] ---> Y
hid_event->ux_device_class_hid_event_buffer[4] ---> wheel
in the example the buttons are always 0
to fix that before ux_device_class_hid_event_set(hid_mouse, &hid_event);
make sure to:
hid_mouse->ux_device_class_hid_report_id = UX_FALSE;
so the hid_event->ux_device_class_hid_event_buffer[0] become actually the first byte sended