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

Add possibility to use bluetooth controllers #26

Open
MrMennens-tech opened this issue Sep 16, 2022 · 13 comments
Open

Add possibility to use bluetooth controllers #26

MrMennens-tech opened this issue Sep 16, 2022 · 13 comments

Comments

@MrMennens-tech
Copy link

I'm using the program & Pi Zero to connect wheelchairs with Bluetooth Mouse support to the XAC

Works like a charm after fiddling with the settings.

However, there are some very nice bluetooth "VR Controllers" that i would love to connect to the XAC without gutting it open.
Would it be possible to add support for gamepad joysticks to "passthrough" the joystick command to the XAC?

Starting out with python, so i'm not able to code this myself.

@milador
Copy link
Owner

milador commented Sep 16, 2022

Hi there, Thanks alot for your feedback and glad you were able to use it. It's on the roadmap to add input joystick for co-pilot usage so there will be support for it very soon. It should not be a major change but requires more testing. Let me know if there are other features that you would like to see before I release the improved version.

@MrMennens-tech
Copy link
Author

Hi there, Thanks alot for your feedback and glad you were able to use it. It's on the roadmap to add input joystick for co-pilot usage so there will be support for it very soon. It should not be a major change but requires more testing. Let me know if there are other features that you would like to see before I release the improved version.

Awesome! Good to hear you have plans for an improved version.

I'm planning to use the pizero-joystick-xac combination with quite a lot of different input devices. So I'm looking to add a nice OLED display, some up/down/select buttons to scan for Bluetooth devices or connect them from the device itself (without the need to add a keyboard & display or ssh to it from a different machine.

Also i'm going to add an off button so I can power down the pi correctly without corrupting the microSD card.

If I can help out with testing, please let me know!

@milador
Copy link
Owner

milador commented Sep 17, 2022

Awesome! OLED display would be a great addon. Hopefully, I would be able to create an applet to replace the main desktop UI as well. That can improve the experience to next level. I would be more than happy to have some help to test the new features soon.

@MrMennens-tech
Copy link
Author

Hi there, Thanks alot for your feedback and glad you were able to use it. It's on the roadmap to add input joystick for co-pilot usage so there will be support for it very soon. It should not be a major change but requires more testing. Let me know if there are other features that you would like to see before I release the improved version.

Hi there Milador,
Just wondering if you've been able to add controller / joystick support for the project?
i've been trying to split my Logitech extreme 3d pro joystick for a few weeks now (with GDsports solutions).
Sadly not been able to get it working.

Would be awesome to get it working with your scripts!

If I can test stuff out, just let me know!

@milador
Copy link
Owner

milador commented Dec 19, 2022

HI @MrMennens-tech , I looked into it , but it would make the project way too complex as gamepads descriptors can be different for each joystick. It's possible but it would take time to test it with different joysticks. However, I can help you get it working with Logitech extreme 3d pro joystick.

Run the following code ( event number can be different and not always event0 ) and press buttons and move the joystick in all directions :

#!/usr/bin/python3
from evdev import InputDevice, categorize, ecodes, KeyEvent
gamepad = InputDevice('/dev/input/event0')

for event in gamepad.read_loop():
    print(categorize[event])

Then if you send me the output (copy & paste), I can add the logic to the code.

@MrMennens-tech
Copy link
Author

Thanks! Asked my new friend GPT to edit the script a bit to get some log output.
Sadly there's quite a lot of mess inside because of an off axis neutral position i think...

See excel file for the buttons, Log1 for the axis, Log2 for the hat axis

Log 1: Up, Down, Left, Right, Turn left, Turn Right, Throttle down, Throttle up
Log 2: Up, Down, Left, Right (twice)
Log2.txt
Log1.txt
Log_Buttons.xlsx

If you need anything else, just let me know.

@milador
Copy link
Owner

milador commented Dec 21, 2022

@MrMennens-tech I will need to connect actual joystick for the axis which I probably do in next few days once I find it!

I modified the code in 'passthrough' branch to handle buttons and hat axis. Give it a try and let me know.

Here how you can test it:

  • Stop the running service in terminal window by running
sudo systemctl stop xac_gamepad.service
sudo systemctl disable xac_gamepad.service
sudo systemctl daemon-reload
  • Download gamepad_xac_inputevent.py from 'passthrough' branch. I assume it's saved under /home/pi/
  • Navigate to XAC directory at /home/pi/RaspberryPi-Joystick/XACGamepad/Code/ or through terminal
    cd /home/pi/RaspberryPi-Joystick/XACGamepad/Code/
  • Delete gamepad_xac_inputevent.py or in terminal by running
    sudo rm -r gamepad_xac_inputevent.py
  • Add the updated gamepad_xac_inputevent.py file or through terminal
  • sudo cp /home/pi/gamepad_xac_inputevent.py /home/pi/RaspberryPi-Joystick/XACGamepad/Code/
  • Now run the code to make sure everything working ( Use CTRL+C to exit after )
    sudo python3 gamepad_xac_inputevent.py
  • Now if everything worked then you can enable the service
systemctl daemon-reload
systemctl enable xac_gamepad.service
systemctl start xac_gamepad.service

You may need to restart your pi.

@MrMennens-tech
Copy link
Author

MrMennens-tech commented Dec 22, 2022

Sadly no luck...

sudo python3 gamepad_xac_inputevent.py

Traceback (most recent call last):
  File "/home/mennenstech/RaspberryPi-Joystick/XACGamepad/Code/gamepad_xac_inputevent.py", line 14, in <module>
    Joystick.begin('/dev/hidg0')
  File "/home/mennenstech/RaspberryPi-Joystick/XACGamepad/Code/Gamepad_XAC.py", line 48, in begin
    self.write()
  File "/home/mennenstech/RaspberryPi-Joystick/XACGamepad/Code/Gamepad_XAC.py", line 65, in write
    self.devhandle.flush()
BrokenPipeError: [Errno 108] Cannot send after transport endpoint shutdown

if i connect the Logitech Joystick to the pizero using a OTG cable it gets found when using lsusb.
When i connect the pizero to the XAC using the stem, i lose the Logitech Joystick when using lsusb.

In both situations, the Brokenpipeerror is the same. Reboot also doesn't seem to fix it.

Edit: i don't receive an error when only connected to the XAC. When i plug in the Logitech controller, everything fails. I'll check to see if a pi 2 / 3 of 4 is better equipped for the task

Edit 2: after a bit of reading and researching looks like I found the problem... Pi zero is not capable of receiving USB input and OTG at the same time. Only option with a USB joystick is the Raspberry pi 4 (or a different board).

To bad, really hoped i could get it to work on a pi zero (with costs and availability in mind)

Only option to keep it with the pi zero is to send its data to a pi pico using serial (like the scripts from GDSports).

@MrMennens-tech
Copy link
Author

alright, i've managed to get my hands on a NanoPi Neo which can do the OTG and USB-A input at the same time.

the code runs, but I don't receive any output when running the script (code runs fine, shows some key stuff (see attached piece of code) but doesn't fire buttons to the XAC Gamepad connected to windows pc

device /dev/input/event0, name "Logitech Extreme 3D pro", phys "usb-1c1d400.usb-1/input0" /dev/input/event0 Logitech Extreme 3D pro usb-1c1d400.usb-1/input0 {('EV_SYN', 0): [('SYN_REPORT', 0), ('SYN_CONFIG', 1), ('SYN_DROPPED', 3), ('?', 4)], ('EV_KEY', 1): [(['BTN_JOYSTICK', 'BTN_TRIGGER'], 288), ('BTN_THUMB', 289), ('BTN_THUMB2', 290), ('BTN_TOP', 291), ('BTN_TOP2', 292), ('BTN_PINKIE', 293), ('BTN_BASE', 294), ('BTN_BASE2', 295), ('BTN_BASE3', 296), ('BTN_BASE4', 297), ('BTN_BASE5', 298), ('BTN_BASE6', 299)], ('EV_ABS', 3): [(('ABS_X', 0), AbsInfo(value=512, min=0, max=1023, fuzz=3, flat=63, resolution=0)), (('ABS_Y', 1), AbsInfo(value=511, min=0, max=1023, fuzz=3, flat=63, resolution=0)), (('ABS_RZ', 5), AbsInfo(value=127, min=0, max=255, fuzz=0, flat=15, resolution=0)), (('ABS_THROTTLE', 6), AbsInfo(value=255, min=0, max=255, fuzz=0, flat=15, resolution=0)), (('ABS_HAT0X', 16), AbsInfo(value=0, min=-1, max=1, fuzz=0, flat=0, resolution=0)), (('ABS_HAT0Y', 17), AbsInfo(value=0, min=-1, max=1, fuzz=0, flat=0, resolution=0))], ('EV_MSC', 4): [('MSC_SCAN', 4)]} Has EV_KEY [288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299] device /dev/input/event1, name "r_gpio_keys", phys "gpio-keys/input0" /dev/input/event1 r_gpio_keys gpio-keys/input0 {('EV_SYN', 0): [('SYN_REPORT', 0), ('SYN_CONFIG', 1)], ('EV_KEY', 1): [('KEY_POWER', 116)]} Has EV_KEY [116]

@milador
Copy link
Owner

milador commented Dec 26, 2022

@MrMennens-tech Thanks for trying. The code may not work on other single board computers if they lack driver support. I will need to debug the code with actual joystick as it seems I need to make more changes.

@milador
Copy link
Owner

milador commented Jan 4, 2023

@MrMennens-tech I have been sick in last few days and I will look into it once I am better.

@MrMennens
Copy link

No worries, no rush! Get well soon!

@MrMennens-tech
Copy link
Author

@MrMennens-tech I have been sick in last few days and I will look into it once I am better.

@milador How have you been? Hope you're doing better!

Any chance you've been able to debug something?

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