<?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>A switch instead of a button</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/25686/a-switch-instead-of-a-button</link><description>we use
peripheral: exemple ble_app_blinky
central: exemple_ble_app_bliky-c 
 Instead of a button we have a Switch.
When we set the Switch to &amp;quot;on&amp;quot; the led go on.
That&amp;#39;s ok.
But when we let the position of the Switch &amp;quot;on&amp;quot;
and then reseat the bords</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Oct 2017 14:28:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/25686/a-switch-instead-of-a-button" /><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101184?ContentTypeID=1</link><pubDate>Mon, 23 Oct 2017 14:28:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ce852ac-f62f-4a8f-886a-586a18e94c3f</guid><dc:creator>mc</dc:creator><description>&lt;p&gt;Hello John Froysa
We have loking for exemples for the &amp;quot;Power-fail comparator&amp;quot; pofcom, but we ar not capable to
implement the code in the peripheral &amp;quot;exemple ble_app_blinky&amp;quot;.
Importent is that when the &amp;quot;peripheral battery is 2.3V&amp;quot;,  the led 4 on the &amp;quot;central&amp;quot; must toggle.
Can you please send us the code und where we must set it.
Thank you very much!
Best regards
MC&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101183?ContentTypeID=1</link><pubDate>Tue, 17 Oct 2017 06:02:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e8609e0-e280-4628-9d0b-1fc50d2ef1bb</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Happy to help! I appreciate the offer, but there is not need for payment. Nordic Semiconductor already pays me :) We prefer that our customers use our official support channels for the best efficiency so feel free to ask additional questions here on DevZone, or if your questions are confidential you can make a MyPage case over at &lt;a href="http://www.nordicsemi.com/"&gt;nordicsemi.com&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101185?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 17:58:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7471601-d18a-4acc-b1fd-b39b768741da</guid><dc:creator>mc</dc:creator><description>&lt;p&gt;Hello John Froysa
Super it works fine!! Thank you very much!
As said we would pay your work.
How can we do it. It is possible  to ask you
directly for further questions?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101186?ContentTypeID=1</link><pubDate>Mon, 16 Oct 2017 14:04:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:41891909-99ae-4a1f-801e-7944a8049ea0</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;I have updated my answer with some code.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101182?ContentTypeID=1</link><pubDate>Tue, 10 Oct 2017 12:34:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9ce187f-82cd-42cb-9753-c3f83df81752</guid><dc:creator>mc</dc:creator><description>&lt;p&gt;Hello Jorn Froysa&lt;/p&gt;
&lt;p&gt;Thank you very much for the answer.
Since we are new not so good in programing, its possible that  you please can send us the code and
where we must write it in the &amp;quot;peripheral&amp;quot;: exemple ble_app_blinky /  and in the &amp;quot;central&amp;quot;:exemple_ble_app_bliky-c.
We would also pay for your work.&lt;/p&gt;
&lt;p&gt;Best regards
MC&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: A switch instead of a button</title><link>https://devzone.nordicsemi.com/thread/101181?ContentTypeID=1</link><pubDate>Thu, 05 Oct 2017 10:56:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2fa759bc-e3a1-49fa-9216-df023621b62f</guid><dc:creator>J&amp;#248;rn</dc:creator><description>&lt;p&gt;Hello mc&lt;/p&gt;
&lt;p&gt;The ble_app_blinky example uses the app_buttons module, which configures the pin for GPIOTE port events, see page 70 of the nRF51 series &lt;a href="http://infocenter.nordicsemi.com/pdf/nRF51_RM_v3.0.1.pdf"&gt;reference manual&lt;/a&gt;. Port events triggers on the rising edge of the GPIO DETECT signal, see page 56 of the reference manual.
When the button is pressed a GPIOTE event is triggered, and it ends up at the app_buttons module. The app_buttons module compares the current pin state with the pins active state (in the example active state is set to 0). If the pin is high a 0 is transmitted, if the pin is low a 1 is transmitted.
When you flip the switch and reset the boards there isn&amp;#39;t a rising transition of the DETECT signal after the GPIOTE has been configured, and the port event is never triggered. To get the initial state of the led correct you would need to do a pin read on startup, and then transmit the initial state state.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;==EDIT==&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I made a quick fix. It&amp;#39;s not optimal, but it will update the initial value of the button when the client enables notifications.
I modified the ble_lbs.c file for the peripheral in the following way&lt;/p&gt;
&lt;p&gt;I added&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;boards.h&amp;quot; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to the top of the file,
I added the function&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;void init_state_update(ble_lbs_t * p_lbs)
{

            ret_code_t err_code;
            ble_gatts_hvx_params_t params;
            uint8_t button_state = 0;
            if(nrf_gpio_pin_read(BSP_BUTTON_0)==0)
            {
            button_state=1;
            }
            uint16_t len = sizeof(button_state);
        
            memset(&amp;amp;params, 0, sizeof(params));
            params.type = BLE_GATT_HVX_NOTIFICATION;
            params.handle = p_lbs-&amp;gt;button_char_handles.value_handle;
            params.p_data = &amp;amp;button_state;
            params.p_len = &amp;amp;len;
            err_code = sd_ble_gatts_hvx(p_lbs-&amp;gt;conn_handle, &amp;amp;params);
            nrf_gpio_pin_read(BSP_BOARD_LED_3);
            APP_ERROR_CHECK(err_code);

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;close to the top of the file, and I modified the on_write function&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;/**@brief Function for handling the Write event.
 *
 * @param[in] p_lbs      LED Button Service structure.
 * @param[in] p_ble_evt  Event received from the BLE stack.
 */
static void on_write(ble_lbs_t * p_lbs, ble_evt_t * p_ble_evt)
{
    ble_gatts_evt_write_t * p_evt_write = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.write;

    if ((p_evt_write-&amp;gt;handle == p_lbs-&amp;gt;led_char_handles.value_handle) &amp;amp;&amp;amp;
        (p_evt_write-&amp;gt;len == 1) &amp;amp;&amp;amp;
        (p_lbs-&amp;gt;led_write_handler != NULL))
    {
        p_lbs-&amp;gt;led_write_handler(p_lbs, p_evt_write-&amp;gt;data[0]);
    }
		
    else if (p_evt_write-&amp;gt;handle == p_lbs-&amp;gt;button_char_handles.cccd_handle)
    {
        if(p_ble_evt-&amp;gt;evt.gatts_evt.params.write.len==2)
        {
					init_state_update(p_lbs);
        }
    }    
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This checks if the write is a cccd change, and sends a notification of the initial button value.
DO NOTE the button value updated here is entered separately from the one defined in main.c, so if you change the pin you will need to change it both in main.c and in ble_lbs.c.
You could move the pin defines to a common header file to avoid this.&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Jørn Frøysa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>