diff --git a/samples/boards/microbit/pong/src/main.c b/samples/boards/microbit/pong/src/main.c index 96a2017fd12..152c9e68141 100644 --- a/samples/boards/microbit/pong/src/main.c +++ b/samples/boards/microbit/pong/src/main.c @@ -376,6 +376,21 @@ void pong_ball_received(s8_t x_pos, s8_t y_pos, s8_t x_vel, s8_t y_vel) static void button_pressed(struct device *dev, struct gpio_callback *cb, u32_t pins) { + /* Filter out spurious presses */ + if (pins & BIT(SW0_GPIO_PIN)) { + printk("A pressed\n"); + if (k_uptime_delta(&a_timestamp) < K_MSEC(100)) { + printk("Too quick A presses\n"); + return; + } + } else { + printk("B pressed\n"); + if (k_uptime_delta(&b_timestamp) < K_MSEC(100)) { + printk("Too quick B presses\n"); + return; + } + } + if (ended && (k_uptime_get() - ended) > RESTART_THRESHOLD) { k_delayed_work_cancel(&refresh); game_init(state == SINGLE || remote_lost); @@ -391,15 +406,12 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb, } if (pins & BIT(SW0_GPIO_PIN)) { - printk("A pressed\n"); - if (select) { pong_select_change(); return; } if (!started) { - a_timestamp = k_uptime_get(); check_start(); } @@ -412,15 +424,12 @@ static void button_pressed(struct device *dev, struct gpio_callback *cb, k_sem_give(&disp_update); } } else { - printk("B pressed\n"); - if (select) { pong_select_complete(); return; } if (!started) { - b_timestamp = k_uptime_get(); check_start(); }