In this article, we will discuss how to connect and use Web HID devices on Ubuntu Desktop 24.04 LTS with a Dell XPS. Web HID devices are a variety of devices known to work on Windows, but none of the GPIO devices appear to work on Ubuntu.
Prerequisites
Before we begin, ensure that your Ubuntu system is up-to-date by running the following command:
sudo apt update && sudo apt upgrade
Connecting Web HID Devices
To connect a Web HID device, simply plug it into one of the USB ports on your Dell XPS. The system should automatically detect and install the necessary drivers. You can verify if the device is connected by running the following command:
lsusb
You should see the device's vendor and product IDs listed in the output.
Testing Web HID Devices
To test if the device is working correctly, you can use the evtest command. Replace /dev/input/eventX with the path of your device's event file, which you can find using the lsusb command:
evtest /dev/input/eventX
You should see a stream of events being printed to the console, indicating that the device is functioning properly.
Using Web HID Devices
To use a Web HID device in your applications, you can use the Linux Input API. Here's a simple example of how to read data from a keyboard:
#include <fcntl.h>
#include <linux/input.h>
#include <sys/ioctl.h>
#include <unistd.h>
#define DEVICE "/dev/input/event0"
int main() {
int fd = open(DEVICE, O_RDONLY);
if (fd < 0) {
perror("Failed to open device");
return 1;
}
struct input_event event;
while (1) {
ssize_t n = read(fd, &event, sizeof(event));
if (n < 0) {
perror("Failed to read event");
break;
}
if (event.type == EV_KEY && event.value == 1) {
printf("Key %d pressed
", event.code);
} else if (event.type == EV_KEY && event.value == 0) {
printf("Key %d released
", event.code);
}
}
close(fd);
return 0;
}
Save this code in a file named keyboard.c, then compile and run it:
gcc keyboard.c -o keyboard
./keyboard
You should see messages indicating when keys are pressed and released.
References
This article has covered the basics of connecting and using Web HID devices on Ubuntu Desktop 24.04 LTS with a Dell XPS. By understanding the Linux Input API, you can build applications that interact with these devices.