Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Button stuck upon pressing, keeps sending signal to my device

Hello everyone, 

I'm using a modified version of SDK 15.0.0 ble_app_hids_keyboard on my nRF52 DK. It sends a volume up and a volume down command when I press buttons 1 or 2. However, the program gets stuck and won't stop sending that command. My button 4 which sends a pwm signal to led 4 seems to work fine. I've tried switching around the case lines in the button_event_handler function that I've attached here but that made things worse. Any help would be appreciated. Thank you.

static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
    if (button_action == APP_BUTTON_PUSH)
    {
        switch (pin_no)
        {
            case VOLUP_BUTTON:
                APP_ERROR_CHECK(consumer_control_send(CONSUMER_CTRL_VOL_UP));
                break;
            case VOLDOWN_BUTTON:
                APP_ERROR_CHECK(consumer_control_send(CONSUMER_CTRL_VOL_DW));
                break;
            case IR_BUTTON:
            {
                if(!pwm_on && !nrf_gpio_pin_read(IR_BUTTON))
                {
                    pwm_on = true;
                    app_pwm_channel_duty_set(&PWM1, 0, 50); 
                }
                else
                {
                    pwm_on = false;
                    app_pwm_channel_duty_set(&PWM1, 0, 0);
                }
                break;
            }
            case KEY_PRESS_BUTTON_PIN_NO:
            {
                APP_ERROR_CHECK(hid_kbd_send_string());
                break;
            }
            default:
                APP_ERROR_HANDLER(pin_no);
                break;
        } // end of switch
    } // end of if(button....)
    else if (button_action == APP_BUTTON_RELEASE)
    {
        switch (pin_no)
        {
            case IR_BUTTON: 

                break;
            case VOLDOWN_BUTTON:
                // Fall-through 
            case VOLUP_BUTTON:
                APP_ERROR_CHECK(consumer_control_send(RELEASE_KEY)); 
                break;
            case KEY_PRESS_BUTTON_PIN_NO:    
                APP_ERROR_CHECK(hid_kbd_send_release());
                break;
            default:
                APP_ERROR_HANDLER(pin_no);
                break;
        }
    }
}

  • Hi,

    However, the program gets stuck and won't stop sending that command

    How often does it happen?

     Do you know where it's "stuck" ?

    What's the reason for why the command is sent? Is e.g. button_event_handler() being constantly called?

  • It happens at the first instance of a push on either button 1 or 2. So everything will be okay until the first push of those two buttons that it keeps sending that command. I don't know where it's getting stuck but it is not registering that the button is being released or else it would've stopped sending the command. The two buttons send a 'vol up' and 'vol down' command so what I see on my phone is something spamming the volume up or down repeatedly. If I push vol up, it'll spam vol up and the other way is true. 

  • Hi,

    Did you check that the function "consumer_control_send(RELEASE_KEY)" is called when you release the button?

  • Yes, I set a breakpoint on that line but it seems to trigger when I push the button, not release it. I've made sure that APP_BUTTON_PUSH and APP_BUTTON_RELEASE are the correct values and would not trigger at the same time. However, it looks like the release function acts the same as the push function, hence constantly sending the same command over and over.

  • Hello, 

    Thank you for your patience with this. The summer holidays have begun here in Norway, and DevZone is therefore operating with reduced staff for the time being. Sorry for any inconvenience this might cause.

    Runar is currently out of office, so I will be handling this case in his absence.

    Gerardo Martin said:
    However, it looks like the release function acts the same as the push function, hence constantly sending the same command over and over.

    Interesting. Do you have debounce on your button? Have you made any changes to the BSP module, if so, could you detail these?
    It would be great if you could share a more complete version of your code, preferably containing the button initialization and configuration, along with any changes you might have made to the BSP module.

    Looking forward to resolving this issue together!

    Best regards,
    Karl

Related