hidapi-usb 0.3.2__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hidapi_usb-0.3.2/hidapi_usb.egg-info → hidapi_usb-0.3.3}/PKG-INFO +3 -2
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/hidapi.py +168 -1
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3/hidapi_usb.egg-info}/PKG-INFO +3 -2
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/setup.py +1 -1
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/LICENSE.txt +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/README.md +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/hidapi_usb.egg-info/SOURCES.txt +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/hidapi_usb.egg-info/dependency_links.txt +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/hidapi_usb.egg-info/requires.txt +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/hidapi_usb.egg-info/top_level.txt +0 -0
- {hidapi_usb-0.3.2 → hidapi_usb-0.3.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hidapi-usb
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: CFFI wrapper for hidapi with changes by flok
|
|
5
5
|
Home-page: https://github.com/flok/hidapi-cffi.git
|
|
6
6
|
Author: Florian K
|
|
@@ -12,5 +12,6 @@ Dynamic: author
|
|
|
12
12
|
Dynamic: author-email
|
|
13
13
|
Dynamic: home-page
|
|
14
14
|
Dynamic: license
|
|
15
|
+
Dynamic: license-file
|
|
15
16
|
Dynamic: requires-dist
|
|
16
17
|
Dynamic: summary
|
|
@@ -2,7 +2,7 @@ from cffi import FFI
|
|
|
2
2
|
from sys import platform
|
|
3
3
|
ffi = FFI()
|
|
4
4
|
|
|
5
|
-
if platform.startswith('linux')
|
|
5
|
+
if platform.startswith('linux'):
|
|
6
6
|
ffi.cdef("""
|
|
7
7
|
|
|
8
8
|
struct hid_device_;
|
|
@@ -51,6 +51,61 @@ int hid_get_indexed_string(hid_device *device, int string_index,
|
|
|
51
51
|
wchar_t *string, size_t maxlen);
|
|
52
52
|
const wchar_t* hid_error(hid_device *device);
|
|
53
53
|
""")
|
|
54
|
+
elif platform.startswith('darwin'):
|
|
55
|
+
ffi.cdef("""
|
|
56
|
+
|
|
57
|
+
struct hid_device_;
|
|
58
|
+
typedef struct hid_device_ hid_device;
|
|
59
|
+
|
|
60
|
+
struct hid_device_info {
|
|
61
|
+
char *path;
|
|
62
|
+
unsigned short vendor_id;
|
|
63
|
+
unsigned short product_id;
|
|
64
|
+
wchar_t *serial_number;
|
|
65
|
+
unsigned short release_number;
|
|
66
|
+
wchar_t *manufacturer_string;
|
|
67
|
+
wchar_t *product_string;
|
|
68
|
+
unsigned short usage_page;
|
|
69
|
+
unsigned short usage;
|
|
70
|
+
int interface_number;
|
|
71
|
+
struct hid_device_info *next;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
int hid_init(void);
|
|
75
|
+
int hid_exit(void);
|
|
76
|
+
|
|
77
|
+
struct hid_device_info* hid_enumerate(unsigned short vendor_id,
|
|
78
|
+
unsigned short product_id);
|
|
79
|
+
void hid_free_enumeration(struct hid_device_info *devs);
|
|
80
|
+
hid_device* hid_open(unsigned short vendor_id, unsigned short product_id,
|
|
81
|
+
const wchar_t *serial_number);
|
|
82
|
+
hid_device* hid_open_path(const char *path);
|
|
83
|
+
int hid_write(hid_device *device, const unsigned char *data, size_t length);
|
|
84
|
+
int hid_read_timeout(hid_device *dev, unsigned char *data, size_t length,
|
|
85
|
+
int milliseconds);
|
|
86
|
+
int hid_read(hid_device *device, unsigned char *data, size_t length);
|
|
87
|
+
int hid_set_nonblocking(hid_device *device, int nonblock);
|
|
88
|
+
int hid_send_feature_report(hid_device *device, const unsigned char *data,
|
|
89
|
+
size_t length);
|
|
90
|
+
int hid_get_feature_report(hid_device *device, unsigned char *data,
|
|
91
|
+
size_t length);
|
|
92
|
+
void hid_close(hid_device *device);
|
|
93
|
+
int hid_get_manufacturer_string(hid_device *device, wchar_t *string,
|
|
94
|
+
size_t maxlen);
|
|
95
|
+
int hid_get_product_string(hid_device *device, wchar_t *string,
|
|
96
|
+
size_t maxlen);
|
|
97
|
+
int hid_get_serial_number_string(hid_device *device, wchar_t *string,
|
|
98
|
+
size_t maxlen);
|
|
99
|
+
int hid_get_indexed_string(hid_device *device, int string_index,
|
|
100
|
+
wchar_t *string, size_t maxlen);
|
|
101
|
+
const wchar_t* hid_error(hid_device *device);
|
|
102
|
+
|
|
103
|
+
// Darwin-specific functions from hidapi_darwin.h
|
|
104
|
+
int hid_darwin_get_location_id(hid_device *dev, unsigned int *location_id);
|
|
105
|
+
void hid_darwin_set_open_exclusive(int open_exclusive);
|
|
106
|
+
int hid_darwin_get_open_exclusive(void);
|
|
107
|
+
int hid_darwin_is_device_open_exclusive(hid_device *dev);
|
|
108
|
+
""")
|
|
54
109
|
elif platform.startswith('win32'):
|
|
55
110
|
ffi.cdef("""
|
|
56
111
|
|
|
@@ -156,6 +211,66 @@ else:
|
|
|
156
211
|
if hidapi.hid_init() == -1:
|
|
157
212
|
raise OSError("Failed to initialize hidapi")
|
|
158
213
|
|
|
214
|
+
# Darwin-specific option to open device in non-exclusive mode by default
|
|
215
|
+
if platform.startswith('darwin'):
|
|
216
|
+
# Check if Darwin functions are available and set non-exclusive mode by default
|
|
217
|
+
if hasattr(hidapi, 'hid_darwin_set_open_exclusive'):
|
|
218
|
+
try:
|
|
219
|
+
hidapi.hid_darwin_set_open_exclusive(0) # Set non-exclusive as default
|
|
220
|
+
# Verify the setting was applied
|
|
221
|
+
current_mode = hidapi.hid_darwin_get_open_exclusive()
|
|
222
|
+
if current_mode != 0:
|
|
223
|
+
import warnings
|
|
224
|
+
warnings.warn(f"Failed to set non-exclusive mode. Current mode: {current_mode}")
|
|
225
|
+
except Exception as e:
|
|
226
|
+
# If this fails, warn the user but continue
|
|
227
|
+
import warnings
|
|
228
|
+
warnings.warn(f"Could not set Darwin non-exclusive mode: {e}")
|
|
229
|
+
pass
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
# Darwin-specific functions
|
|
233
|
+
def darwin_set_open_exclusive(open_exclusive=0):
|
|
234
|
+
"""Set open exclusive on macOS.
|
|
235
|
+
|
|
236
|
+
:param open_exclusive: When set to 0 - all further devices will be opened
|
|
237
|
+
in non-exclusive mode. Otherwise - all further devices will be opened
|
|
238
|
+
in exclusive mode. Default = 0 (non-exclusive)
|
|
239
|
+
"""
|
|
240
|
+
if not platform.startswith('darwin'):
|
|
241
|
+
raise NotImplementedError('darwin_set_open_exclusive is only available on macOS')
|
|
242
|
+
|
|
243
|
+
# Check if hidapi is available
|
|
244
|
+
if 'hidapi' not in globals():
|
|
245
|
+
raise RuntimeError('hidapi library not loaded')
|
|
246
|
+
|
|
247
|
+
# Check if the Darwin-specific function is available in the loaded library
|
|
248
|
+
if not hasattr(hidapi, 'hid_darwin_set_open_exclusive'):
|
|
249
|
+
raise RuntimeError('hidapi library does not support Darwin-specific functions. '
|
|
250
|
+
'Make sure you have a hidapi library built with Darwin support.')
|
|
251
|
+
|
|
252
|
+
hidapi.hid_darwin_set_open_exclusive(open_exclusive)
|
|
253
|
+
|
|
254
|
+
def darwin_get_open_exclusive():
|
|
255
|
+
"""Get open exclusive on macOS.
|
|
256
|
+
|
|
257
|
+
:return: 1 if all further devices will be opened in exclusive mode.
|
|
258
|
+
:rtype: int
|
|
259
|
+
"""
|
|
260
|
+
if not platform.startswith('darwin'):
|
|
261
|
+
raise NotImplementedError('darwin_get_open_exclusive is only available on macOS')
|
|
262
|
+
|
|
263
|
+
# Check if hidapi is available
|
|
264
|
+
if 'hidapi' not in globals():
|
|
265
|
+
raise RuntimeError('hidapi library not loaded')
|
|
266
|
+
|
|
267
|
+
# Check if the Darwin-specific function is available in the loaded library
|
|
268
|
+
if not hasattr(hidapi, 'hid_darwin_get_open_exclusive'):
|
|
269
|
+
raise RuntimeError('hidapi library does not support Darwin-specific functions. '
|
|
270
|
+
'Make sure you have a hidapi library built with Darwin support.')
|
|
271
|
+
|
|
272
|
+
return hidapi.hid_darwin_get_open_exclusive()
|
|
273
|
+
|
|
159
274
|
|
|
160
275
|
class DeviceInfo(object):
|
|
161
276
|
__slots__ = ['path', 'vendor_id', 'product_id', 'serial_number',
|
|
@@ -416,6 +531,58 @@ class Device(object):
|
|
|
416
531
|
.format(idx, self._get_last_error_string()))
|
|
417
532
|
return ffi.buffer(bufp, 65536)[:].strip()
|
|
418
533
|
|
|
534
|
+
def darwin_get_location_id(self):
|
|
535
|
+
"""Return location id on macOS.
|
|
536
|
+
|
|
537
|
+
:return: Location ID
|
|
538
|
+
:rtype: int
|
|
539
|
+
:raises ValueError: If connection is not opened.
|
|
540
|
+
:raises IOError: If getting location ID fails.
|
|
541
|
+
"""
|
|
542
|
+
if not platform.startswith('darwin'):
|
|
543
|
+
raise NotImplementedError('darwin_get_location_id is only available on macOS')
|
|
544
|
+
|
|
545
|
+
self._check_device_status()
|
|
546
|
+
|
|
547
|
+
# Check if hidapi is available
|
|
548
|
+
if 'hidapi' not in globals():
|
|
549
|
+
raise RuntimeError('hidapi library not loaded')
|
|
550
|
+
|
|
551
|
+
# Check if the Darwin-specific function is available in the loaded library
|
|
552
|
+
if not hasattr(hidapi, 'hid_darwin_get_location_id'):
|
|
553
|
+
raise RuntimeError('hidapi library does not support Darwin-specific functions. '
|
|
554
|
+
'Make sure you have a hidapi library built with Darwin support.')
|
|
555
|
+
|
|
556
|
+
location_id_p = ffi.new("unsigned int *")
|
|
557
|
+
rv = hidapi.hid_darwin_get_location_id(self._device, location_id_p)
|
|
558
|
+
if rv < 0:
|
|
559
|
+
raise IOError('get darwin location id error')
|
|
560
|
+
return location_id_p[0]
|
|
561
|
+
|
|
562
|
+
def darwin_is_device_open_exclusive(self):
|
|
563
|
+
"""Check if the given device is opened in exclusive mode on macOS.
|
|
564
|
+
|
|
565
|
+
:return: 1 if the device is opened in exclusive mode, 0 - opened in non-exclusive,
|
|
566
|
+
-1 - if dev is invalid.
|
|
567
|
+
:rtype: int
|
|
568
|
+
:raises ValueError: If connection is not opened.
|
|
569
|
+
"""
|
|
570
|
+
if not platform.startswith('darwin'):
|
|
571
|
+
raise NotImplementedError('darwin_is_device_open_exclusive is only available on macOS')
|
|
572
|
+
|
|
573
|
+
self._check_device_status()
|
|
574
|
+
|
|
575
|
+
# Check if hidapi is available
|
|
576
|
+
if 'hidapi' not in globals():
|
|
577
|
+
raise RuntimeError('hidapi library not loaded')
|
|
578
|
+
|
|
579
|
+
# Check if the Darwin-specific function is available in the loaded library
|
|
580
|
+
if not hasattr(hidapi, 'hid_darwin_is_device_open_exclusive'):
|
|
581
|
+
raise RuntimeError('hidapi library does not support Darwin-specific functions. '
|
|
582
|
+
'Make sure you have a hidapi library built with Darwin support.')
|
|
583
|
+
|
|
584
|
+
return hidapi.hid_darwin_is_device_open_exclusive(self._device)
|
|
585
|
+
|
|
419
586
|
def close(self):
|
|
420
587
|
""" Close connection to HID device.
|
|
421
588
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hidapi-usb
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: CFFI wrapper for hidapi with changes by flok
|
|
5
5
|
Home-page: https://github.com/flok/hidapi-cffi.git
|
|
6
6
|
Author: Florian K
|
|
@@ -12,5 +12,6 @@ Dynamic: author
|
|
|
12
12
|
Dynamic: author-email
|
|
13
13
|
Dynamic: home-page
|
|
14
14
|
Dynamic: license
|
|
15
|
+
Dynamic: license-file
|
|
15
16
|
Dynamic: requires-dist
|
|
16
17
|
Dynamic: summary
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|