Skip to content

Commit

Permalink
Experimental support for Wacom driver devices
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hawku committed Mar 24, 2018
1 parent 8a9dc7c commit c203bbe
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 28 deletions.
37 changes: 37 additions & 0 deletions TabletDriverGUI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,43 @@ public App()
}
}

//
// Check Wacom processes
//
string[] wacomProcessNames =
{
"Pen_Tablet",
"Wacom_Tablet"
};

processes = Process.GetProcesses();
foreach (Process process in processes)
{
foreach (string wacomProcessName in wacomProcessNames)
{
if (process.ProcessName.ToLower() == wacomProcessName.ToLower())

This comment has been minimized.

Copy link
@Dico200

Dico200 Mar 30, 2018

are there not any other criteria you can use to check that the process is indeed the wacom driver? Maybe the file location, which should have other files in that folder? Any process can have the name "Pen_Tablet.exe". Sorry if pain.

This comment has been minimized.

Copy link
@hawku

hawku Mar 31, 2018

Author Owner

If you have a better solution for that, please create a pull request, thanks.

{
try
{
process.Kill();
}
catch (Exception)
{
MessageBox.Show(
"You have Wacom driver processes running in the background:\n " +
string.Join("\n ", wacomProcessNames) +
"\n\nPlease shutdown those before starting the GUI!",
"Error!", MessageBoxButton.OK, MessageBoxImage.Error
);
instanceMutex.ReleaseMutex();
Shutdown();
return;
}
}
}
}


MainWindow mainWindow = new MainWindow();
mainWindow.Show();
Exit += App_Exit;
Expand Down
10 changes: 9 additions & 1 deletion TabletDriverService/HIDDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ bool HIDDevice::OpenDevice(HANDLE *handle, USHORT vendorId, USHORT productId, US
return false;
}


// Read HID report
int HIDDevice::Read(void *buffer, int length) {
//return HidD_GetInputReport(_deviceHandle, buffer, length);
DWORD bytesRead;
Expand All @@ -181,6 +181,7 @@ int HIDDevice::Read(void *buffer, int length) {
return 0;
}

// Write HID report
int HIDDevice::Write(void *buffer, int length) {
DWORD bytesWritten;
if(WriteFile(_deviceHandle, buffer, length, &bytesWritten, 0)) {
Expand All @@ -189,10 +190,17 @@ int HIDDevice::Write(void *buffer, int length) {
return 0;
}

// Set feature report
bool HIDDevice::SetFeature(void *buffer, int length) {
return HidD_SetFeature(_deviceHandle, buffer, length);
}

// Get feature report
bool HIDDevice::GetFeature(void *buffer, int length) {
return HidD_GetFeature(_deviceHandle, buffer, length);
}

// Close the device
void HIDDevice::CloseDevice() {
if(isOpen && _deviceHandle != NULL && _deviceHandle != INVALID_HANDLE_VALUE) {
try {
Expand Down
1 change: 1 addition & 0 deletions TabletDriverService/HIDDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class HIDDevice {
int Read(void *buffer, int length);
int Write(void *buffer, int length);
bool SetFeature(void *buffer, int length);
bool GetFeature(void *buffer, int length);
void CloseDevice();
};
47 changes: 37 additions & 10 deletions TabletDriverService/ProcessCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,18 @@ bool ProcessCommand(CommandLine *cmd) {
// Wacom Intuos (490)
if(cmd->GetStringLower(0, "") == "wacomintuos") {
tablet->settings.type = TabletSettings::TypeWacomIntuos;
}

// Wacom CTL-4100
} else if(cmd->GetStringLower(0, "") == "wacom4100") {
else if(cmd->GetStringLower(0, "") == "wacom4100") {
tablet->settings.type = TabletSettings::TypeWacom4100;
}

// Wacom Drivers
else if(cmd->GetStringLower(0, "") == "wacomdrivers") {
tablet->settings.type = TabletSettings::TypeWacomDrivers;
}

LOG_INFO("Tablet type = %d\n", tablet->settings.type);
}

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


//
// Send Feature Report
// Set Feature Report
//
else if((cmd->is("FeatureReport") || cmd->is("Feature")) && cmd->valueCount > 0) {
else if((cmd->is("SetFeature") || cmd->is("Feature")) && cmd->valueCount > 1) {
if(tablet == NULL) return false;
if(tablet->hidDevice == NULL) return false;
int length = cmd->valueCount;
int length = cmd->GetInt(0, 1);
BYTE *buffer = new BYTE[length];
for(int i = 0; i < length; i++) {
buffer[i] = cmd->GetInt(i, 0);
buffer[i] = cmd->GetInt(i + 1, 0);
}
LOG_INFOBUFFER(buffer, length, "Set Feature Report (%d): ", length);
tablet->hidDevice->SetFeature(buffer, length);
LOG_INFOBUFFER(buffer, length, "Tablet HID Feature Report: ");
LOG_INFO("HID Feature set!\n");
delete buffer;
}

//
// Get Feature Report
//
else if(cmd->is("GetFeature") && cmd->valueCount > 1) {
if(tablet == NULL) return false;
if(tablet->hidDevice == NULL) return false;
int length = cmd->GetInt(0, 1);
BYTE *buffer = new BYTE[length];
for(int i = 0; i < length; i++) {
buffer[i] = cmd->GetInt(i + 1, 0);
}
LOG_INFOBUFFER(buffer, length, "Get Feature Report (%d): ", length);
tablet->hidDevice->GetFeature(buffer, length);
LOG_INFOBUFFER(buffer, length, "Result Feature Report (%d): ", length);
delete buffer;
}


//
// Send Output Report
//
else if((cmd->is("OutputReport") || cmd->is("Report")) && cmd->valueCount > 0) {
else if((cmd->is("OutputReport") || cmd->is("Report")) && cmd->valueCount > 1) {
if(tablet == NULL) return false;
if(tablet->hidDevice == NULL) return false;
int length = cmd->valueCount;
int length = cmd->GetInt(0, 1);
BYTE *buffer = new BYTE[length];
for(int i = 0; i < length; i++) {
buffer[i] = cmd->GetInt(i, 0);
buffer[i] = cmd->GetInt(i + 1, 0);
}
LOG_INFOBUFFER(buffer, length, "Sending HID Report: ");
tablet->hidDevice->Write(buffer, length);
LOG_INFOBUFFER(buffer, length, "Tablet HID Output Report: ");
LOG_INFO("Report sent!\n");
delete buffer;
}

Expand Down
44 changes: 29 additions & 15 deletions TabletDriverService/Tablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ bool Tablet::IsConfigured() {
//
int Tablet::ReadPosition() {
UCHAR buffer[1024];
UCHAR *data;
int buttonIndex;


Expand All @@ -163,43 +164,56 @@ int Tablet::ReadPosition() {
return Tablet::PacketInvalid;
}

// Validate packet id
if(settings.reportId > 0 && buffer[0] != settings.reportId) {
return Tablet::PacketInvalid;

// Set data pointer
if(settings.type == TabletSettings::TypeWacomDrivers) {
data = buffer + 1;
} else {
data = buffer;
}

//
// Wacom Intuos data format
//
if(settings.type == TabletSettings::TypeWacomIntuos) {
reportData.x = ((buffer[2] * 0x100 + buffer[3]) << 1) | ((buffer[9] >> 1) & 1);
reportData.y = ((buffer[4] * 0x100 + buffer[5]) << 1) | (buffer[9] & 1);
reportData.pressure = (buffer[6] << 3) | ((buffer[7] & 0xC0) >> 5) | (buffer[1] & 1);
reportData.reportId = buffer[0];
reportData.buttons = buffer[1] & ~0x01;
reportData.reportId = data[0];
reportData.buttons = data[1] & ~0x01;
reportData.x = ((data[2] * 0x100 + data[3]) << 1) | ((data[9] >> 1) & 1);
reportData.y = ((data[4] * 0x100 + data[5]) << 1) | (data[9] & 1);
reportData.pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1);
//distance = buffer[9] >> 2;

//
// Wacom 4100 data format
//
} else if(settings.type == TabletSettings::TypeWacom4100) {

reportData.x = (buffer[2] | (buffer[3] << 8) | (buffer[4] << 16) );

reportData.y = (buffer[5] | (buffer[6] << 8) | (buffer[7] << 16) );
// Wacom driver device
if(settings.reportLength == 193) {
data = buffer + 1;
}

reportData.pressure = (buffer[8] | (buffer[9] << 8));
reportData.reportId = buffer[0];
reportData.buttons = buffer[1] & ~0x01;
reportData.reportId = data[0];
reportData.buttons = data[1] & ~0x01;
reportData.x = (data[2] | (data[3] << 8) | (data[4] << 16));
reportData.y = (data[5] | (data[6] << 8) | (data[7] << 16));
reportData.pressure = (data[8] | (data[9] << 8));

//
// Copy buffer to struct
//
} else {
memcpy(&reportData, buffer, sizeof(reportData));
memcpy(&reportData, data, sizeof(reportData));
}


// Validate packet id
if(settings.reportId > 0 && reportData.reportId != settings.reportId) {
return Tablet::PacketInvalid;
}



// Validate position
if(settings.buttonMask > 0 && (reportData.buttons & settings.buttonMask) != settings.buttonMask) {
return Tablet::PacketPositionInvalid;
Expand Down
3 changes: 2 additions & 1 deletion TabletDriverService/TabletSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class TabletSettings {
enum TabletType {
TabletNormal,
TypeWacomIntuos,
TypeWacom4100
TypeWacom4100,
TypeWacomDrivers
};

BYTE buttonMask;
Expand Down
71 changes: 70 additions & 1 deletion TabletDriverService/config/tablet.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
#
# Wacom CTL-470
# Example tablet definition:
# Tablet 0x056a 0x00dd 0x0D 0x01
#
# VID: 0x056a
# PID: 0x00dd
# HID Usage Page: 0x0D
# HID Usage: 0x01
#


#
# Wacom CTL-470 (Wacom drivers installed)
#
Tablet 0x056a 0x00dd 0xFF00 0x000A
Name "Wacom CTL-470 (Wacom drivers installed)"
ReportId 0x02
ReportLength 11
ButtonMask 0x40
MaxX 14720
MaxY 9200
MaxPressure 1023
Width 147.2
Height 92.0
Type WacomDrivers


#
# Wacom CTL-470
#
Tablet 0x056a 0x00dd 0x0D 0x01
Name "Wacom CTL-470"
ReportId 0x02
Expand Down Expand Up @@ -113,6 +135,22 @@ Height 135.00
InitFeature 0x02 0x02


#
# Wacom CTL-480 (Wacom drivers installed)
#
Tablet 0x056a 0x030e 0xFF00 0x000A
Name "Wacom CTL-480 (Wacom drivers installed)"
ReportId 0x02
ReportLength 11
ButtonMask 0x40
MaxX 15200
MaxY 9500
MaxPressure 1023
Width 152.0
Height 95.0
Type WacomDrivers


#
# Wacom CTL-480
#
Expand All @@ -129,6 +167,22 @@ Height 95.0
InitFeature 0x02 0x02


#
# Wacom CTH-480 (Wacom drivers installed)
#
Tablet 0x056a 0x0302 0xFF00 0x000A
Name "Wacom CTH-480 (Wacom drivers installed)"
ReportId 0x02
ReportLength 11
ButtonMask 0x40
MaxX 15200
MaxY 9500
MaxPressure 1023
Width 152.0
Height 95.0
Type WacomDrivers


#
# Wacom CTH-480
#
Expand Down Expand Up @@ -228,6 +282,21 @@ Width 152.0
Height 95.0
Type Wacom4100

#
# Wacom CTL-4100 (Wacom drivers installed)
#
Tablet 0x056a 0x0376 0xFF00 0x000A
Name "Wacom CTL-4100 (Wacom drivers installed)"
ReportId 0x10
ReportLength 193
ButtonMask 0x40
MaxX 15200
MaxY 9500
MaxPressure 4095
Width 152.0
Height 95.0
Type Wacom4100


#
# Wacom CTL-4100 Bluetooth
Expand Down

0 comments on commit c203bbe

Please sign in to comment.