Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #31 from InfinityGhost/stringcontains
Browse files Browse the repository at this point in the history
Add DeviceStringContains command
  • Loading branch information
InfinityGhost authored Nov 21, 2019
2 parents cc13baa + 362fc7e commit 82640e4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
74 changes: 74 additions & 0 deletions TabletDriverService/CommandHandler.Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,79 @@ void CommandHandler::CreateDeviceCommands() {
return true;

}));

AddAlias("StringContains", "DeviceStringContains");
AddHelp("DeviceStringContains", "Usage:");
AddHelp("DeviceStringContains", " DeviceStringContains <string id> \"<match>\"");
AddHelp("DeviceStringContains", " DeviceStringContains Manufacturer \"<match>\"");
AddHelp("DeviceStringContains", " DeviceStringContains Product \"<match>\"");
AddHelp("DeviceStringContains", " DeviceStringContains SerialNumber \"<match>\"");
AddCommand(new Command("DeviceStringContains", [&](CommandLine *cmd) {
if (cmd->valueCount <= 1) {
ExecuteCommand("Help", "DeviceStringContains");
return false;
}
if (tablet == NULL) return false;

int stringId = cmd->GetInt(0, 0);
std::string stringName = cmd->GetStringLower(0, "");
std::string matchString = cmd->GetString(1, "");
std::string deviceString = "";

// Manufacturer
if (stringName.compare(0, 3, "man") == 0) {
stringName = "Manufacturer";
deviceString = tablet->GetDeviceManufacturerName();
}

// Product name
else if (stringName.compare(0, 3, "pro") == 0) {
stringName = "Product";
deviceString = tablet->GetDeviceProductName();
}

// Serial number
else if (stringName.compare(0, 3, "ser") == 0) {
stringName = "SerialNumber";
deviceString = tablet->GetDeviceSerialNumber();
}

// Request device string
else {
stringName = std::to_string(stringId);
if (stringId == 0) {
LOG_ERROR("Invalid string id!\n");
return false;
}
try {
deviceString = tablet->GetDeviceString(stringId);
}
catch (std::exception&e) {
LOG_ERROR("%s\n", e.what());
}
}

// Does the string contain the matching term?
if (deviceString.find(matchString) != std::string::npos) {
LOG_INFO("Device string (%s) '%s' contains '%s'\n",
stringName.c_str(),
deviceString.c_str(),
matchString.c_str()
);
return true;
}

// Does not contain the matching term
else {
LOG_INFO("Device string (%s) '%s' does not contain '%s'. Tablet invalid!\n",
stringName.c_str(),
deviceString.c_str(),
matchString.c_str()
);
delete tablet;
tablet = NULL;
return false;
}
return true;
}));
}
2 changes: 1 addition & 1 deletion TabletDriverService/config/gaomon.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
HIDTablet 0x256C 0x006D 0xFF00 0x0001
USBTablet "{62F12D4C-3431-4EFD-8DD7-8E9AAB18D30C}"
CheckString 201 "OEM02_T18e_190329"
StringContains 201 "OEM02_T18e_"
Name "Gaomon S620"
ReportId 0x00
ReportLength 16
Expand Down

0 comments on commit 82640e4

Please sign in to comment.