Skip to content

Commit

Permalink
Check linux compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag committed Nov 6, 2024
1 parent 68dcff6 commit d38146a
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
File renamed without changes.
File renamed without changes.
20 changes: 10 additions & 10 deletions lib/hidapi/hidapi_impl.py → lib/hidapi2/hidapi_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""Generic Human Interface Device API.
This provides a python interface to libusb's hidapi library which,
This provides a python interface to libusb's hidapi2 library which,
unlike udev, is available for non-linux platforms.
See https://github.com/libusb/hidapi for how to obtain binaries.
Expand All @@ -36,7 +36,7 @@
from typing import Any
from typing import Callable

from hidapi.common import DeviceInfo
from hidapi2.common import DeviceInfo

if typing.TYPE_CHECKING:
import gi
Expand All @@ -49,10 +49,10 @@
ACTION_ADD = "add"
ACTION_REMOVE = "remove"

# Global handle to hidapi
# Global handle to hidapi2
_hidapi = None

# hidapi binary names for various platforms
# hidapi2 binary names for various platforms
_library_paths = (
"libhidapi-hidraw.so",
"libhidapi-hidraw.so.0",
Expand All @@ -61,7 +61,7 @@
"libhidapi-iohidmanager.so",
"libhidapi-iohidmanager.so.0",
"libhidapi.dylib",
"hidapi.dll",
"hidapi2.dll",
"libhidapi-0.dll",
)

Expand All @@ -72,7 +72,7 @@
except OSError:
pass
else:
raise ImportError(f"Unable to load hidapi library, tried: {' '.join(_library_paths)}")
raise ImportError(f"Unable to load hidapi2 library, tried: {' '.join(_library_paths)}")


# Retrieve version of hdiapi library
Expand Down Expand Up @@ -114,7 +114,7 @@ def as_dict(self):
_cDeviceInfo_fields.append(("bus_type", ctypes.c_int))
_cDeviceInfo._fields_ = _cDeviceInfo_fields

# Set up hidapi functions
# Set up hidapi2 functions
_hidapi.hid_init.argtypes = []
_hidapi.hid_init.restype = ctypes.c_int
_hidapi.hid_exit.argtypes = []
Expand Down Expand Up @@ -154,7 +154,7 @@ def as_dict(self):
_hidapi.hid_error.argtypes = [ctypes.c_void_p]
_hidapi.hid_error.restype = ctypes.c_wchar_p

# Initialize hidapi
# Initialize hidapi2
_hidapi.hid_init()
atexit.register(_hidapi.hid_exit)

Expand Down Expand Up @@ -190,7 +190,7 @@ def _enumerate_devices() -> list:
# print(f"Ignoring keyboard or mouse device: {device}")
continue

# hidapi returns separate entries for each usage page of a device.
# hidapi2 returns separate entries for each usage page of a device.
# Deduplicate by path to only keep one device entry.
if device["path"] not in unique_devices:
unique_devices[device["path"]] = device
Expand Down Expand Up @@ -241,7 +241,7 @@ def _match(
vid = device["vendor_id"]
pid = device["product_id"]

# Translate hidapi bus_type to the bus_id values Solaar expects
# Translate hidapi2 bus_type to the bus_id values Solaar expects
if device.get("bus_type") == 0x01:
bus_id = 0x03 # USB
elif device.get("bus_type") == 0x02:
Expand Down
4 changes: 2 additions & 2 deletions lib/hidapi/hidconsole.py → lib/hidapi2/hidconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
from threading import Thread

if platform.system() == "Linux":
import hidapi.udev_impl as hidapi
import hidapi2.udev_impl as hidapi
else:
import hidapi.hidapi_impl as hidapi
import hidapi2.hidapi_impl as hidapi

LOGITECH_VENDOR_ID = 0x046D

Expand Down
10 changes: 5 additions & 5 deletions lib/hidapi/udev_impl.py → lib/hidapi2/udev_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
It is currently a partial pure-Python implementation of the native HID API
implemented by signal11 (https://github.com/signal11/hidapi), and requires
``pyudev``.
The docstrings are mostly copied from the hidapi API header, with changes where
The docstrings are mostly copied from the hidapi2 API header, with changes where
necessary.
"""

Expand All @@ -40,7 +40,7 @@

import pyudev

from hidapi.common import DeviceInfo
from hidapi2.common import DeviceInfo

if typing.TYPE_CHECKING:
import gi
Expand All @@ -57,12 +57,12 @@

#
# exposed API
# docstrings mostly copied from hidapi.h
# docstrings mostly copied from hidapi2.h
#


def init():
"""This function is a no-op, and exists only to match the native hidapi
"""This function is a no-op, and exists only to match the native hidapi2
implementation.
:returns: ``True``.
Expand All @@ -71,7 +71,7 @@ def init():


def exit():
"""This function is a no-op, and exists only to match the native hidapi
"""This function is a no-op, and exists only to match the native hidapi2
implementation.
:returns: ``True``.
Expand Down
8 changes: 4 additions & 4 deletions lib/logitech_receiver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
if typing.TYPE_CHECKING:
import gi

from hidapi.common import DeviceInfo
from hidapi2.common import DeviceInfo

gi.require_version("Gdk", "3.0")
from gi.repository import GLib # NOQA: E402

if platform.system() == "Linux":
import hidapi.udev_impl as hidapi
import hidapi2.udev_impl as hidapi
else:
import hidapi.hidapi_impl as hidapi
import hidapi2.hidapi_impl as hidapi

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -366,7 +366,7 @@ def _read(handle, timeout):
unloaded. The handle will be closed automatically.
"""
try:
# convert timeout to milliseconds, the hidapi expects it
# convert timeout to milliseconds, the hidapi2 expects it
timeout = int(timeout * 1000)
data = hidapi.read(int(handle), _MAX_READ_SIZE, timeout)
except Exception as reason:
Expand Down
2 changes: 1 addition & 1 deletion tests/integrationtests/test_device_monitor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hidapi.hidapi_impl import DeviceMonitor
from hidapi2.hidapi_impl import DeviceMonitor


def test_device_monitor(mocker):
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/hidapi/test_hidapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from unittest import mock

if platform.system() == "Linux":
import hidapi.udev_impl as hidapi
import hidapi2.udev_impl as hidapi
else:
import hidapi.hidapi_impl as hidapi
import hidapi2.hidapi_impl as hidapi


def test_find_paired_node():
Expand Down
4 changes: 2 additions & 2 deletions tools/hidconsole
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ def init_paths():
import sys

src_lib = _path.normpath(_path.join(_path.realpath(sys.path[0]), "..", "lib"))
init_py = _path.join(src_lib, "hidapi", "__init__.py")
init_py = _path.join(src_lib, "hidapi2", "__init__.py")
if _path.exists(init_py):
sys.path[0] = src_lib


if __name__ == "__main__":
init_paths()
from hidapi import hidconsole
from hidapi2 import hidconsole

hidconsole.main()

0 comments on commit d38146a

Please sign in to comment.