Skip to content

Commit

Permalink
Call hid_init() at import time, to avoid macOS crash (#150)
Browse files Browse the repository at this point in the history
fixes #142
fixes #148

note #148 (comment) :
> HIDAPI on macOS has an additional issue regarding thread-safety.
> I did encountered it in my project(s) but didn't have enough time to gather info/find a root cause.
> Looks like on macOS hid_init/hid_exit needs to be called in the same thread,
> which is an additional restriction compared to other platforms.
  • Loading branch information
SomberNight authored May 11, 2023
1 parent 8e92053 commit 04a31cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions chid.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cdef extern from "hidapi.h":
hid_device* hid_open(unsigned short, unsigned short, const wchar_t*)
hid_device* hid_open_path(char *path)
void hid_close(hid_device *)
int hid_init()
int hid_exit()
int hid_write(hid_device* device, unsigned char *data, int length) nogil
int hid_read(hid_device* device, unsigned char* data, int max_length) nogil
Expand Down
3 changes: 3 additions & 0 deletions hid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ from libc.stddef cimport wchar_t, size_t
__version__ = "0.13.1"


hid_init()


cdef extern from "ctype.h":
int wcslen(wchar_t*)

Expand Down

0 comments on commit 04a31cb

Please sign in to comment.