Mouse / Keyboard (FreeBSD): add support

This commit is contained in:
Carter Li
2024-10-10 09:30:20 +08:00
parent 4dbc9566da
commit 9dcfdcae83
3 changed files with 96 additions and 2 deletions
+2 -2
View File
@@ -628,7 +628,7 @@ elseif(FreeBSD)
src/detection/lm/lm_linux.c
src/detection/icons/icons_linux.c
src/detection/initsystem/initsystem_linux.c
src/detection/keyboard/keyboard_nosupport.c
src/detection/keyboard/keyboard_bsd.c
src/detection/libc/libc_bsd.c
src/detection/loadavg/loadavg_bsd.c
src/detection/locale/locale_linux.c
@@ -636,7 +636,7 @@ elseif(FreeBSD)
src/detection/gamepad/gamepad_bsd.c
src/detection/media/media_linux.c
src/detection/memory/memory_bsd.c
src/detection/mouse/mouse_nosupport.c
src/detection/mouse/mouse_bsd.c
src/detection/netio/netio_bsd.c
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
+47
View File
@@ -0,0 +1,47 @@
#include "keyboard.h"
#include "common/io/io.h"
#include <stdio.h>
#include <fcntl.h>
#include <usbhid.h>
#include <dev/usb/usb_ioctl.h>
#define MAX_UHID_JOYS 64
const char* ffDetectKeyboard(FFlist* devices /* List of FFKeyboardDevice */)
{
char path[16];
for (int i = 0; i < MAX_UHID_JOYS; i++)
{
snprintf(path, sizeof(path), "/dev/uhid%d", i);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) continue;
report_desc_t repDesc = hid_get_report_desc(fd);
if (!repDesc) continue;
int reportId = hid_get_report_id(fd);
struct hid_data* hData = hid_start_parse(repDesc, 0, reportId);
if (hData)
{
struct hid_item hItem;
while (hid_get_item(hData, &hItem) > 0)
{
if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 6) continue;
struct usb_device_info di;
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
{
FFKeyboardDevice* device = (FFKeyboardDevice*) ffListAdd(devices);
ffStrbufInitS(&device->serial, di.udi_serial);
ffStrbufInitS(&device->name, di.udi_product);
}
}
}
hid_dispose_report_desc(repDesc);
}
return NULL;
}
+47
View File
@@ -0,0 +1,47 @@
#include "mouse.h"
#include "common/io/io.h"
#include <stdio.h>
#include <fcntl.h>
#include <usbhid.h>
#include <dev/usb/usb_ioctl.h>
#define MAX_UHID_JOYS 64
const char* ffDetectMouse(FFlist* devices /* List of FFMouseDevice */)
{
char path[16];
for (int i = 0; i < MAX_UHID_JOYS; i++)
{
snprintf(path, sizeof(path), "/dev/uhid%d", i);
FF_AUTO_CLOSE_FD int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) continue;
report_desc_t repDesc = hid_get_report_desc(fd);
if (!repDesc) continue;
int reportId = hid_get_report_id(fd);
struct hid_data* hData = hid_start_parse(repDesc, 0, reportId);
if (hData)
{
struct hid_item hItem;
while (hid_get_item(hData, &hItem) > 0)
{
if (HID_PAGE(hItem.usage) != 1 || HID_USAGE(hItem.usage) != 2) continue;
struct usb_device_info di;
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
{
FFMouseDevice* device = (FFMouseDevice*) ffListAdd(devices);
ffStrbufInitS(&device->serial, di.udi_serial);
ffStrbufInitS(&device->name, di.udi_product);
}
}
}
hid_dispose_report_desc(repDesc);
}
return NULL;
}