Skip to content

Commit

Permalink
drv/button_adc: fix button combos
Browse files Browse the repository at this point in the history
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: pybricks/support#237
  • Loading branch information
dlech committed Feb 2, 2021
1 parent 2bb577f commit 6c7888a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/pbio/drv/button/button_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6c7888a

Please sign in to comment.