From 280374fa63e284f272b714358aac32b75a4bee6a Mon Sep 17 00:00:00 2001 From: Radomir Dopieralski Date: Sat, 31 Mar 2018 21:13:02 +0200 Subject: [PATCH] Respect pin's pull in gamepad While it is traditional to have buttons on pins that are pulled up, and have the button connect them to the ground, some CircuitPython boards (notably the CPX) have the button pins pulled low and the button connects them to VCC. This patch makes the gamepad only change the pin's pull if it wasn't already set when passed to the constructor, and also makes it consider a button pressed when its value is the opposite of its pull. --- shared-module/gamepad/GamePad.c | 8 +++++++- shared-module/gamepad/__init__.c | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/shared-module/gamepad/GamePad.c b/shared-module/gamepad/GamePad.c index 3a2b8a3fe9264..cd1df9b574317 100644 --- a/shared-module/gamepad/GamePad.c +++ b/shared-module/gamepad/GamePad.c @@ -31,6 +31,7 @@ #include "shared-bindings/digitalio/Pull.h" #include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/util.h" void gamepad_init(size_t n_pins, const mp_obj_t* pins) { @@ -39,8 +40,13 @@ void gamepad_init(size_t n_pins, const mp_obj_t* pins) { } for (size_t i=0; ipins[i] = pin; - common_hal_digitalio_digitalinout_switch_to_input(pin, PULL_UP); } gamepad_singleton->last = 0; } diff --git a/shared-module/gamepad/__init__.c b/shared-module/gamepad/__init__.c index b6c8be2157dbc..591a2fa0a0204 100644 --- a/shared-module/gamepad/__init__.c +++ b/shared-module/gamepad/__init__.c @@ -42,8 +42,10 @@ void gamepad_tick(void) { if (!pin) { break; } - if (!common_hal_digitalio_digitalinout_get_value(pin)) { - gamepad_current |= 1<pressed |= gamepad_singleton->last & gamepad_current;