<?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>nRF51822 s110 custom event handlers</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/4337/nrf51822-s110-custom-event-handlers</link><description>Hi guys and gals! 
 I recently got Evelution kit nRF51822 and I&amp;#39;m working on custom application with SoftDevice s110 on Peripheral side. I was looking in &amp;quot;nAN-36&amp;quot; documentation file for easy start and I understand it, but I&amp;#39;m having truble with writting</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 21 Jan 2015 12:33:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/4337/nrf51822-s110-custom-event-handlers" /><item><title>RE: nRF51822 s110 custom event handlers</title><link>https://devzone.nordicsemi.com/thread/15436?ContentTypeID=1</link><pubDate>Wed, 21 Jan 2015 12:33:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:87ec85dd-4a50-44b9-bb04-82e61b82a31a</guid><dc:creator>Inspectron</dc:creator><description>&lt;p&gt;If I want always to send YOUR_VALUE. Where I have to call ble_lbs_on_button_change()?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51822 s110 custom event handlers</title><link>https://devzone.nordicsemi.com/thread/15435?ContentTypeID=1</link><pubDate>Fri, 09 Jan 2015 15:12:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:333651cc-12df-4889-ab41-6a12c79d7e67</guid><dc:creator>Stian R&amp;#248;ed Hafskjold</dc:creator><description>&lt;p&gt;Since you already started with the &lt;a href="https://github.com/NordicSemiconductor/nrf51-ble-app-lbs/"&gt;nAN-36 led-button example&lt;/a&gt;, you can use the button characteristic to send out the notification.&lt;/p&gt;
&lt;p&gt;In the led-button example the &lt;code&gt;ble_lbs_on_button_change()&lt;/code&gt; in &lt;strong&gt;ble_lbs.c&lt;/strong&gt; is called by the &lt;code&gt;button_event_handler()&lt;/code&gt; handler in &lt;strong&gt;main.c&lt;/strong&gt;. The button event handler is called whenever a change in the buttons registered in the &lt;code&gt;gpiote_init()&lt;/code&gt; function changes.&lt;/p&gt;
&lt;p&gt;Likewise, you can call the &lt;code&gt;ble_lbs_on_button_change()&lt;/code&gt; from any other interrupt handlers. If you are going to use the ADC, its interrupt handler is &lt;code&gt;ADC_IRQHandler()&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;If you use the led-button example as a starting point, and you add the following code to &lt;strong&gt;main.c&lt;/strong&gt;, it will use a timer to sample the variable value, then send a notification using the &lt;code&gt;ble_lbs_on_button_change()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you want to send a value from I2C, the I2C creates an event when there is a new variable in the TXD register. Then you can use this event to call &lt;code&gt;ble_lbs_on_button_change()&lt;/code&gt;, instead of the timeout event. Similarly, the ADC has its own event when a value has been sampled.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define CUSTOM_TIMER_MEAS_INTERVAL     APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER)
static app_timer_id_t                  m_custom_timer_id;

// The timeout handler that calls the ble_lbs_on_button_change() function 
// with an arbitrary value
static void custom_timer_meas_timeout_handler(void * p_context)
{
	ble_lbs_on_value_change(&amp;amp;m_lbs, YOUR_VALUE);
}

// Initialize the timer to call the timeout handler
static void timers_init(void)
{
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, true);
    uint32_t err_code;
	err_code = app_timer_create(&amp;amp;m_custom_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                custom_timer_meas_timeout_handler);
    APP_ERROR_CHECK(err_code);
}

// Start the timer
static void timers_start(void)
{
	uint32_t err_code;
	err_code = app_timer_start(m_custom_timer_id, CUSTOM_TIMER_MEAS_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>