Skip to content

Commit

Permalink
Merge branch 'trezor:master' into ci-cross-platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Youw authored Nov 11, 2024
2 parents 2010c8e + 9dbdd01 commit ea093c4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.12"]
python-version: ["3.8", "3.13"]
system-hidapi: ["", "--with-system-hidapi"]
libusb-backend: ["", "--with-libusb"]
exclude:
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ jobs:
submodules: true

- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.13"

- name: Setup QEMU
if: ${{ runner.os == 'Linux' }}
uses: docker/setup-qemu-action@v3

- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_BUILD: "cp3*-*"
CIBW_SKIP: "*-musllinux_*"
CIBW_ARCHS_WINDOWS: "auto"
CIBW_ARCHS_MACOS: "x86_64 arm64"
CIBW_ARCHS_LINUX: "x86_64 i686 aarch64"
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_BEFORE_ALL_LINUX: yum install -y libusb1-devel libudev-devel
HIDAPI_WITH_LIBUSB: 1
CIBW_BEFORE_ALL_LINUX: yum install -y libusb1-devel libudev-devel || apk add --upgrade libusb-dev eudev-dev

- name: Store artifacts
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions chid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cdef extern from "<hidapi.h>":
int hid_read(hid_device* device, unsigned char* data, int max_length) nogil
int hid_read_timeout(hid_device* device, unsigned char* data, int max_length, int milliseconds) nogil
int hid_set_nonblocking(hid_device* device, int value)
int hid_get_report_descriptor(hid_device* device, unsigned char *data, int length) nogil
int hid_send_feature_report(hid_device* device, unsigned char *data, int length) nogil
int hid_get_feature_report(hid_device* device, unsigned char *data, int length) nogil
int hid_get_input_report(hid_device* device, unsigned char *data, int length) nogil
Expand Down
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
# ones.
extensions = [
"sphinx.ext.autodoc",
"recommonmark",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

source_suffix = {
".rst": "restructuredtext",
".md": "markdown",
}

# List of patterns, relative to source directory, that match files and
Expand Down
61 changes: 0 additions & 61 deletions docs/examples.md

This file was deleted.

64 changes: 64 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Examples
========

Finding devices
---------------

List all info of all devices with:

.. code-block:: python
import hid
for device_dict in hid.enumerate():
keys = list(device_dict.keys())
keys.sort()
for key in keys:
print("%s : %s" % (key, device_dict[key]))
print()
Connecting, reading and writing
-------------------------------

.. code-block:: python
try:
print("Opening the device")
h = hid.device()
h.open(0x534C, 0x0001) # TREZOR VendorID/ProductID
print("Manufacturer: %s" % h.get_manufacturer_string())
print("Product: %s" % h.get_product_string())
print("Serial No: %s" % h.get_serial_number_string())
# enable non-blocking mode
h.set_nonblocking(1)
# write some data to the device
print("Write the data")
h.write([0, 63, 35, 35] + [0] * 61)
# wait
time.sleep(0.05)
# read back the answer
print("Read the data")
while True:
d = h.read(64)
if d:
print(d)
else:
break
print("Closing the device")
h.close()
except IOError as ex:
print(ex)
print("You probably don't have the hard-coded device.")
print("Update the h.open() line in this script with the one")
print("from the enumeration list output above and try again.")
print("Done")
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Welcome to HIDAPI's documentation!
:caption: Contents:

Home <self>
examples.md
examples.rst
api.rst


Expand Down
34 changes: 33 additions & 1 deletion hid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ from chid cimport *
from libc.stddef cimport wchar_t, size_t


__version__ = "0.14.0"
__version__ = "0.14.0.post3"


hid_init()
Expand Down Expand Up @@ -330,6 +330,38 @@ cdef class device:
result = hid_send_feature_report(c_hid, cbuff, c_buff_len)
return result

def get_report_descriptor(self, int max_length=4096):
"""Return the report descriptor up to max_length bytes.
If max_length is bigger than the actual descriptor, the full descriptor will be returned.
:param max_length: Maximum number of bytes to read, must be positive
:type max_length: int
:return:
:rtype: List[int]
:raises ValueError: If connection is not opened.
:raises IOError: If read error
"""
if self._c_hid == NULL:
raise ValueError('not open')

cdef unsigned char* cbuff
cdef size_t c_descriptor_length = max(1, max_length)
cdef hid_device * c_hid = self._c_hid
cdef int n
result = []
try:
cbuff = <unsigned char *>malloc(max_length)
with nogil:
n = hid_get_report_descriptor(c_hid, cbuff, c_descriptor_length)
if n < 0:
raise IOError('read error')
for i in range(n):
result.append(cbuff[i])
finally:
free(cbuff)
return result

def get_feature_report(self, int report_num, int max_length):
"""Receive feature report.
Expand Down

0 comments on commit ea093c4

Please sign in to comment.