Skip to content

Commit

Permalink
new: implementations for detecting protocol that an input device is u…
Browse files Browse the repository at this point in the history
…sing
  • Loading branch information
kernel-dev committed Mar 18, 2022
1 parent d59f293 commit a0667d8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/util/driver_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import subprocess

smbus_driver = subprocess.check_output(["powershell", "Get-WmiObject", "-Class", "Win32_PnPEntity", "|", "Where",
"-Property", "CompatibleID", "-Contains", "-Value", '"PCI\CC_0C0500"', "|", "Select", "Name"]).decode().lower()

smbus_elan = len(smbus_driver) > 0 and "elans" in smbus_driver
smbus_syna = len(smbus_driver) > 0 and "synaptics" in smbus_driver

def is_usb(inf, service):
return inf.split(".")[0] in ("msmouse", "keyboard", "input") and service in ("mouhid", "kbdhid", "hidusb")


def is_i2c(inf, service):
return "hidi2c" in inf and service == "hidi2c"


def is_smbus(desc):
return ("synaptics" in desc and smbus_syna) or ("elans" in desc and smbus_elan)


def is_ps2(service):
return "i8042" in service.lower()


def driver_type(pnp_id, desc, w):
pnp_entity = w.query(f"SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID = '{pnp_id}'")[
0].GetDeviceProperties(["DEVPKEY_Device_DriverInfPath", "DEVPKEY_Device_Service", "DEVPKEY_Device_Stack"])

protocol = None

for instances in pnp_entity:
if type(instances) == int:
continue

inf = instances[0].Data.lower()
service = instances[1].Data.lower()

if is_usb(inf, service):
protocol = "USB"
elif is_i2c(inf, service):
protocol = "I2C"
elif is_ps2(service):
if is_smbus(desc.lower()):
protocol = "SMBus"
else:
protocol = "PS/2"

return protocol

0 comments on commit a0667d8

Please sign in to comment.