Multiple fixes in gamepad#864
Conversation
Don't check the pin's pull direction on every tick, instead cache it at the beginning. Also avoid a "can't get pull of output pin" error when one of the pins passed is in output mode.
For some reason, when the GamePad is created from frozen code, the get_pressed method would always return 0. This fixes it, and makes it work properly no matter how the object was created.
dhalbert
left a comment
There was a problem hiding this comment.
I notice you made gamepad_singleton volatile, but I'm not sure why you did that.
There's an issue in gamepad_make_new. It's in code that hasn't changed so I can't add a line comment. The issue is that you set gamepad_singleton early. But there are two possible exceptions that occur after that: if one of the args is not a DIgitalInOut, or later, gamepad_init() can also throw an exception if one of the pins is deinited. So in either case you'll be left with a broken singleton. So don't set the singleton until it's completely successfully init'ed.
I'm not sure if this has to do with the problem you mentioned in discord.
|
Also, use |
Raise exceptions before the gamepad_singleton is created. Also, use mp_raise for creating the exceptions.
|
Thanks. I also added an error when more than 8 buttons are passed — before it would be a memory overflow. |
Don't check the pin's pull direction on every tick, instead cache it
at the beginning. Also avoid a "can't get pull of output pin" error
when one of the pins passed is in output mode.