Giter Site home page Giter Site logo

Comments (2)

gvalkov avatar gvalkov commented on August 29, 2024

Hello @Avraamu,

I must admit that the device.read() method must be documented more thoroughly. What this exception is telling you is that there is nothing to be read from the input device at the moment. Since the device is opened in non-blocking mode, you first have to check if there is anything that can be read from it. One way to do that is with select. For example:

from select import select

while True:
    # The select() call will block until there are events on dev_obj.
    r, w, x = select([self.dev_obj], [], [])
    # .read() will surely return a list of events now.
    for event in self.dev_obj.read():
        yield event

This is exactly what the device.read_loop() method does btw. So, your solution might be as simple as modifying your main() function to check if the device is readable:

def main():
    controller = ControllerInput(controller_name)
    while True:
        select([controller.dev_obj], [], [])
        controller.get_axis_pos()

# you may remove the 'if event_gen is not None' line from 'get_axis_pos()'

One issue with this approach is that your program will only be able to do things when there are events from the pad. This can be addressed in several ways (e.g. select has a timeout parameter or you could use a thread for input handling). I think issue #15 also touched on this subject.

Let me know if this helps.

Kind regards,
Georgi

from python-evdev.

philipgroet avatar philipgroet commented on August 29, 2024

Hello Georgi,

Thanks for the quick reply!
I'm surprised the solution was so simple! I got the example working as you said, with the select function.
Sorry for bothering you with such simple questions :)

Regards Avraamu

from python-evdev.

Related Issues (20)

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.