// SPDX-License-Identifier: GPL-2.0 /* * UHID Example * * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> * * The code may be used by anyone for any purpose, * and can serve as a starting point for developing * applications using uhid.
*/
/* * UHID Example * This example emulates a basic 3 buttons mouse with wheel over UHID. Run this * program as root and then use the following keys to control the mouse: * q: Quit the application * 1: Toggle left button (down, up, ...) * 2: Toggle right button * 3: Toggle middle button * a: Move mouse left * d: Move mouse right * w: Move mouse up * s: Move mouse down * r: Move wheel up * f: Move wheel down * * Additionally to 3 button mouse, 3 keyboard LEDs are also supported (LED_NUML, * LED_CAPSL and LED_SCROLLL). The device doesn't generate any related keyboard * events, though. You need to manually write the EV_LED/LED_XY/1 activation * input event to the evdev device to see it being sent to this device. * * If uhid is not available as /dev/uhid, then you can pass a different path as * first argument. * If <linux/uhid.h> is not installed in /usr, then compile this with: * gcc -o ./uhid_test -Wall -I./include ./samples/uhid/uhid-example.c * And ignore the warning about kernel headers. However, it is recommended to * use the installed uhid.h if available.
*/
/* This parses raw output reports sent by the kernel to the device. A normal * uhid program shouldn't do this but instead just forward the raw report. * However, for ducomentational purposes, we try to detect LED events here and
* print debug messages for it. */ staticvoid handle_output(struct uhid_event *ev)
{ /* LED messages are adverised via OUTPUT reports; ignore the rest */ if (ev->u.output.rtype != UHID_OUTPUT_REPORT) return; /* LED reports have length 2 bytes */ if (ev->u.output.size != 2) return; /* first byte is report-id which is 0x02 for LEDs in our rdesc */ if (ev->u.output.data[0] != 0x2) return;
/* print flags payload */
fprintf(stderr, "LED output report received with flags %x\n",
ev->u.output.data[1]);
}
switch (ev.type) { case UHID_START:
fprintf(stderr, "UHID_START from uhid-dev\n"); break; case UHID_STOP:
fprintf(stderr, "UHID_STOP from uhid-dev\n"); break; case UHID_OPEN:
fprintf(stderr, "UHID_OPEN from uhid-dev\n"); break; case UHID_CLOSE:
fprintf(stderr, "UHID_CLOSE from uhid-dev\n"); break; case UHID_OUTPUT:
fprintf(stderr, "UHID_OUTPUT from uhid-dev\n");
handle_output(&ev); break; case UHID_OUTPUT_EV:
fprintf(stderr, "UHID_OUTPUT_EV from uhid-dev\n"); break; default:
fprintf(stderr, "Invalid event from uhid-dev: %u\n", ev.type);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.