<?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>Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/3109/bug-in-app_button_is_pushed</link><description>Within app_button module, code for app_button_is_pushed() seems to have changed from SDK version 5.1 to 6.0. I notice my code has stopped working properly with that update. Debugger makes it apparent that this is the problematic line: 
 app_button_cfg_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 12 Sep 2014 10:26:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/3109/bug-in-app_button_is_pushed" /><item><title>RE: Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/thread/11550?ContentTypeID=1</link><pubDate>Fri, 12 Sep 2014 10:26:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84730dc1-a754-434e-a302-cfcf112e881e</guid><dc:creator>Sam Lin</dc:creator><description>&lt;p&gt;I think the API app_button_is_pushed assuming button index is poor.
Because the behavior is implicit. you might change button array declare order and the whole thing goes wrong without clue. It&amp;#39;s dangerous. Even beacon reference design example made wrong assumption. :
From beacon reference code:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;err_code = app_button_is_pushed(CONFIG_MODE_BUTTON_PIN, &amp;amp;config_mode);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;CONFIG_MODE_BUTTON_PIN is defined as BUTTON_1 (1).&lt;/p&gt;
&lt;p&gt;but in fact :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static app_button_cfg_t buttons[] =
{
    {CONFIG_MODE_BUTTON_PIN, false, BUTTON_PULL, button_handler},
    {BOOTLOADER_BUTTON_PIN, false, BUTTON_PULL, button_handler}
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;what it expects is index 0.&lt;/p&gt;
&lt;p&gt;This causes mess.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/thread/11549?ContentTypeID=1</link><pubDate>Fri, 12 Sep 2014 09:35:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a7483f1-fbec-4c0d-b494-27b0776291bd</guid><dc:creator>Sam Lin</dc:creator><description>&lt;p&gt;such API design is strange, I have to keep 2 enumeration for one button. one is button pin and another one is (trivial) button index of button array. they are totally different, and existing ALL examples wrongly assume they are the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/thread/11548?ContentTypeID=1</link><pubDate>Wed, 27 Aug 2014 08:14:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66f1fe61-7aa9-46eb-8ccf-2c31e98a5d49</guid><dc:creator>Charles Custon</dc:creator><description>&lt;p&gt;This is still an issue, as the function also uses:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    // If the pin is active low, then the pin being high means it is not pushed.
    if(((active_pins &amp;gt;&amp;gt; pin_no) &amp;amp; 0x01))
    {
        *p_is_pushed = false;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;pin_no is used to index an array that has BUTTON_COUNT number of elements, yet is also being used to logically shift a 32 bit register.&lt;/p&gt;
&lt;p&gt;We&amp;#39;ve modified the functions for our purposes as follows, with the first argument being the button number, instead of pin number:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint32_t app_button_is_pushed(uint8_t button_no, bool * p_is_pushed)
{
uint32_t err_code;
uint32_t active_pins;

app_button_cfg_t * p_btn = &amp;amp;mp_buttons[button_no];

if (mp_buttons == NULL)
{
    return NRF_ERROR_INVALID_STATE;
}

err_code = app_gpiote_pins_state_get(m_gpiote_user_id, &amp;amp;active_pins);

if (err_code != NRF_SUCCESS)
{
    return err_code;
}

if(p_btn-&amp;gt;active_state == APP_BUTTON_ACTIVE_LOW)
{
    // If the pin is active low, then the pin being high means it is not pushed.
    if(((active_pins &amp;gt;&amp;gt; p_btn-&amp;gt;pin_no) &amp;amp; 0x01))
    {
        *p_is_pushed = false;
    }
    else
    {
        *p_is_pushed = true;  
    }            
}
else if(p_btn-&amp;gt;active_state == APP_BUTTON_ACTIVE_HIGH)
{
    // If the pin is active high, then the pin being high means it is pushed.
    if(((active_pins &amp;gt;&amp;gt; p_btn-&amp;gt;pin_no) &amp;amp; 0x01))
    {
        *p_is_pushed = true;
    }
    else
    {
        *p_is_pushed = false;   
    }
}

return NRF_SUCCESS;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/thread/11547?ContentTypeID=1</link><pubDate>Wed, 16 Jul 2014 10:57:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55bc239f-6f50-4879-8c49-aa4913106c56</guid><dc:creator>Leif-Alexandre ASCHEHOUG</dc:creator><description>&lt;p&gt;Hi
Actually, the input parameter of the app_button_is_pushed has changed and documentation is not reflecting this change, which is misleading. It should be the actual pin number being passed to the function but the index of the button in the array of configured buttons (which has been given to the init function).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bug in app_button_is_pushed()?</title><link>https://devzone.nordicsemi.com/thread/11546?ContentTypeID=1</link><pubDate>Sun, 13 Jul 2014 12:23:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20866de8-93f3-436a-9807-71b721378aec</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;That looks like a huge bug to me, I agree that that array is an array of buttons which exist, not an array of pins and that&amp;#39;s just not going to work in most cases. The pointer is only checked for NULL on the next line as well, which is rather strange.&lt;/p&gt;
&lt;p&gt;I&amp;#39;d suggest filing a support case with this one but perhaps report back after that&amp;#39;s concluded.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>