summaryrefslogtreecommitdiff
path: root/ioctl/hidraw.py
diff options
context:
space:
mode:
authorFilipe Laíns <lains@archlinux.org>2020-08-10 21:11:53 +0100
committerFilipe Laíns <lains@archlinux.org>2020-08-10 21:29:15 +0100
commitfe81a27bbbbe80cbc4c8a8f2499df118d3df5f7f (patch)
tree368aa3d0adf43904ac19737798035389bb8c74de /ioctl/hidraw.py
parent2e556a670664335eae46866f598c924501fd95ce (diff)
hidraw: allow using a custom read length
Signed-off-by: Filipe Laíns <lains@archlinux.org>
Diffstat (limited to 'ioctl/hidraw.py')
-rw-r--r--ioctl/hidraw.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/ioctl/hidraw.py b/ioctl/hidraw.py
index 1d70012..6c69c8e 100644
--- a/ioctl/hidraw.py
+++ b/ioctl/hidraw.py
@@ -48,11 +48,10 @@ class Hidraw(object):
HIDIOCGFEATURE = 0x07
HIDIOCGRAWUNIQ = 0x08
- HID_NAME_SIZE = 1024
-
- def __init__(self, path: str) -> None:
+ def __init__(self, path: str, read_length: int = 1024) -> None:
self._path = path
self._fd = open(path, 'rb+')
+ self.read_length = read_length
fcntl.fcntl(self._fd, fcntl.F_SETFL, os.O_NONBLOCK)
def __str__(self) -> str:
@@ -120,7 +119,7 @@ class Hidraw(object):
HID name of the hidraw node
'''
return ioctl.IOCTL.IOR(
- 'H', self.HIDIOCGRAWNAME, self.HID_NAME_SIZE
+ 'H', self.HIDIOCGRAWNAME, self.read_length
).perform(self._fd).decode('utf-8').strip('\x00')
@property
@@ -129,7 +128,7 @@ class Hidraw(object):
Physical name of the hidraw node
'''
return ioctl.IOCTL.IOR(
- 'H', self.HIDIOCGRAWPHYS, self.HID_NAME_SIZE
+ 'H', self.HIDIOCGRAWPHYS, self.read_length
).perform(self._fd).decode('utf-8').strip('\x00')
@property
@@ -138,7 +137,7 @@ class Hidraw(object):
Unique name of the hidraw node
'''
return ioctl.IOCTL.IOR(
- 'H', self.HIDIOCGRAWUNIQ, self.HID_NAME_SIZE
+ 'H', self.HIDIOCGRAWUNIQ, self.read_length
).perform(self._fd).decode('utf-8').strip('\x00')
# TODO: HIDIOCSFEATURE, HIDIOCGFEATURE