Giter Site home page Giter Site logo

approxeng / approxeng.input Goto Github PK

View Code? Open in Web Editor NEW
54.0 54.0 17.0 9.92 MB

Python classes to handle game controllers, including PS3, PS4, XBox One and Rock Candy

Home Page: https://approxeng.github.io/approxeng.input

License: Apache License 2.0

Makefile 4.48% Python 95.52%

approxeng.input's People

Contributors

claremacrae avatar dependabot[bot] avatar keithellis74 avatar kneave avatar rbricheno avatar recantha avatar sainsaar avatar tabroughton avatar tomgidden avatar tomoinn avatar ukbaz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

approxeng.input's Issues

PS4 Left axis gets mapped to RT

After changing mapping in dualshock4.py still nothing,
Also inversion doesn't work on any axis.
I'm working on jetson nano

Bind to multiple controllers from one thread in selectbinder

At the moment it's possible to bind to multiple controllers using either nested 'with' blocks or by manually binding and unbinding. Both of these options will create one thread per controller - not a major issue as each thread spends almost all its time sleeping on the select statements, but a bit messy. It should be possible to change the binding code to have a map of [device] -> controller, and use that to pull out multiple controller events from a single select.

Feature to add: Unknown button number finder

At the moment, show_controls is used to show what buttons and controls are being used, depending on the controller configuration activated. When you're trying to configure or create a new controller type and you're pressing the buttons, notification that an Unknown Button or control is shown by the underlying code. However, the curses commands in the main loop in show_controls is continually clearing the screen, which means the error messages either don't appear or they appear and straight away get cleared. Feature request is to either allow this script to pick up the unknown buttons/controls and display the numerical code to access them in the configuration. Alternatively, a new script could be written specifically to allow the identification of these buttons/commands.

Xbox One wireless button mappings incorrect

I noticed on my Xbox One controller some of the wireless mappings appear to be incorrect. I don't know if it's specific my model variant or a general issue.

In particular:
X shows up as:
[W 180114 23:00:45 init:797] Unknown button code 306

Y maps to square and not triangle

View and Menu are mapped to l1 and r1 instead of Select and Start
LB maps to triangle

RB shows up as:
[W 180114 23:04:17 init:797] Unknown button code 309

The left and right analogue buttons when pushed give:
[W 180114 23:04:45 init:797] Unknown button code 312
[W 180114 23:04:50 init:797] Unknown button code 313

The controller is a Bluetooth based model with an integrated headphone socket.

module not found after pip install

Please can you help me? My daughter and I are trying to get ready for piwars but we're very stuck with any kind of remote control and we are hoping to use your python package :)

We are getting module not found from when importing the input package though and we really can't understand why this is happening - here's an output of what we have on our system and hopefully you can point out anything obvious.

pi@raspberrypi:~ $ pip show approxeng.input
---
Name: approxeng.input
Version: 0.5
Location: /usr/local/lib/python2.7/dist-packages
Requires: evdev
pi@raspberrypi:~ $ sudo python
Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)

/usr/local/lib/python2.7/dist-packages/grovepi-0.0.0-py2.7.egg
/usr/lib/python2.7
/usr/lib/python2.7/plat-arm-linux-gnueabihf
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/root/.local/lib/python2.7/site-packages
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
>>> import approxeng.input
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named approxeng.input

Support for Rock Candy controllers

(copied from #2 because this isn't about python3 compatibility any more)

@keithellis74 says:

OK, I've created a class

from approxeng.input import Controller, Button, CentredAxis, TriggerAxis, BinaryAxis

RC_VENDOR_ID = 3695
RC_PRODUCT_ID = 296


class RockCandy(Controller):
    """
    Driver for the Rock Candy PS3 controller
    """

    def __init__(self, dead_zone=0.05, hot_zone=0.05):
        """
        Create a new Rock Candy driver

        :param float dead_zone:
            Used to set the dead zone for each :class:`approxeng.input.CentredAxis` in the controller.
        :param float hot_zone:
            Used to set the hot zone for each :class:`approxeng.input.CentredAxis` in the controller.
        """
        super(RockCandy, self).__init__(vendor_id=RC_VENDOR_ID,
                                         product_id=RC_PRODUCT_ID,
                                         controls=[
                                             Button("Circle", 306, sname='circle'),
                                             Button("Cross", 305, sname='cross'),
                                             Button("Square", 304, sname='square'),
                                             Button("Triangle", 307, sname='triangle'),
                                             Button("Home (PS)", 316, sname='home'),
                                             Button("Share", 312, sname='select'),
                                             Button("Options", 313, sname='start'),
                                             Button("Trackpad", 317, sname='ps4_pad'),
                                             Button("L1", 308, sname='l1'),
                                             Button("R1", 309, sname='r1'),
                                             Button("L2", 310, sname='l2'),
                                             Button("R2", 311, sname='r2'),
                                             Button("Left Stick", 314, sname='ls'),
                                             Button("Right Stick", 315, sname='rs'),
                                             CentredAxis("Left Horizontal", 0, 255, 0, sname='lx'),
                                             CentredAxis("Left Vertical", 0, 255, 1, invert=True, sname='ly'),
                                             CentredAxis("Right Horizontal", 0, 255, 2, sname='rx'),
                                             CentredAxis("Right Vertical", 0, 255, 5, invert=True, sname='ry'),
                                             TriggerAxis("Left Trigger", 0, 255, 3, sname='lt'),
                                             TriggerAxis("Right Trigger", 0, 255, 4, sname='rt'),
                                             BinaryAxis("D-pad Horizontal", 16, b1name='dleft', b2name='dright'),
                                             BinaryAxis("D-pad Vertical", 17, b1name='dup', b2name='ddown')
                                         ],
                                         dead_zone=dead_zone,
                                         hot_zone=hot_zone)

    def __repr__(self):
        return 'Rock Candy PS3 controller'

Mayflash Magic-S Pro mapping attached

Here is a mapping for the Mayflash Magic-S Pro controller adapter.

This is for the DINPUT mode on the adapter (red light).

This adapter converts various controllers into various protocols. In theory, configuring it once in approxeng.input should allow you to connect any supported wired or wireless controller to the adapter without remapping approxeng.input since the adapter handles the conversion. I tried this by initially profiling using two Nintendo Switch Joy Cons in dual mode (one half of a full controller map each) and then switching to a wired Xbox One S controller plugged into the Magic-S Pro. The system detects those as the same controller. That is however the extent of the testing I've done on the universal nature of this method.

All buttons are mapped but triggers are mapped digitally only.

magics_pro_v12068_p246.zip

Create multiple controller examples

All the examples use basically the same binding mechanism, it'd be nice to have some that illustrated the more advanced modes, and dual controllers is apparently a thing now so should use that as an example.

vibration support

Can this library support the control of the handle vibration motor? How to achieve it ?

Controller not detected on Ubuntu 20.04 LTS aarch64

Hi there,

It seems that controllers are not detected on the aarch Ubuntu 20.04 (Kernel: Linux 5.4.0-1028-raspi aarch64) version for Raspberry Pi. (Downloaded here)
I tried running approxeng_input_list_devices while a controller is connected, but no output was returned there. With the same controller I do get correct output on RaspiOS (tested on Raspberry Pi 3) and on Ubuntu 20.04 LTS x86_64 (Kernel: Linux 5.8.0-44-generic x86_64).
Running ls /dev/input/ shows js0 which should be the controller because it disappears after I plug it out. So I guess the device itself is recognized by the system.
To exclude the possibility this could be a pure RPi 4 problem, I installed the same Ubuntu version (so starting with a fresh OS) on the RPi 3. Unfortunately the same result there: no controllers detected.
Not sure if I'm missing a dependency or some other detail. I followed the commands listed on Getting the code.
Versions of the dependencies are the same on the aarch64 and x86_64 Ubuntu versions:
python3-dev: 3.8.2-0ubuntu2
python3: 3.8.5
gcc: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

Regards,
Niko

Fresh install on Raspberry Pi not working

Im trying a fresh install on a Raspberry pi Zero 2 with the latest PiOS. However, it wont install, with "error: externally-managed-environment". Using sudo apt install approxeng.input cant find it.

Any help would be appreciated

pi@raspberrypi:~ $ pip3 install pigpio
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

pi@raspberrypi:~ $ sudo apt install approxeng.input
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package approxeng.input
E: Couldn't find any package by glob 'approxeng.input'

Cannot check for button release

I encountered AttributeError and it refers to joystick.releases.circle when I ran the following code from https://approxeng.github.io/approxeng.input/simpleusage.html#querying-button-presses

from approxeng.input.selectbinder import ControllerResource

# Get a joystick
with ControllerResource() as joystick:
    # Loop until we're disconnected
    while joystick.connected:
        # Call check_presses at the top of the loop to check for presses and releases, this returns the buttons
        # pressed, but not the ones released. It does, however, have the side effect of updating the
        # joystick.presses and joystick.releases properties, so you use it even if you're not storing the return
        # value anywhere.
        joystick.check_presses()
        # Check for a button press
        if joystick.presses.circle:
            print('CIRCLE pressed since last check')
        # Check for a button release
        if joystick.releases.circle:
            print('CIRCLE released since last check')

        # If we had any releases, print the list of released buttons by standard name
        if joystick.has_releases:
            print(joystick.releases)

Please help

Trying to install on Pi 4

I get this error when trying to install

Collecting approxeng.input
Using cached https://files.pythonhosted.org/packages/1c/27/418500122ddff3e29355c5f248b20690555102c59037961968583262ae55/approxeng.input-2.4.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-bbupn4v0/approxeng.input/setup.py", line 2, in
from setuptools import setup, find_namespace_packages
ImportError: cannot import name 'find_namespace_packages'

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-bbupn4v0/approxeng.input/
You are using pip version 8.1.1, however version 20.2.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Axis merge when identical codes are specified

The wii controller, because it has optional extensions, has multiple mappings from code -> the same axis. In the definition this doesn't work, the one defined second over-writes the one defined first and so only one of the axes on the controller will send events to that sname. The Controller (or maybe Axes) class should detect this and create a merged axis of some kind that accepts input from either axis and immediately pushes it through to a shared one that is then surfaced by the controller instance, that way events coming in on any of a set of codes would be usable. There's a question as to whether it's raw values or centred and dead/hot zone corrected ones that would be pushed through, presumably the latter as there's no guarantee that the physical devices pushing the event codes will have the same range just because they conceptually map to the same sname.

This basically happens with the wii because it's possible to connect either the nunchuck (with a single joystick) or the classic controller (similar, but different evdev codes) and we really want e.g. both evdev codes for the x-axis on each extension to map to the same surfaced axis in the controller instance, that being the most obvious way for it to work and therefore the correct one as far as users are concerned.

Connection of Bluetooth devices

To get bluetooth devices connected I have been doing it manually via bluetoothctl, it would be nice if this could be rolled into a function to search for remotes, pair, trust and disconnect etc.

PiHut controller button mapping problem

Good morning,

I've bought the PiHut 2.4Ghz wireless controller from here . I'm connecting this to a Raspberry Pi Zero W mounted on my robot.

$ dmesg detects it as a "ShanWan PC/PS3/Android" controller:

[ 4496.194008] usb 1-1: New USB device found, idVendor=2563, idProduct=0575, bcdDevice= 2.00
[ 4496.194036] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 4496.194049] usb 1-1: Product: PC/PS3/Android
[ 4496.194060] usb 1-1: Manufacturer: ShanWan
[ 4496.217141] input: ShanWan PC/PS3/Android as /devices/platform/soc/20980000.usb/usb1/1-1/1-1:1.0/0003:2563:0575.0001/input/input0
[ 4496.218858] hid-generic 0003:2563:0575.0001: input,hidraw0: USB HID v1.10 Gamepad [ShanWan PC/PS3/Android] on usb-20980000.usb-1/input0

I've installed your excellent python library, and then attempted to write a python script to control the BrickPi3 hat on my robot using the wireless controller. I eventually concluded that the button mappings are all wrong, none of the circle, square, cross, triangle buttons map correctly. The left trigger maps to select, select maps to l2, l1 maps to triangle etc. In addition both analogue sticks seem to have large dead\hot zones covering over 50% of the analogue sticks range, although I don't know if this is a hardware quality issue.

To exclude my code, I've cloned your repo and run python3 scripts/show_controls.py and it shows the same incorrect mappings for my controller. I'm willing to try and debug\write code\submit a pull request, however I'm primarily a Java programmer and my python code is at beginner level! Could you point me in the right direction as to how to start debugging this?

Many thanks!

Incomplete list of supported controllers in docs

Hi Tom,

Thanks for an awesome library! I read the docs cover-to-cover this morning, and noticed this small inconsistency....

This section says: "currently there are six supported controllers:"
https://approxeng.github.io/approxeng.input/howtouse.html?highlight=six%20supported%20controllers#constructing-and-binding-a-controller

Whereas this page has pictures of 8 controllers, but has links to 9 of them.
https://approxeng.github.io/approxeng.input/index.html

  1. Could the missing ones be added to howtouse.html?

  2. I wonder whether in the following doc for adding new controllers, it might be worth listing documentation pages that need to be updated..
    https://approxeng.github.io/approxeng.input/addingcontrollers.html

I guess it could link to:

Unable to find any joysticks

I started working with this again after a hiatus and something that worked before does not seem to be working now. I have two pis that I am using for the same code. One of the pis connects to the controller just fine using the code below and works as I remember but the other does not and will just keep saying "Unable to find any joysticks" even though the controller is connected through bluetoothctl to the pi. Not sure if there is some file management that I am forgetting about or if something else is happening. I pretty much used the sample code from "Simple Usage" but added my own things in as a controller test. I am using an xboxone controller. Any help would be very appreciated!
test_controller.txt

Handle controllers with multiple overlapping devices

There are some controllers, such as the DS4, which generate a lot more events (conceptually) than evdev was ever intended to handle. It's not completely certain how this will be handled in the future, but right now there are some combinations of OS, controller version which generate a load of extraneous events. There's some discussion on the kernel lists that the way to do this 'properly' is to have multiple devices, but for the library to work with that we not only need a way to identify multiple devices (which we have) but to batch off events differently depending on what device they're from (which we don't)

python3 convesion

Hi Tom,

Firstly I'm not expecting you to run and fix this, but leaving this here incase you do get round to looking at it.

I've had a go at converting this to python3, initially I just replaced all print _statement_ references with print(_statement_) but this did not work, so I ran the python 2to3 script on all the files in ~/approxeng.input/src/python/approxeng/input and reinstalled with sudo python3 setup.py develop (I'm not running in a venv)

When running with python3 testinit.py I get the following error:

pi@raspberrypi:~/repo/approxeng.input/scripts $ python3 testinit.py
Not importing evdev, expected during sphinx generation on OSX
Binding to Performance Designed Products Rock Candy Wireless Gamepad for PS3 at /dev/input/event0
Foo!
Traceback (most recent call last):
  File "testinit.py", line 12, in <module>
    with ControllerResource(controller=DualShock4(), device_name='Performance Designed Products Rock Candy Wireless Gamepad for PS3') as joystick:
  File "/home/pi/repo/approxeng.input/src/python/approxeng/input/asyncorebinder.py", line 33, in __enter__
    self.unbind = bind_controller(self.controller, device_name=self.device_name, device_path=self.device_path)
  File "/home/pi/repo/approxeng.input/src/python/approxeng/input/asyncorebinder.py", line 105, in bind_controller
    loop_thread = AsyncLoop(InputDeviceDispatcher())
  File "/home/pi/repo/approxeng.input/src/python/approxeng/input/asyncorebinder.py", line 96, in __init__
    self._set_daemon()
AttributeError: 'AsyncLoop' object has no attribute '_set_daemon'
pi@raspberrypi:~/repo/approxeng.input/scripts $

This works as expected if I run python testinit.py

DualSense 5 support

Hi, are there any plans to support PS5 DualSense 5? If you point me to the right direction on where to start, I might even be able to add support myself and contribute to this repo. Thanks!

Handle controller disconnection properly

At the moment if a controller disconnects the client won't realise as we just stop sending events to the Controller. There should be a way for the binder to realise that there's been a disconnection and raise an appropriate exception when the next Controller method is called. That or an explicit check operation in Controller to raise an exception if the underlying device has gone away.

Controller class formet

The format for the controller class files seems to have changed and the documentation for adding a new class nolonger works. Can this be updated please.
cheers,
Keith.

No module named approxeng.input.selectbinder

Hi,

I'm trying to run the script but i have this import error :

GPIO Zero not found, using dummy functions.
Traceback (most recent call last):
  File "camjamedukit3.py", line 92, in <module>
    from approxeng.input.selectbinder import ControllerResource
ImportError: No module named approxeng.input.selectbinder

My approxeng.input is installed tho..

Any ideas ?

Thank you

PS4 DualShock4 incorrect mapping

DualShock4 PS4 (product_id 2508) controller class appears to be mapping a number of the buttons incorrectly and returning NoneType when checking battery. I've binded to the controller explicitly and using the ControllerResource. Controller connects fine either way. But when queried for buttons pressed, some don't work and the ones that do are incorrectly named.
I assume this is due to a software update on the DualShock4. Remapping looks easy enough, but I wanted to see if this was a known bug.

B07 controller d-pad

Got the dpad working on the B07 controller. In the profiler you must press up before down (and right before left) for the dpad to start registering, pressing the -1 direction first is ignored until you press the +1 direction.

May be update the help text to "Press both directions on each axis to assign"

File not found: /sys/class/leds/default-on/device/uevent

Hi,

First of all, thanks very much for providing this library. It made it much, much easier for me to get going in PiWars.

I updated the packages on my Pi recently and I now get this error when my controller connects:

  File "/usr/local/lib/python3.7/dist-packages/approxeng/input/selectbinder.py", line 131, in bind_controllers
    sys.scan_cache(force_update=True)
  File "/usr/local/lib/python3.7/dist-packages/approxeng/input/sys.py", line 23, in scan_cache
    __CACHED_SCAN__ = scan_system()
  File "/usr/local/lib/python3.7/dist-packages/approxeng/input/sys.py", line 126, in scan_system
    device_id = find_device_hardware_id(sub + '/device/uevent')
  File "/usr/local/lib/python3.7/dist-packages/approxeng/input/sys.py", line 107, in find_device_hardware_id
    for line in open(uevent_file_path, 'r').read().split('\n'):
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/leds/default-on/device/uevent'

The problem is that /sys/class/leds/default-on/ doesn't contain a device directory.

Catching the file not found exception like this fixes the issue:
f0633b3

Is this a problem with my Pi?

cheers,
Richard (Team Gremlin)

Issues with Output Values

I installed xpadneo to help with button mapping, which it did fix that, but I also have one more issue that has been occurring. I will press and hold the right trigger of my X Box One S controller and it will give a value of one, but when I release, it will not become zero and will instead output a lower number (from about usually 0.01 to 0.5 or so). When I release slowly it goes all the way down but is there a way to make sure it actually outputs zero when the triggers are released? There also seems like there is a similar issue with the sticks where they work well when being moved around, but when they are released, they have a random value that keeps being output. Any help is appreciated.

unmapped Axes for DualShock3 in output stream

Getting
Values streaming/printing such as are flooding terminal:

[W 180305 12:52:23 __init__:295] Unknown axis code 62, value 504
[W 180305 12:52:23 __init__:295] Unknown axis code 59, value 501
[W 180305 12:52:23 __init__:295] Unknown axis code 60, value 516
[W 180305 12:52:23 __init__:295] Unknown axis code 61, value 397
[W 180305 12:52:19 __init__:295] Unknown axis code 61, value 420
[W 180305 12:52:19 __init__:295] Unknown axis code 59, value 514
[W 180305 12:52:19 __init__:295] Unknown axis code 59, value 513
[W 180305 12:52:19 __init__:295] Unknown axis code 60, value 561
[W 180305 12:52:19 __init__:295] Unknown axis code 61, value 420
[W 180305 12:52:19 __init__:295] Unknown axis code 44, value 78
[W 180305 12:52:19 __init__:295] Unknown axis code 61, value 425

and also when pressing d-pad:

['dup']
[W 180305 12:52:19 __init__:295] Unknown axis code 44, value 125

what is advisable here? - we could fix in driver/controller or suppress output streaming to terminal.

output from list devices:

{ 'axes': { 'ABS_MISC': {'code': 40, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_MT_BLOB_ID': {'code': 56, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_MT_DISTANCE': {'code': 59, 'flat': 63, 'fuzz': 3, 'max': 1023, 'min': 0, 'res': 0},
            'ABS_MT_ORIENTATION': { 'code': 52,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_MT_POSITION_X': { 'code': 53,
                                   'flat': 15,
                                   'fuzz': 0,
                                   'max': 255,
                                   'min': 0,
                                   'res': 0},
            'ABS_MT_POSITION_Y': { 'code': 54,
                                   'flat': 15,
                                   'fuzz': 0,
                                   'max': 255,
                                   'min': 0,
                                   'res': 0},
            'ABS_MT_PRESSURE': {'code': 58, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_MT_SLOT': {'code': 47, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_MT_TOOL_TYPE': {'code': 55, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_MT_TOOL_X': {'code': 60, 'flat': 63, 'fuzz': 3, 'max': 1023, 'min': 0, 'res': 0},
            'ABS_MT_TOOL_Y': {'code': 61, 'flat': 63, 'fuzz': 3, 'max': 1023, 'min': 0, 'res': 0},
            'ABS_MT_TOUCH_MAJOR': { 'code': 48,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_MT_TOUCH_MINOR': { 'code': 49,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_MT_TRACKING_ID': { 'code': 57,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_MT_WIDTH_MAJOR': { 'code': 50,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_MT_WIDTH_MINOR': { 'code': 51,
                                    'flat': 15,
                                    'fuzz': 0,
                                    'max': 255,
                                    'min': 0,
                                    'res': 0},
            'ABS_RZ': {'code': 5, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_X': {'code': 0, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_Y': {'code': 1, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'ABS_Z': {'code': 2, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_41': {'code': 41, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_42': {'code': 42, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_43': {'code': 43, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_44': {'code': 44, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_45': {'code': 45, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_46': {'code': 46, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0},
            'EXTENDED_CODE_62': { 'code': 62,
                                  'flat': 63,
                                  'fuzz': 3,
                                  'max': 1023,
                                  'min': 0,
                                  'res': 0}},
  'bus': 5,
  'buttons': { 288: ['BTN_JOYSTICK', 'BTN_TRIGGER'],
               289: 'BTN_THUMB',
               290: 'BTN_THUMB2',
               291: 'BTN_TOP',
               292: 'BTN_TOP2',
               293: 'BTN_PINKIE',
               294: 'BTN_BASE',
               295: 'BTN_BASE2',
               296: 'BTN_BASE3',
               297: 'BTN_BASE4',
               298: 'BTN_BASE5',
               299: 'BTN_BASE6',
               300: '?',
               301: '?',
               302: '?',
               303: 'BTN_DEAD',
               704: ['BTN_TRIGGER_HAPPY', 'BTN_TRIGGER_HAPPY1'],
               705: 'BTN_TRIGGER_HAPPY2',
               706: 'BTN_TRIGGER_HAPPY3'},
  'fn': '/dev/input/event0',
  'name': 'PLAYSTATION(R)3 Controller',
  'phys': 'b8:27:eb:84:7d:54',
  'product': 616,
  'vendor': 1356,
  'version': 256}

ModuleNotFoundError when importing Controller Resource

Hello,

This is an issue that just started happening this past month. I've been using your library for interfacing with a PS4 controller since November and it was working well.

Very recently, I've been getting the following error when attempting to import the library in the following format:
from approxeng.input.selectbinder import ControllerResrouce

I now get the following error:

File "PS4BT2.py", line 15, in <module>
  from approxeng.input.selectbinder import ControllerResource
File "/home/nvidia/.local/lib/python3.6/site-packages/approxeng/input/selectbinder.py", line 6, in <module>
  from approxeng.input.controllers import *
File "/home/nvidia/.local/lib/python3.6/site-packages/approxeng/input/controllers.py", line 1, in <module>
  import importlib.resources as resources
ModuleNotFoundError: No module named 'importlib.resources

This is similar code that I copied from the example on Brian Corteil's Tiny 4WD robot as shown in the doc: https://approxeng.github.io/approxeng.input/examples/tiny4wd.html

Thanks!

WiiMote pointer

Hi, it is possible to retrieve coordinates from WiiMote?
Thanks

unusual readings

Board: Beaglebone blue, running kernel 4.14
Controller: Dualshock 3 Model CECHZC2U
Script: running the updated "show_controls.py" script

when I change the pitch of the controller, LT shows a value affected by the pitch.

When i move the left stick,
Lx varies between -.5 and 1
Ly varies berween .5 and -1
it also changes based on the pitch or roll i move the device. it impacts Lx and Ly changing these values until i move with the left stick again.

Pressing L2(lt) increases to 1, then stops at .18 when full pressed

Pitch and roll never change from 0.00.
Battery level never changes from 1.00.

Rx and ry change as expected. from 1 to -1 on both axes.

All the button presses show as expected.

Any idea why this does this?

PS4 Wireless Controller with Pi 3 and Stretch

I'm unable to get the PS4 controller working using a Raspberry Pi 3 with the current updated Raspian Stretch and wondered if there is an issue with Raspian Stretch. Below is a summary of my observations.

Using the Raspberry Pi 3 with a clean install of Raspian Version "9 Stretch" I installed approving.input as follows:
sudo apt-get install python-dev python-pip gcc
sudo apt install python3-gpiozero
sudo apt install python3-dev gcc
pip install approxeng.input
pip3 install approxeng.input

I then created a python script buttonsHeld.py by copying the python script from the Simple Usage

I connected the PiHut Compatible Wireless Gamepad / Controller and ran the buttonsHeld.py script and this worked.

I shutdown the Pi, disconnected the PiHut controller, booted the PI and paired the PS4 Wireless controller (had to connect the paired controller manually). When I ran buttonsHeld.py it continually printed "Unable to find any joystick" to the console.

ls -l /dev/input listed js0 as a device which I assume is the PS4 wireless controller

To eliminate the hardware I installed the RetroPie OS on the Raspberry Pi 3 and configured the PS4 controller. I tested the controller using the jstest /dev/input/js0 and this worked.

I would be grateful if you could shed any light on this.

Regards

Alan Cairns

Multiple device nodes for single controller in 4.13 kernels

The 4.13 kernels expose devices with motion sensors as multiple nodes in /dev/input, e.g.

tom@Ogre /dev/input $ sudo evtest 
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0:	Power Button
/dev/input/event1:	Power Button
/dev/input/event2:	USB Keyboard
/dev/input/event3:	USB Keyboard
/dev/input/event4:	Logitech G500s Laser Gaming Mouse
/dev/input/event5:	Logitech G500s Laser Gaming Mouse
/dev/input/event6:	Eee PC WMI hotkeys
/dev/input/event7:	HDA NVidia HDMI/DP,pcm=3
/dev/input/event8:	HDA NVidia HDMI/DP,pcm=7
/dev/input/event9:	HDA NVidia HDMI/DP,pcm=8
/dev/input/event10:	HDA NVidia HDMI/DP,pcm=9
/dev/input/event11:	Bowers & Wilkins MM-1
/dev/input/event12:	Wireless Controller Touchpad
/dev/input/event13:	Wireless Controller Motion Sensors
/dev/input/event14:	Wireless Controller
Select the device event number [0-14]: 

for the DualShock4 controller, with something very similar for the DS3, and probably for all controllers that can push more events than evdev was originally intended to handle. Need to change the code that binds to device nodes to bind to multiple nodes if needed, and to prefix events from each node with the node ID in some way so we can distinguish between e.g. ABS_X from a stick, and ABS_X from a motion sensor node.

Raspberry Pi 4 - Success in Finding Device, Failing to Find Controller

Hi,

Not sure if there was a support forum avaliable. But perhaps, this is an issue that is related to the firmware or compatability.

I'm running a Raspberry Pi 4 on the latest version of Rasbian, trying to connect a Xbox Elite 2 Controller.

While a device may be found, it will not be detected as a controller by approxeng.input.

When calling with print_devices, you can see the device below. However, print_controllers will not find it.

DEBUG: list controllers found { 'axes': { 'ABS_HAT0X': {'code': 16, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_HAT0Y': {'code': 17, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_RX': {'code': 3, 'flat': 128, 'fuzz': 16, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_RY': {'code': 4, 'flat': 128, 'fuzz': 16, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_RZ': {'code': 5, 'flat': 0, 'fuzz': 0, 'max': 1023, 'min': 0, 'res': 0}, 'ABS_X': {'code': 0, 'flat': 128, 'fuzz': 0, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_Y': {'code': 1, 'flat': 128, 'fuzz': 0, 'max': 32767, 'min': -32768, 'res': 0}, 'ABS_Z': {'code': 2, 'flat': 0, 'fuzz': 0, 'max': 1023, 'min': 0, 'res': 0}}, 'bus': 3, 'buttons': { 304: ['BTN_A', 'BTN_GAMEPAD', 'BTN_SOUTH'], 305: ['BTN_B', 'BTN_EAST'], 307: ['BTN_NORTH', 'BTN_X'], 308: ['BTN_WEST', 'BTN_Y'], 310: 'BTN_TL', 311: 'BTN_TR', 314: 'BTN_SELECT', 315: 'BTN_START', 316: 'BTN_MODE', 317: 'BTN_THUMBL', 318: 'BTN_THUMBR'}, 'fn': '/dev/input/event0', 'name': 'Generic X-Box pad', 'path': '/dev/input/event0', 'phys': 'usb-0000:01:00.0-1.4/input0', 'product': 2816, 'rel_axes': None, 'uniq': '', 'unique_name': 'usb-0000:01:00.0-1.4', 'vendor': 1118, 'version': 1032} None

I have also tried a second different controller (Google Stadia), in case it was controller related.

DEBUG: list controllers found { 'axes': { 'ABS_BRAKE': {'code': 10, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0}, 'ABS_GAS': {'code': 9, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 0, 'res': 0}, 'ABS_HAT0X': {'code': 16, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_HAT0Y': {'code': 17, 'flat': 0, 'fuzz': 0, 'max': 1, 'min': -1, 'res': 0}, 'ABS_RZ': {'code': 5, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_X': {'code': 0, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_Y': {'code': 1, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}, 'ABS_Z': {'code': 2, 'flat': 15, 'fuzz': 0, 'max': 255, 'min': 1, 'res': 0}}, 'bus': 3, 'buttons': { 114: 'KEY_VOLUMEDOWN', 115: 'KEY_VOLUMEUP', 164: 'KEY_PLAYPAUSE', 304: ['BTN_A', 'BTN_GAMEPAD', 'BTN_SOUTH'], 305: ['BTN_B', 'BTN_EAST'], 307: ['BTN_NORTH', 'BTN_X'], 308: ['BTN_WEST', 'BTN_Y'], 310: 'BTN_TL', 311: 'BTN_TR', 314: 'BTN_SELECT', 315: 'BTN_START', 316: 'BTN_MODE', 317: 'BTN_THUMBL', 318: 'BTN_THUMBR', 704: ['BTN_TRIGGER_HAPPY', 'BTN_TRIGGER_HAPPY1'], 705: 'BTN_TRIGGER_HAPPY2', 706: 'BTN_TRIGGER_HAPPY3', 707: 'BTN_TRIGGER_HAPPY4'}, 'fn': '/dev/input/event0', 'name': 'Google LLC Stadia Controller rev. A', 'path': '/dev/input/event0', 'phys': 'usb-0000:01:00.0-1.4/input1', 'product': 37888, 'rel_axes': None, 'uniq': '9A050YCAC2KGMV', 'unique_name': '9A050YCAC2KGMV', 'vendor': 6353, 'version': 273} None

The error being raised when trying to use ControllerResource without any requirements, or with one using a custom profile is

Traceback (most recent call last): File "main.py", line 102, in <module> with ControllerResource(ControllerRequirement(require_class=WirelessXBoxOnePad)) as joystick: File "/usr/local/lib/python3.7/dist-packages/approxeng/input/selectbinder.py", line 37, in __init__ self.discoveries = find_matching_controllers(*requirements, **kwargs) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 178, in find_matching_controllers raise exception File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 174, in find_matching_controllers return list(pop_controller(r, all_controllers) for r in requirements) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 174, in <genexpr> return list(pop_controller(r, all_controllers) for r in requirements) File "/usr/local/lib/python3.7/dist-packages/approxeng/input/controllers.py", line 169, in pop_controller raise ControllerNotFoundError() approxeng.input.controllers.ControllerNotFoundError

I have tried a number of combinations of Python scripts - but the one I have been trying to get an output from resembles:

`# Get a joystick
with ControllerResource() as joystick:
# Loop until we're disconnected
while joystick.connected:
# This is an instance of approxeng.input.ButtonPresses
left_y = joystick['ly']
if left_y != 0:
print('left x is %s' % left_y)
if left_y == 1:
print('left x is %s' % left_y)
elif left_y == -1:
print('left x is %s' % left_y)
else:
print('left x is %s' % left_y)
presses = joystick.check_presses()
if presses['square']:
print('SQUARE pressed since last check')
# We can also use attributes directly, and get at the presses object from the controller:
if joystick.presses.circle:
print('CIRCLE pressed since last check')
# Or we can use the 'x in y' syntax:
if 'triangle' in presses:
print('TRIANGLE pressed since last check')

    # If we had any presses, print the list of pressed buttons by standard name
    if joystick.has_presses:
        print(joystick.presses)`

I'm new to this library so I may be making an error my side,

But I would appreciate any suggestions,

Thanks,

Is this project maintained?

As title says:

I'm looking for a project that supports gamepad controllers on any OS. Some of the other packages that are popular in Python are unmaintained as far as I can tell. This one, however, seems to be more recently updated than the others.

Do you plan on supporting this package for the foreseeable future? I don't want to base my new project on a package that won't be updated properly.

Thanks.

Add simple methods to Contoller to make it easy to use with GPIOzero

The 'stream' (not really) API used by GPIO-zero is questionable, but it's easy to support as the 'streams' are just generators which return appropriate sequences of values. This is also pretty easy to do without library support really, but a helper function and some docs will make it even easier.

xbox series S controller

doesn't seem to work for Xbox series S controller trigger if anyone a template that works please share

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.