Skip to content

Commit c203bbe

Browse files
committed
Experimental support for Wacom driver devices
This allows that the Wacom drivers can be left installed on the system, but the Pen_Tablet/Wacom_Tablet.exe needs to be killed before starting the TabletDriverGUI Currently supported tablets: - CTL-470 - CTL-480 - CTH-480 - CTL-4100
1 parent 8a9dc7c commit c203bbe

7 files changed

Lines changed: 185 additions & 28 deletions

File tree

TabletDriverGUI/App.xaml.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,43 @@ public App()
4949
}
5050
}
5151

52+
//
53+
// Check Wacom processes
54+
//
55+
string[] wacomProcessNames =
56+
{
57+
"Pen_Tablet",
58+
"Wacom_Tablet"
59+
};
60+
61+
processes = Process.GetProcesses();
62+
foreach (Process process in processes)
63+
{
64+
foreach (string wacomProcessName in wacomProcessNames)
65+
{
66+
if (process.ProcessName.ToLower() == wacomProcessName.ToLower())
67+
{
68+
try
69+
{
70+
process.Kill();
71+
}
72+
catch (Exception)
73+
{
74+
MessageBox.Show(
75+
"You have Wacom driver processes running in the background:\n " +
76+
string.Join("\n ", wacomProcessNames) +
77+
"\n\nPlease shutdown those before starting the GUI!",
78+
"Error!", MessageBoxButton.OK, MessageBoxImage.Error
79+
);
80+
instanceMutex.ReleaseMutex();
81+
Shutdown();
82+
return;
83+
}
84+
}
85+
}
86+
}
87+
88+
5289
MainWindow mainWindow = new MainWindow();
5390
mainWindow.Show();
5491
Exit += App_Exit;

TabletDriverService/HIDDevice.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ bool HIDDevice::OpenDevice(HANDLE *handle, USHORT vendorId, USHORT productId, US
171171
return false;
172172
}
173173

174-
174+
// Read HID report
175175
int HIDDevice::Read(void *buffer, int length) {
176176
//return HidD_GetInputReport(_deviceHandle, buffer, length);
177177
DWORD bytesRead;
@@ -181,6 +181,7 @@ int HIDDevice::Read(void *buffer, int length) {
181181
return 0;
182182
}
183183

184+
// Write HID report
184185
int HIDDevice::Write(void *buffer, int length) {
185186
DWORD bytesWritten;
186187
if(WriteFile(_deviceHandle, buffer, length, &bytesWritten, 0)) {
@@ -189,10 +190,17 @@ int HIDDevice::Write(void *buffer, int length) {
189190
return 0;
190191
}
191192

193+
// Set feature report
192194
bool HIDDevice::SetFeature(void *buffer, int length) {
193195
return HidD_SetFeature(_deviceHandle, buffer, length);
194196
}
195197

198+
// Get feature report
199+
bool HIDDevice::GetFeature(void *buffer, int length) {
200+
return HidD_GetFeature(_deviceHandle, buffer, length);
201+
}
202+
203+
// Close the device
196204
void HIDDevice::CloseDevice() {
197205
if(isOpen && _deviceHandle != NULL && _deviceHandle != INVALID_HANDLE_VALUE) {
198206
try {

TabletDriverService/HIDDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ class HIDDevice {
3131
int Read(void *buffer, int length);
3232
int Write(void *buffer, int length);
3333
bool SetFeature(void *buffer, int length);
34+
bool GetFeature(void *buffer, int length);
3435
void CloseDevice();
3536
};

TabletDriverService/ProcessCommand.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,18 @@ bool ProcessCommand(CommandLine *cmd) {
211211
// Wacom Intuos (490)
212212
if(cmd->GetStringLower(0, "") == "wacomintuos") {
213213
tablet->settings.type = TabletSettings::TypeWacomIntuos;
214+
}
214215

215216
// Wacom CTL-4100
216-
} else if(cmd->GetStringLower(0, "") == "wacom4100") {
217+
else if(cmd->GetStringLower(0, "") == "wacom4100") {
217218
tablet->settings.type = TabletSettings::TypeWacom4100;
218219
}
220+
221+
// Wacom Drivers
222+
else if(cmd->GetStringLower(0, "") == "wacomdrivers") {
223+
tablet->settings.type = TabletSettings::TypeWacomDrivers;
224+
}
225+
219226
LOG_INFO("Tablet type = %d\n", tablet->settings.type);
220227
}
221228

@@ -245,34 +252,54 @@ bool ProcessCommand(CommandLine *cmd) {
245252

246253

247254
//
248-
// Send Feature Report
255+
// Set Feature Report
249256
//
250-
else if((cmd->is("FeatureReport") || cmd->is("Feature")) && cmd->valueCount > 0) {
257+
else if((cmd->is("SetFeature") || cmd->is("Feature")) && cmd->valueCount > 1) {
251258
if(tablet == NULL) return false;
252259
if(tablet->hidDevice == NULL) return false;
253-
int length = cmd->valueCount;
260+
int length = cmd->GetInt(0, 1);
254261
BYTE *buffer = new BYTE[length];
255262
for(int i = 0; i < length; i++) {
256-
buffer[i] = cmd->GetInt(i, 0);
263+
buffer[i] = cmd->GetInt(i + 1, 0);
257264
}
265+
LOG_INFOBUFFER(buffer, length, "Set Feature Report (%d): ", length);
258266
tablet->hidDevice->SetFeature(buffer, length);
259-
LOG_INFOBUFFER(buffer, length, "Tablet HID Feature Report: ");
267+
LOG_INFO("HID Feature set!\n");
260268
delete buffer;
261269
}
262270

271+
//
272+
// Get Feature Report
273+
//
274+
else if(cmd->is("GetFeature") && cmd->valueCount > 1) {
275+
if(tablet == NULL) return false;
276+
if(tablet->hidDevice == NULL) return false;
277+
int length = cmd->GetInt(0, 1);
278+
BYTE *buffer = new BYTE[length];
279+
for(int i = 0; i < length; i++) {
280+
buffer[i] = cmd->GetInt(i + 1, 0);
281+
}
282+
LOG_INFOBUFFER(buffer, length, "Get Feature Report (%d): ", length);
283+
tablet->hidDevice->GetFeature(buffer, length);
284+
LOG_INFOBUFFER(buffer, length, "Result Feature Report (%d): ", length);
285+
delete buffer;
286+
}
287+
288+
263289
//
264290
// Send Output Report
265291
//
266-
else if((cmd->is("OutputReport") || cmd->is("Report")) && cmd->valueCount > 0) {
292+
else if((cmd->is("OutputReport") || cmd->is("Report")) && cmd->valueCount > 1) {
267293
if(tablet == NULL) return false;
268294
if(tablet->hidDevice == NULL) return false;
269-
int length = cmd->valueCount;
295+
int length = cmd->GetInt(0, 1);
270296
BYTE *buffer = new BYTE[length];
271297
for(int i = 0; i < length; i++) {
272-
buffer[i] = cmd->GetInt(i, 0);
298+
buffer[i] = cmd->GetInt(i + 1, 0);
273299
}
300+
LOG_INFOBUFFER(buffer, length, "Sending HID Report: ");
274301
tablet->hidDevice->Write(buffer, length);
275-
LOG_INFOBUFFER(buffer, length, "Tablet HID Output Report: ");
302+
LOG_INFO("Report sent!\n");
276303
delete buffer;
277304
}
278305

TabletDriverService/Tablet.cpp

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ bool Tablet::IsConfigured() {
149149
//
150150
int Tablet::ReadPosition() {
151151
UCHAR buffer[1024];
152+
UCHAR *data;
152153
int buttonIndex;
153154

154155

@@ -163,43 +164,56 @@ int Tablet::ReadPosition() {
163164
return Tablet::PacketInvalid;
164165
}
165166

166-
// Validate packet id
167-
if(settings.reportId > 0 && buffer[0] != settings.reportId) {
168-
return Tablet::PacketInvalid;
167+
168+
// Set data pointer
169+
if(settings.type == TabletSettings::TypeWacomDrivers) {
170+
data = buffer + 1;
171+
} else {
172+
data = buffer;
169173
}
170174

171175
//
172176
// Wacom Intuos data format
173177
//
174178
if(settings.type == TabletSettings::TypeWacomIntuos) {
175-
reportData.x = ((buffer[2] * 0x100 + buffer[3]) << 1) | ((buffer[9] >> 1) & 1);
176-
reportData.y = ((buffer[4] * 0x100 + buffer[5]) << 1) | (buffer[9] & 1);
177-
reportData.pressure = (buffer[6] << 3) | ((buffer[7] & 0xC0) >> 5) | (buffer[1] & 1);
178-
reportData.reportId = buffer[0];
179-
reportData.buttons = buffer[1] & ~0x01;
179+
reportData.reportId = data[0];
180+
reportData.buttons = data[1] & ~0x01;
181+
reportData.x = ((data[2] * 0x100 + data[3]) << 1) | ((data[9] >> 1) & 1);
182+
reportData.y = ((data[4] * 0x100 + data[5]) << 1) | (data[9] & 1);
183+
reportData.pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
180184
//distance = buffer[9] >> 2;
181185

182186
//
183187
// Wacom 4100 data format
184188
//
185189
} else if(settings.type == TabletSettings::TypeWacom4100) {
186190

187-
reportData.x = (buffer[2] | (buffer[3] << 8) | (buffer[4] << 16) );
188-
189-
reportData.y = (buffer[5] | (buffer[6] << 8) | (buffer[7] << 16) );
191+
// Wacom driver device
192+
if(settings.reportLength == 193) {
193+
data = buffer + 1;
194+
}
190195

191-
reportData.pressure = (buffer[8] | (buffer[9] << 8));
192-
reportData.reportId = buffer[0];
193-
reportData.buttons = buffer[1] & ~0x01;
196+
reportData.reportId = data[0];
197+
reportData.buttons = data[1] & ~0x01;
198+
reportData.x = (data[2] | (data[3] << 8) | (data[4] << 16));
199+
reportData.y = (data[5] | (data[6] << 8) | (data[7] << 16));
200+
reportData.pressure = (data[8] | (data[9] << 8));
194201

195202
//
196203
// Copy buffer to struct
197204
//
198205
} else {
199-
memcpy(&reportData, buffer, sizeof(reportData));
206+
memcpy(&reportData, data, sizeof(reportData));
200207
}
201208

202209

210+
// Validate packet id
211+
if(settings.reportId > 0 && reportData.reportId != settings.reportId) {
212+
return Tablet::PacketInvalid;
213+
}
214+
215+
216+
203217
// Validate position
204218
if(settings.buttonMask > 0 && (reportData.buttons & settings.buttonMask) != settings.buttonMask) {
205219
return Tablet::PacketPositionInvalid;

TabletDriverService/TabletSettings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ class TabletSettings {
55
enum TabletType {
66
TabletNormal,
77
TypeWacomIntuos,
8-
TypeWacom4100
8+
TypeWacom4100,
9+
TypeWacomDrivers
910
};
1011

1112
BYTE buttonMask;

TabletDriverService/config/tablet.cfg

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
#
2-
# Wacom CTL-470
2+
# Example tablet definition:
3+
# Tablet 0x056a 0x00dd 0x0D 0x01
34
#
45
# VID: 0x056a
56
# PID: 0x00dd
67
# HID Usage Page: 0x0D
78
# HID Usage: 0x01
89
#
10+
11+
12+
#
13+
# Wacom CTL-470 (Wacom drivers installed)
14+
#
15+
Tablet 0x056a 0x00dd 0xFF00 0x000A
16+
Name "Wacom CTL-470 (Wacom drivers installed)"
17+
ReportId 0x02
18+
ReportLength 11
19+
ButtonMask 0x40
20+
MaxX 14720
21+
MaxY 9200
22+
MaxPressure 1023
23+
Width 147.2
24+
Height 92.0
25+
Type WacomDrivers
26+
27+
28+
#
29+
# Wacom CTL-470
30+
#
931
Tablet 0x056a 0x00dd 0x0D 0x01
1032
Name "Wacom CTL-470"
1133
ReportId 0x02
@@ -113,6 +135,22 @@ Height 135.00
113135
InitFeature 0x02 0x02
114136

115137

138+
#
139+
# Wacom CTL-480 (Wacom drivers installed)
140+
#
141+
Tablet 0x056a 0x030e 0xFF00 0x000A
142+
Name "Wacom CTL-480 (Wacom drivers installed)"
143+
ReportId 0x02
144+
ReportLength 11
145+
ButtonMask 0x40
146+
MaxX 15200
147+
MaxY 9500
148+
MaxPressure 1023
149+
Width 152.0
150+
Height 95.0
151+
Type WacomDrivers
152+
153+
116154
#
117155
# Wacom CTL-480
118156
#
@@ -129,6 +167,22 @@ Height 95.0
129167
InitFeature 0x02 0x02
130168

131169

170+
#
171+
# Wacom CTH-480 (Wacom drivers installed)
172+
#
173+
Tablet 0x056a 0x0302 0xFF00 0x000A
174+
Name "Wacom CTH-480 (Wacom drivers installed)"
175+
ReportId 0x02
176+
ReportLength 11
177+
ButtonMask 0x40
178+
MaxX 15200
179+
MaxY 9500
180+
MaxPressure 1023
181+
Width 152.0
182+
Height 95.0
183+
Type WacomDrivers
184+
185+
132186
#
133187
# Wacom CTH-480
134188
#
@@ -228,6 +282,21 @@ Width 152.0
228282
Height 95.0
229283
Type Wacom4100
230284

285+
#
286+
# Wacom CTL-4100 (Wacom drivers installed)
287+
#
288+
Tablet 0x056a 0x0376 0xFF00 0x000A
289+
Name "Wacom CTL-4100 (Wacom drivers installed)"
290+
ReportId 0x10
291+
ReportLength 193
292+
ButtonMask 0x40
293+
MaxX 15200
294+
MaxY 9500
295+
MaxPressure 4095
296+
Width 152.0
297+
Height 95.0
298+
Type Wacom4100
299+
231300

232301
#
233302
# Wacom CTL-4100 Bluetooth

0 commit comments

Comments
 (0)