Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure on macOS, M1 #40

Open
UEFI-code opened this issue Jan 7, 2023 · 13 comments
Open

Failure on macOS, M1 #40

UEFI-code opened this issue Jan 7, 2023 · 13 comments

Comments

@UEFI-code
Copy link

UEFI-code commented Jan 7, 2023

I'm trying on my M1 Mac, and got error out of index. I guess some hid data were missing

Python 3.10.8 (main, Oct 13 2022, 09:48:40) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydualsense
>>> obj = pydualsense.pydualsense()
>>> obj.init()
>>> Exception in thread Thread-1 (sendReport):
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/pydualsense/pydualsense.py", line 216, in sendReport
    self.readInput(inReport)
  File "/opt/homebrew/lib/python3.10/site-packages/pydualsense/pydualsense.py", line 262, in readInput
    misc2 = states[10]
IndexError: list index out of range

>>> obj.device.get_product_string()
'DualSense Wireless Controller'
>>> data = obj.device.read(64)
>>> data
b'\x01\x80~\x7f~\x08\x00\x08\x00\x00'
@flok
Copy link
Owner

flok commented Jan 10, 2023

I dont have an arm device to test. but it seems like the hidapi works diffrent in the m1.

how did you install the hidapi?

@UEFI-code
Copy link
Author

UEFI-code commented Jan 11, 2023 via email

@flok
Copy link
Owner

flok commented Jan 14, 2023

This is weird. Could you change the source and output the states list with a print ?

@UEFI-code
Copy link
Author

UEFI-code commented Jan 19, 2023

I think I set the verbose to True it will print something.

>>> import pydualsense
>>> obj = pydualsense.pydualsense(True)
>>> obj.init()
>>> 2023-01-19 11:00:42,754 b'\x01\x7f~\x80\x80\x08\x00\x00\x00\x00'
Exception in thread Thread-1 (sendReport):
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/pydualsense/pydualsense.py", line 216, in sendReport
    self.readInput(inReport)
  File "/opt/homebrew/lib/python3.10/site-packages/pydualsense/pydualsense.py", line 268, in readInput
    self.state.trackPadTouch0.ID = inReport[33] & 0x7F
IndexError: index out of range

Hidapi on m1 output data less then other platform

@wayne-xyz
Copy link

Hi thank you for this issue . and also thank flok's great repo. I have tried this lib on my m3 device , it does not work , i find out the hidapi wont works well on the mac device ( hidapi_usb ) .
will raise the erro in the hidapi.py :
raise OSError('System platform not supported')
is there any possible to replace other hidapi library to be suitable with the mac device ?

@flok
Copy link
Owner

flok commented Jan 6, 2025

It's seems that the arm chips of apple are recognized in python by a different platform (which makes sense). I have not implemented this platform type yet.

As i don't have a mac arm device on hand my support is limited.
Pydualsense uses a modified hidapi python binding using cffi. You can find that here: https://github.com/flok/hidapi-cffi

First approach would be to test what the sys.platform prints out on mac arm chips and then implement that platform inside the hidapi.py in here: https://github.com/flok/hidapi-cffi/blob/master/hidapi.py#L5 (maybe no c code changes are required and only another or parameter for the linux / darwin branch is needed.

If someone can test this on their machine and create PR i will gladly merge it and release a new version

@wayne-xyz
Copy link

It's seems that the arm chips of apple are recognized in python by a different platform (which makes sense). I have not implemented this platform type yet.

As i don't have a mac arm device on hand my support is limited. Pydualsense uses a modified hidapi python binding using cffi. You can find that here: https://github.com/flok/hidapi-cffi

First approach would be to test what the sys.platform prints out on mac arm chips and then implement that platform inside the hidapi.py in here: https://github.com/flok/hidapi-cffi/blob/master/hidapi.py#L5 (maybe no c code changes are required and only another or parameter for the linux / darwin branch is needed.

If someone can test this on their machine and create PR i will gladly merge it and release a new version

thank you for your reply , you did greate work on this repo , and i will tried a minumun adjust to make it works on mac device later. When I complete the implement. i will let you know .

@UEFI-code
Copy link
Author

UEFI-code commented Jan 7, 2025 via email

@wayne-xyz
Copy link

It's seems that the arm chips of apple are recognized in python by a different platform (which makes sense). I have not implemented this platform type yet.
As i don't have a mac arm device on hand my support is limited. Pydualsense uses a modified hidapi python binding using cffi. You can find that here: https://github.com/flok/hidapi-cffi
First approach would be to test what the sys.platform prints out on mac arm chips and then implement that platform inside the hidapi.py in here: https://github.com/flok/hidapi-cffi/blob/master/hidapi.py#L5 (maybe no c code changes are required and only another or parameter for the linux / darwin branch is needed.
If someone can test this on their machine and create PR i will gladly merge it and release a new version

thank you for your reply , you did greate work on this repo , and i will tried a minumun adjust to make it works on mac device later. When I complete the implement. i will let you know .

after i have tried the adjustement in the hidapi.py. which is dependency

if platform.startswith('linux') or platform.startswith('darwin'): this code will works for fixing my issue , and i have tred several hid features it's stable ,
my deivce Macbook AIR 2024 M3. I think i will create the pr top on that library after I do more stable monitoring.

@wayne-xyz
Copy link

i noticed that in https://github.com/flok/hidapi-cffi , there is. the adjustment for support the macos , but it did not appear in this library, i am not sure what the step i should take .

@flok
Copy link
Owner

flok commented Jan 28, 2025

i noticed that in https://github.com/flok/hidapi-cffi , there is. the adjustment for support the macos , but it did not appear in this library, i am not sure what the step i should take .

Thanks for the info. Seems like i received a PR several years ago but didn't create a new pypi release for it.

I just created it and will also update the dependency inside pydualsense. After this it should also work on apple silicon pc.

@flok
Copy link
Owner

flok commented Jan 29, 2025

v0.7.3 with the hidapi-cffi changed is release. could you test it please?

@wayne-xyz
Copy link

wayne-xyz commented Feb 3, 2025

v0.7.3 with the hidapi-cffi changed is release. could you test it please?

Thank you. Now it works , i have tried several function in my own project include:

  • HID api connection features , read and write command
  • UAC , playback on the haptic motors

There is still a limitation in macos, I believe it's the system drive issue , I can not playback on the speaker of the controller. The system wont detect the speaker's channel

  • My device: Macbook Air 2024 M3 Chip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants