mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-25 09:17:12 +01:00
evdev: Detect whether input devices are accelerometers
Anything with X, Y and Z axes but no buttons is probably an accelerometer (this is the assumption made in udev). Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
parent
fdd945f2af
commit
aae53d5972
@ -33,6 +33,24 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
|
|||||||
int devclass = 0;
|
int devclass = 0;
|
||||||
unsigned long keyboard_mask;
|
unsigned long keyboard_mask;
|
||||||
|
|
||||||
|
/* X, Y, Z axes but no buttons probably means an accelerometer */
|
||||||
|
if (test_bit(EV_ABS, bitmask_ev) &&
|
||||||
|
test_bit(ABS_X, bitmask_abs) &&
|
||||||
|
test_bit(ABS_Y, bitmask_abs) &&
|
||||||
|
test_bit(ABS_Z, bitmask_abs) &&
|
||||||
|
!test_bit(EV_KEY, bitmask_ev)) {
|
||||||
|
return SDL_UDEV_DEVICE_ACCELEROMETER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RX, RY, RZ axes but no buttons also probably means an accelerometer */
|
||||||
|
if (test_bit(EV_ABS, bitmask_ev) &&
|
||||||
|
test_bit(ABS_RX, bitmask_abs) &&
|
||||||
|
test_bit(ABS_RY, bitmask_abs) &&
|
||||||
|
test_bit(ABS_RZ, bitmask_abs) &&
|
||||||
|
!test_bit(EV_KEY, bitmask_ev)) {
|
||||||
|
return SDL_UDEV_DEVICE_ACCELEROMETER;
|
||||||
|
}
|
||||||
|
|
||||||
if (test_bit(EV_ABS, bitmask_ev) &&
|
if (test_bit(EV_ABS, bitmask_ev) &&
|
||||||
test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
|
test_bit(ABS_X, bitmask_abs) && test_bit(ABS_Y, bitmask_abs)) {
|
||||||
if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
|
if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
|
||||||
|
@ -37,7 +37,8 @@ typedef enum
|
|||||||
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
|
SDL_UDEV_DEVICE_KEYBOARD = 0x0002,
|
||||||
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
|
SDL_UDEV_DEVICE_JOYSTICK = 0x0004,
|
||||||
SDL_UDEV_DEVICE_SOUND = 0x0008,
|
SDL_UDEV_DEVICE_SOUND = 0x0008,
|
||||||
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010
|
SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010,
|
||||||
|
SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020
|
||||||
} SDL_UDEV_deviceclass;
|
} SDL_UDEV_deviceclass;
|
||||||
|
|
||||||
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
|
#define BITS_PER_LONG (sizeof(unsigned long) * 8)
|
||||||
|
Loading…
Reference in New Issue
Block a user