From b67c7dd84f6174f439ccafc3339cd2e850e47930 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 17 Dec 2019 22:32:06 +0100 Subject: [PATCH] device: support digitizers via Win32 raw input API --- panda/src/device/inputDevice.cxx | 6 ++++++ panda/src/device/inputDevice.h | 6 ++++++ panda/src/device/phidsdi.h | 1 + panda/src/device/winInputDeviceManager.cxx | 9 +++++++-- panda/src/device/winRawInputDevice.cxx | 13 +++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/panda/src/device/inputDevice.cxx b/panda/src/device/inputDevice.cxx index cce2f975b4..71869abc64 100644 --- a/panda/src/device/inputDevice.cxx +++ b/panda/src/device/inputDevice.cxx @@ -578,6 +578,9 @@ format_device_class(DeviceClass dc) { case InputDevice::DeviceClass::spatial_mouse: return "spatial_mouse"; + + case InputDevice::DeviceClass::digitizer: + return "digitizer"; } return "**invalid**"; } @@ -644,6 +647,9 @@ format_axis(Axis axis) { case InputDevice::Axis::brake: return "brake"; + + case InputDevice::Axis::pressure: + return "pressure"; } return "**invalid**"; } diff --git a/panda/src/device/inputDevice.h b/panda/src/device/inputDevice.h index f3f500e378..83038075a8 100644 --- a/panda/src/device/inputDevice.h +++ b/panda/src/device/inputDevice.h @@ -80,6 +80,9 @@ PUBLISHED: // 3D mouse, such as produced by 3Dconnexion. spatial_mouse, + + // A graphics tablet with stylus/pen. + digitizer, }; enum class Feature { @@ -128,6 +131,9 @@ PUBLISHED: wheel, accelerator, brake, + + // Pen pressure + pressure, }; enum State { diff --git a/panda/src/device/phidsdi.h b/panda/src/device/phidsdi.h index 647b3ed322..5917155b0c 100644 --- a/panda/src/device/phidsdi.h +++ b/panda/src/device/phidsdi.h @@ -28,6 +28,7 @@ typedef USHORT USAGE, *PUSAGE; #define HID_USAGE_PAGE_KEYBOARD ((USAGE) 0x07) #define HID_USAGE_PAGE_LED ((USAGE) 0x08) #define HID_USAGE_PAGE_BUTTON ((USAGE) 0x09) +#define HID_USAGE_PAGE_DIGITIZER ((USAGE) 0x0d) #define HID_USAGE_GENERIC_POINTER ((USAGE) 0x01) #define HID_USAGE_GENERIC_MOUSE ((USAGE) 0x02) diff --git a/panda/src/device/winInputDeviceManager.cxx b/panda/src/device/winInputDeviceManager.cxx index 2ca4540ae6..0d2c69f216 100644 --- a/panda/src/device/winInputDeviceManager.cxx +++ b/panda/src/device/winInputDeviceManager.cxx @@ -14,6 +14,7 @@ #include "winInputDeviceManager.h" #include "winRawInputDevice.h" #include "throw_event.h" +#include "phidsdi.h" #if defined(_WIN32) && !defined(CPPPARSER) @@ -385,7 +386,7 @@ setup_message_loop() { } // Now listen for raw input devices using the created message loop. - RAWINPUTDEVICE rid[3]; + RAWINPUTDEVICE rid[4]; rid[0].usUsagePage = 1; rid[0].usUsage = 4; // Joysticks rid[0].dwFlags = RIDEV_DEVNOTIFY | RIDEV_INPUTSINK; @@ -398,7 +399,11 @@ setup_message_loop() { rid[2].usUsage = 8; // Multi-axis controllers (including 3D mice) rid[2].dwFlags = RIDEV_DEVNOTIFY | RIDEV_INPUTSINK; rid[2].hwndTarget = _message_hwnd; - if (!RegisterRawInputDevices(rid, 3, sizeof(RAWINPUTDEVICE))) { + rid[3].usUsagePage = HID_USAGE_PAGE_DIGITIZER; + rid[3].usUsage = 1; // Digitizers + rid[3].dwFlags = RIDEV_DEVNOTIFY | RIDEV_INPUTSINK; + rid[3].hwndTarget = _message_hwnd; + if (!RegisterRawInputDevices(rid, 4, sizeof(RAWINPUTDEVICE))) { device_cat.warning() << "Failed to register raw input devices.\n"; } diff --git a/panda/src/device/winRawInputDevice.cxx b/panda/src/device/winRawInputDevice.cxx index 10262d124c..843e434a16 100644 --- a/panda/src/device/winRawInputDevice.cxx +++ b/panda/src/device/winRawInputDevice.cxx @@ -199,6 +199,11 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) { info.hid.usUsage == HID_USAGE_GENERIC_KEYBOARD) { _device_class = DeviceClass::keyboard; + // Digitizers + } else if (info.hid.usUsagePage == HID_USAGE_PAGE_DIGITIZER && + info.hid.usUsage == 1) { + _device_class = DeviceClass::digitizer; + // 3Dconnexion SpaceNavigator and friends. } else if (_vendor_id == 0x046d && (_product_id == 0xc623 || @@ -504,6 +509,14 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) { continue; } break; + + case HID_USAGE_PAGE_DIGITIZER: + switch (usage) { + case 0x30: + axis = Axis::pressure; + break; + } + break; } // If this axis already exists, don't double-map it, but take the first