Add support for XP-PEN tablet

Tested on XP-PEN Artist 22 Pro
WTPacket while loop was infinite on XP-PEN
This commit is contained in:
Anaël Seghezzi 2020-02-06 11:27:58 +01:00
parent f47bd94967
commit 8533f58c91
3 changed files with 24 additions and 12 deletions

View File

@ -168,10 +168,14 @@ static GLFWbool loadLibraries(void)
GetProcAddress(_glfw.win32.wintab32.instance, "WTOpenA");
_glfw.win32.wintab32.WTQueueSizeSet = (PFN_WTQueueSizeSet)
GetProcAddress(_glfw.win32.wintab32.instance, "WTQueueSizeSet");
_glfw.win32.wintab32.WTQueueSizeGet = (PFN_WTQueueSizeGet)
GetProcAddress(_glfw.win32.wintab32.instance, "WTQueueSizeGet");
_glfw.win32.wintab32.WTClose = (PFN_WTClose)
GetProcAddress(_glfw.win32.wintab32.instance, "WTClose");
_glfw.win32.wintab32.WTPacket = (PFN_WTPacket)
GetProcAddress(_glfw.win32.wintab32.instance, "WTPacket");
_glfw.win32.wintab32.WTPacketsGet = (PFN_WTPacketsGet)
GetProcAddress(_glfw.win32.wintab32.instance, "WTPacketsGet");
}
return GLFW_TRUE;
@ -366,7 +370,9 @@ static void initWintabContext(HWND hwnd)
// open wintab context
_glfw.win32.wintab32.context = _glfw.win32.wintab32.WTOpenA(hwnd, &context, TRUE);
if (_glfw.win32.wintab32.context) {
_glfw.win32.wintab32.WTQueueSizeSet(_glfw.win32.wintab32.context, 256);
int curr_queue_size = _glfw.win32.wintab32.WTQueueSizeGet(_glfw.win32.wintab32.context);
if (!_glfw.win32.wintab32.WTQueueSizeSet(_glfw.win32.wintab32.context, 256))
_glfw.win32.wintab32.WTQueueSizeSet(_glfw.win32.wintab32.context, curr_queue_size);
_glfw.win32.wintab32.WTInfoA(4, 0, &_glfw.win32.wintab32.contextInfo);
_glfw.win32.wintab32.WTInfoA(100, 15, &_glfw.win32.wintab32.pressureInfo);
_glfw.win32.wintab32.WTInfoA(100, 17, &_glfw.win32.wintab32.orientationInfo);

View File

@ -327,8 +327,10 @@ typedef struct LOGCONTEXTA {
typedef UINT (WINAPI * PFN_WTInfoA)(UINT,UINT,LPVOID);
typedef HCTX (WINAPI * PFN_WTOpenA)(HWND,LPLOGCONTEXTA,BOOL);
typedef BOOL (WINAPI * PFN_WTQueueSizeSet)(HCTX,int);
typedef int (WINAPI * PFN_WTQueueSizeGet)(HCTX);
typedef BOOL (WINAPI * PFN_WTClose)(HCTX);
typedef BOOL (WINAPI * PFN_WTPacket)(HCTX,UINT,LPVOID);
typedef int (WINAPI * PFN_WTPacketsGet)(HCTX, int, LPVOID);
typedef VkFlags VkWin32SurfaceCreateFlagsKHR;
@ -460,8 +462,10 @@ typedef struct _GLFWlibraryWin32
PFN_WTInfoA WTInfoA;
PFN_WTOpenA WTOpenA;
PFN_WTQueueSizeSet WTQueueSizeSet;
PFN_WTQueueSizeGet WTQueueSizeGet;
PFN_WTClose WTClose;
PFN_WTPacket WTPacket;
PFN_WTPacketsGet WTPacketsGet;
HCTX context;
LOGCONTEXTA contextInfo;
AXIS pressureInfo;

View File

@ -626,33 +626,35 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfw.win32.wintab32.instance)
{
#define FIX2DOUBLE(x) ((double)(HIWORD(x))+((double)LOWORD(x)/65536))
PACKET packet;
static PACKET packet_buffer[256];
LOGCONTEXTA contextInfo = _glfw.win32.wintab32.contextInfo;
AXIS pressureInfo = _glfw.win32.wintab32.pressureInfo;
AXIS altInfo = _glfw.win32.wintab32.orientationInfo[1];
AXIS aziInfo = _glfw.win32.wintab32.orientationInfo[0];
AXIS rollInfo = _glfw.win32.wintab32.orientationInfo[2];
int i, packet_count;
while (_glfw.win32.wintab32.WTPacket(_glfw.win32.wintab32.context, (UINT)wParam, &packet)) {
packet_count = _glfw.win32.wintab32.WTPacketsGet(_glfw.win32.wintab32.context, 256, packet_buffer);
for (i = 0; i < packet_count; i++) {
double x, y, z, pressure, pitch=0, yaw=0, roll=0;
x = ((double)(packet.x - contextInfo.lcInOrgX) / contextInfo.lcInExtX) * contextInfo.lcSysExtX + contextInfo.lcSysOrgX;
y = ((double)(packet.y - contextInfo.lcInOrgY) / contextInfo.lcInExtY) * contextInfo.lcSysExtY + contextInfo.lcSysOrgY;
z = packet.z / 1024.0;
pressure = (double)(packet.normalPressure - pressureInfo.min) / (pressureInfo.max - pressureInfo.min);
x = ((double)(packet_buffer[i].x - contextInfo.lcInOrgX) / contextInfo.lcInExtX) * contextInfo.lcSysExtX + contextInfo.lcSysOrgX;
y = ((double)(packet_buffer[i].y - contextInfo.lcInOrgY) / contextInfo.lcInExtY) * contextInfo.lcSysExtY + contextInfo.lcSysOrgY;
z = packet_buffer[i].z / 1024.0;
pressure = (double)(packet_buffer[i].normalPressure - pressureInfo.min) / (pressureInfo.max - pressureInfo.min);
if (aziInfo.resolution && altInfo.resolution) {
double alt = (double)(packet.orientation.altitude - altInfo.min) / (altInfo.max - altInfo.min);
double azi = (double)(packet.orientation.azimuth - aziInfo.min) / (aziInfo.max - aziInfo.min);
double alt = (double)(packet_buffer[i].orientation.altitude - altInfo.min) / (altInfo.max - altInfo.min);
double azi = (double)(packet_buffer[i].orientation.azimuth - aziInfo.min) / (aziInfo.max - aziInfo.min);
pitch = alt * 3.14159265359;
yaw = azi * 6.28318530718;
}
if (rollInfo.resolution) { // roll seems to be mostly unsupported so this is untested
roll = (double)(packet.orientation.twist - rollInfo.min) / (rollInfo.max - rollInfo.min) * 360.0;
roll = (double)(packet_buffer[i].orientation.twist - rollInfo.min) / (rollInfo.max - rollInfo.min) * 360.0;
}
if (packet.changed & 0x0020) { // CURSOR changed
_glfwInputPenTabletCursor(packet.cursor);
if (packet_buffer[i].changed & 0x0020) { // CURSOR changed
_glfwInputPenTabletCursor(packet_buffer[i].cursor);
}
_glfwInputPenTabletData(x, y, z, pressure, pitch, yaw, roll);