Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions hid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import ctypes
import atexit
import enum
import sys

__all__ = ['HIDException', 'DeviceInfo', 'Device', 'enumerate', 'BusType']

Expand Down Expand Up @@ -146,6 +147,18 @@ def as_dict(self):
hidapi.hid_error.argtypes = [ctypes.c_void_p]
hidapi.hid_error.restype = ctypes.c_wchar_p

if version >= (0, 12, 0) and sys.platform == 'darwin':
hidapi.hid_darwin_get_location_id.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint32)]
hidapi.hid_darwin_get_location_id.restype = ctypes.c_int

hidapi.hid_darwin_set_open_exclusive.argtypes = [ctypes.c_int]
hidapi.hid_darwin_set_open_exclusive.restype = None

hidapi.hid_darwin_get_open_exclusive.argtypes = None
hidapi.hid_darwin_get_open_exclusive.restype = ctypes.c_int

hidapi.hid_darwin_is_device_open_exclusive.argtypes = [ctypes.c_void_p]
hidapi.hid_darwin_is_device_open_exclusive.restype = ctypes.c_int

def enumerate(vid=0, pid=0):
ret = []
Expand Down Expand Up @@ -249,6 +262,14 @@ def close(self):
hidapi.hid_close(self.__dev)
self.__dev = None

if version >= (0, 12, 0) and sys.platform == 'darwin':
@property
def location_id(self):
loc_id = ctypes.c_uint32()
self.__hidcall(hidapi.hid_darwin_get_location_id, self.__dev, ctypes.byref(loc_id))

return loc_id.value

@property
def nonblocking(self):
return getattr(self, '_nonblocking', 0)
Expand Down