<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/38072/button-initial-push-shows-up-as-button-hold-while-sleeping</link><description>Hello all, 
 I&amp;#39;m using the Nordic SDK 14.2 BSP button handler. I have a push, release, and long push event on a single button. These are working as expected - 
 Except when the device goes to sleep. I have a push-hold that does the following: 
 1. Turns</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 11 Sep 2018 15:47:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/38072/button-initial-push-shows-up-as-button-hold-while-sleeping" /><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/148268?ContentTypeID=1</link><pubDate>Tue, 11 Sep 2018 15:47:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:045fa80a-44b9-4454-91f6-1dde69f134c3</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;What more are you doing in the&amp;nbsp;&lt;span&gt;HandleButtons() ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does it make any difference if you use the event&amp;nbsp;BSP_EVENT_ADVERTISING_START&amp;nbsp;instead of the&amp;nbsp;BSP_EVENT_KEY_1 for the long push?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/147662?ContentTypeID=1</link><pubDate>Thu, 06 Sep 2018 15:57:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9b642fc-2ce9-42d6-a009-0d5b0105d3c4</guid><dc:creator>videticj</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the psuedo-code.&amp;nbsp; Is this what you need to see for the bsp?&lt;/p&gt;
&lt;p&gt;I&amp;#39;m testing the button push type by toggling an output pin and observing on an oscilloscope (one pulse / two pulses / three pulses differentiates button press events).&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Main loop
main
{
    //BSP_INIT_BUTTONS = 2
    bsp_init(BSP_INIT_BUTTONS, BUTTON_SetButtonType);

    for (;;)
    {
        HandleButtons();
        //Do other things
        uint32_t err_code = sd_app_evt_wait();
        APP_ERROR_CHECK(err_code);
    }
}

//Button action callback
void BUTTON_SetButtonType(bsp_event_t event)
{
    switch (event)
    {
        case BSP_EVENT_KEY_0:       // button short push
        {
          BUTTON_ButtonType = BUTTON_MOMENTARY;
          BUTTON_SetButtonActive(); //flag that button event occurred
          //TOGGLE DEBUG PIN HERE
          break;
        }
        case BSP_EVENT_KEY_1:       // button long push
        {
          BUTTON_ButtonType = BUTTON_HOLD;
          BUTTON_SetButtonActive(); //flag that button event occurred
          //TOGGLE DEBUG PIN HERE
          break;
        }
        default:       // Release, other
        {
          BUTTON_ButtonType = BUTTON_NONE;
          BUTTON_SetButtonActive(); //flag that button event occurred
          //TOGGLE DEBUG PIN HERE
          break;
        }
    }

}

static const app_button_cfg_t app_buttons[1] =
{
    {BSP_BUTTON_0, false, BSP_BTP0, bsp_button_event_handler}
}

uint32_t bsp_init(uint32_t type, bsp_event_callback_t callback)
{
    uint32_t err_code = NRF_SUCCESS;

    err_code = bsp_event_to_button_action_assign(0, BSP_BUTTON_ACTION_PUSH, BSP_EVENT_KEY_2);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(0, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_0);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(0, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_1);
    APP_ERROR_CHECK(err_code);
    
    if (err_code == NRF_SUCCESS)
    {
        bsp_board_buttons_init();
        err_code = app_button_init((app_button_cfg_t *)app_buttons,
                                   1, APP_TIMER_TICKS(50));
    }
    if (err_code == NRF_SUCCESS)
    {
        err_code = app_button_enable();
    }
    if (err_code == NRF_SUCCESS)
    {
        err_code = app_timer_create(&amp;amp;m_button_timer_id,
                                    APP_TIMER_MODE_SINGLE_SHOT,
                                    button_timer_handler);
    }
    return err_code;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, within the HandleButtons() function, the BLE advertising is enabled/disabled upon a button hold event.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_FAST);  //Start advertising

sd_ble_gap_adv_stop();  //Stop advertising&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/147647?ContentTypeID=1</link><pubDate>Thu, 06 Sep 2018 15:02:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2052346a-d9da-4e70-84df-612278895133</guid><dc:creator>Sigurd</dc:creator><description>[quote userid="72397" url="~/f/nordic-q-a/38072/button-initial-push-shows-up-as-button-hold-while-sleeping/147174"]This generates a button press event, which is erroneously marked as a long push.[/quote]
&lt;p&gt;How are you testing and verifying this? Could you post some code?&lt;/p&gt;
&lt;p&gt;How have you configured the BSP ?&lt;/p&gt;
&lt;p&gt;Did you do something like this?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Generate event BSP_EVENT_ADVERTISING_START on long push for button 2(id=1)
    err_code = bsp_event_to_button_action_assign(1,BSP_BUTTON_ACTION_LONG_PUSH,BSP_EVENT_ADVERTISING_START);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And added event check for it in your bsp_event_handler() ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/147189?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 13:10:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cb7aa27f-5e8e-437e-af1f-9cf10305e4b2</guid><dc:creator>videticj</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;I just confirmed that the device is NOT restarting.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;-&amp;nbsp;&amp;nbsp; John&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/147174?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 12:27:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d284dc92-e8d9-43ad-b1b9-b1fe8b64d52c</guid><dc:creator>videticj</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;Thanks for your reply.&amp;nbsp; I have not called sleep_mode_enter() or sd_power_system_off() at any point.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think the device is restarting but I will check.&amp;nbsp; It is in fact starting up; the problem is that it does not wait for a long push - it starts immediately after touching the button. This generates a button press event, which is erroneously marked as a long push.&lt;/p&gt;
&lt;p&gt;Also to clarify, it usually works properly.&amp;nbsp; Occasionally, however, after being in standby (sd_app_evt_wait()) long enough the event occurs.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button initial push shows up as button hold while sleeping</title><link>https://devzone.nordicsemi.com/thread/147013?ContentTypeID=1</link><pubDate>Mon, 03 Sep 2018 14:39:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55e1a1a6-239d-4c20-a2fc-8f9567be68ba</guid><dc:creator>Sigurd</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;So the problem is that the&amp;nbsp;&lt;span&gt;BLE advertising is not starting again, because the action is &amp;#39;push and not &amp;#39;long push&amp;#39;?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Is the device restarting?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Maybe you are entering system off mode? Are you calinig&amp;nbsp;sleep_mode_enter() or&amp;nbsp;sd_power_system_off() somewhere?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>