Skip to content

Conversation

@Fuzzyma
Copy link

@Fuzzyma Fuzzyma commented Oct 7, 2016

As mentioned in #7 the get_gamepad method blocks further execution of the program which is often not desired.
This PR intends to add a blocking parameter which can be used to disable this behavior.
You now can do something like this:

while True:

    # collect all events
    events = []

    while True:
        try:
            events.append(inputs.get_gamepad(blocking=False)[0])
        except inputs.UnpluggedError:
            print "Gamepad is not connected"
            waitForGamepad() # some logic to check if gamepad is connected
            continue
        except inputs.NoDataError:
            break

Note the array index [0] I have to use because it always returns only one array element.
I dont know the internals of other devices or other systems. So I leave it as it is. However: For xbox one controller with win7 this could be simplified (see #8)

Jonniewanathan added a commit to Jonniewanathan/inputs that referenced this pull request Feb 19, 2019
this code has been taken from the an issue on the the original repository: zeth#9
@SolidGeek
Copy link

This works on Windows, however for Linux (rasberry pi) the read() command still blocks. I have tracked down the function that blocks, which is the _get_data(self, read_size) function, when it performs self._character_device.read(read_size).

When running on linux the _character_device returns a BufferedReader object, from using the io.open(path, 'rb') command. When running on windows it uses a simpler approach with io.BytesIO() which I guess does not block?

def _character_device(self):
    if not self._character_file:
        if WIN:
            self._character_file = io.BytesIO()
            return self._character_file
        try:
            self._character_file = io.open(
                self._character_device_path, 'rb')
        except IOError as err:
            ...
    return self._character_file

I am trying to implement this on a Rasberry Pi, thus I need this to work. Anyone got any ideas of how to implement this differently?

@uzunozan41
Copy link

Thank You..

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

Successfully merging this pull request may close these issues.

4 participants