From 6c7888ae487505fdf0aea231795346f5abf6f482 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Mon, 1 Feb 2021 18:50:44 -0600 Subject: [PATCH] drv/button_adc: fix button combos This fixes certain button combos that had the thresholds set too close to the actual value read by the ADC. On some hubs, this caused incorrect detection of button presses when multiple buttons were pressed. Thew new values are calculated from the actual electrical circuit. Partial revert of 0665a27. Fixes: https://github.com/pybricks/support/issues/237 --- lib/pbio/drv/button/button_adc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/pbio/drv/button/button_adc.c b/lib/pbio/drv/button/button_adc.c index 905e01c9e..123791a2f 100644 --- a/lib/pbio/drv/button/button_adc.c +++ b/lib/pbio/drv/button/button_adc.c @@ -76,24 +76,24 @@ pbio_error_t pbdrv_button_is_pressed(pbio_button_flags_t *pressed) { return err; } - if (value > 3654) { + if (value > 3872) { // no buttons pressed - } else if (value > 3155) { + } else if (value > 3394) { *pressed |= PBIO_BUTTON_RIGHT_UP; // Bluetooth - } else if (value > 2885) { + } else if (value > 3009) { *pressed |= PBIO_BUTTON_RIGHT; - } else if (value > 2645) { + } else if (value > 2755) { *pressed |= PBIO_BUTTON_RIGHT_UP; // Bluetooth *pressed |= PBIO_BUTTON_RIGHT; - } else if (value > 2454) { + } else if (value > 2538) { *pressed |= PBIO_BUTTON_LEFT; - } else if (value > 2218) { + } else if (value > 2327) { *pressed |= PBIO_BUTTON_RIGHT_UP; // Bluetooth *pressed |= PBIO_BUTTON_LEFT; - } else if (value > 2084) { + } else if (value > 2141) { *pressed |= PBIO_BUTTON_RIGHT; *pressed |= PBIO_BUTTON_LEFT; - } else if (value > 1800) { + } else if (value > 1969) { *pressed |= PBIO_BUTTON_RIGHT_UP; // Bluetooth *pressed |= PBIO_BUTTON_RIGHT; *pressed |= PBIO_BUTTON_LEFT;