<?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 long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/29203/button-long-press-strange-behaviour-sdk12-3</link><description>main.c Hi, 
 I have implemented button long press with APP_BUTTON library with APP timer (a 5 seconds timer).
Normally the detection works fine. 
 But I found that if the system has been left running for a period of time, it will immediate trigger</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Jan 2018 16:22:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/29203/button-long-press-strange-behaviour-sdk12-3" /><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116152?ContentTypeID=1</link><pubDate>Tue, 16 Jan 2018 16:22:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f29bcfe-6aea-42d3-91c3-d79d86fd6e30</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hi mm81.&lt;br /&gt;
Sorry for the delay. I couldn&amp;#39;t seem to reproduce the problem you are having. Maybe I&amp;#39;m doing something different from you.&lt;br /&gt;
You can take a look at Jørn&amp;#39;s answer in &lt;a href="https://devzone.nordicsemi.com/question/133786/ble-enable-after-5-sec-long-press-button/"&gt;this&lt;/a&gt; thread, that might be useful, as he is explaining how to acheive what you want.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116150?ContentTypeID=1</link><pubDate>Thu, 11 Jan 2018 02:23:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a7d5db8-6c77-47f6-b42f-3136f6f8a36a</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Thanks Joakim!&lt;/p&gt;
&lt;p&gt;I defined the button and LED in a customized board definition header file (just modified from pca10028.h)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define BUTTON_POWER	 0//0
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;#define BUTTON_A	 10//	&lt;/p&gt;
&lt;p&gt;The system.h is not needed and I have removed it from the project.&lt;/p&gt;
&lt;p&gt;As described above I am using SDK12.3 on a nrf51822 (QFACA10) and developing base on ble_app_template from peripheral examples; so I am using a softdevice S130.&lt;/p&gt;
&lt;p&gt;I am using APP_BUTTON for BUTTON_POWER, BUTTON_A  for detection.
When press detected each button will start it&amp;#39;s OWN 5000ms single shot timer (two seperate timer); when the timer expired and the button is still being press it will be recognised as a long press.&lt;/p&gt;
&lt;p&gt;Problem I found is I found that when the system has been run for a while after started, a short press will immediately recognised as a long press.&lt;/p&gt;
&lt;p&gt;Some info for your reference:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The softdevice is not yet paired to any device yet (i just started the development so I am now still working on the application part). I just put the device in a idle state (Not deep sleep ) after advertisement expired.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The button must have been pressed ONCE first below this problem happens. (i.e. the 5000ms must have been started once first)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In latest testing I tried to add a 1000ms repeating timer and start it immediately once the program start. And the issue is gone.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Do you have any idea?&lt;/p&gt;
&lt;p&gt;Many thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116151?ContentTypeID=1</link><pubDate>Wed, 10 Jan 2018 09:29:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daff7818-64e1-4330-904a-307e5361f357</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Thanks! I will take a look and see if I can reproduce your problem.&lt;br /&gt;
Where are you defining the BUTTON_POWER, BUTTON_A etc?&lt;br /&gt;
I can see that you included the system.h, that is not from the SDK, maybe you could upload that file as well? So that when I test, it is as similar to your project as possible.&lt;br /&gt;
Best regards.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116148?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2018 14:11:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1cc277c-be5a-4f9e-b0af-afc48100e071</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;And I am using ble peripheral template as base for development.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116147?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2018 14:04:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0f29b9e-640a-48fb-9c94-7e6c46f4eb02</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Hihi, it is Sdk12.3 on a nrf51822qfac&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116149?ContentTypeID=1</link><pubDate>Tue, 09 Jan 2018 13:59:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:886cdc5e-35ba-429a-9637-9c12f80d53fd</guid><dc:creator>Joakim Jakobsen</dc:creator><description>&lt;p&gt;Hi mm81!&lt;br /&gt;
Which SDK and device is it that you are working with?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116146?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 06:55:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fa814a5b-331f-4def-b869-b5fd2667c251</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Hello, yes the two pins has different polarity and they are correctly set.&lt;/p&gt;
&lt;p&gt;Actually I found both pins exhibit same behaviour (both would enter long press with a short press immediately after the program&amp;#39;s been running for a while).&lt;/p&gt;
&lt;p&gt;I suspect this is a APP TIMER issue...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116145?ContentTypeID=1</link><pubDate>Fri, 05 Jan 2018 05:01:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:304365f4-840b-4abb-b3d5-487b31d06ac5</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hello.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void button_power_5sec_handler(void * p_context){
   if(nrf_gpio_pin_read(BUTTON_POWER)==1) //if button 1 is still pressed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;VS&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static void button_a_5sec_handler(void * p_context){
   if(nrf_gpio_pin_read(BUTTON_A)==0) //if button 2 is still pressed
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Can you check which one to use; 0 or 1?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Except that, I cannot detect major problems with your code.&lt;/p&gt;
&lt;p&gt;-Regards, MANGO&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116144?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 06:03:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6b23481-b55e-41da-967f-014e1f33bfe3</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Thanks for uploading it. I thought you have created one single shot mode timer but looks like you are running 2 single shot timers.&lt;/p&gt;
&lt;p&gt;Anyways, the community members will take a look at the code. I wish for your patience, please.&lt;/p&gt;
&lt;p&gt;-Regards, MANGO&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116143?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:37:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b9a9c05d-7db4-474b-91e4-bbbf44b17bfd</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;It is defined outside the main.
I tried to upload the c file in my original post, can you take a look on it?
Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116142?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:26:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69a475c8-030d-40d6-822d-745d5ae59d17</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hello, about the&lt;/p&gt;
&lt;p&gt;&lt;code&gt;It is initialised **in main**: APP_TIMER_DEF(button_power_5sec_timer_id); //define 5 second timer id&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;you mean you have defined that inside the main function like this?&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;int main(void) {
   APP_TIMER_DEF(button_power_5sec_timer_id);
   // ...
   return 0; }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;or is that defined outside the main function?&lt;/p&gt;
&lt;p&gt;How about uploading your source C file in your original post? Then I think we can speed things up.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116141?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:26:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f4f3875-8479-4754-9f84-d148d54cefef</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;I need to insert code line by line?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116140?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:24:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2b080fd-0df8-400c-bc20-623ba4d139a8</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Time out handler&lt;/p&gt;
&lt;p&gt;static void button_power_5sec_handler(void * p_context)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;{
UNUSED_PARAMETER(p_context);    
if(nrf_gpio_pin_read(BUTTON_POWER)==1) //if button 1 is still pressed
{
    NRF_LOG_INFO(&amp;quot;Button1 5sec long pressed\r\n&amp;quot;);
			v33_ctrl_off();
			pwr_ctrl_off();
}
	app_timer_stop(button_power_5sec_timer_id);
button_power_5sec_timer_enabled=false;
&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: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116139?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:19:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14d91db1-6aaf-4dba-b55d-51b2816f43ea</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Thanks~&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It is initialised in main: APP_TIMER_DEF(button_power_5sec_timer_id); //define 5 second timer id&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Is configured as single shot timer&lt;/p&gt;
&lt;p&gt;case APP_BUTTON_RELEASE:				
NRF_LOG_INFO(&amp;quot;Button%d Released \r\n&amp;quot;, pin_no);
switch(pin_no)
{
case BUTTON_POWER:
app_timer_stop(button_power_5sec_timer_id);
button_power_5sec_timer_enabled=false;								
break;
case BUTTON_A:
app_timer_stop(button_a_5sec_timer_id);
button_a_5sec_timer_enabled=false;
change_op_mode();
break;
}
break;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116138?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:16:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2d97bcb2-4182-446f-bb8e-57aaaf8bf1f4</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hello, then I would recommend you to edit your original question.&lt;/p&gt;
&lt;p&gt;When editing, press the &lt;code&gt;preformatted text&lt;/code&gt; button to insert the code.&lt;/p&gt;
&lt;p&gt;-Regards, MANGO&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116137?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:15:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47f514b1-199a-4511-8b37-f4ad51d79a1d</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;&lt;code&gt;err_code = app_timer_create(&amp;amp;button_power_5sec_timer_id, APP_TIMER_MODE_SINGLE_SHOT, button_5sec_timer_handler);&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Is your &lt;code&gt;button_power_5sec_timer_id&lt;/code&gt; variable a global / static variable? It has to be.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Did you configured the timer as a &lt;code&gt;APP_TIMER_MODE_SINGLE_SHOT&lt;/code&gt; / &lt;code&gt;APP_TIMER_MODE_REPEATED&lt;/code&gt; timer?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Can you show me the code related to the &lt;code&gt;APP_BUTTON_RELEASE&lt;/code&gt; part and the timer handler part?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I think your code when pressing the button doesn&amp;#39;t seem to be a problem.&lt;/p&gt;
&lt;p&gt;I cannot tell big issues without those parts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116136?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 05:03:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8473dfc-0813-4dd8-8816-9b4a698c1cbd</guid><dc:creator>mm81</dc:creator><description>&lt;p&gt;Sorry  don&amp;#39;t know how to properly paste the code here with correct format...&lt;/p&gt;
&lt;p&gt;Timer init as below:
err_code = app_timer_create(&amp;amp;button_power_5sec_timer_id, APP_TIMER_MODE_SINGLE_SHOT, button_power_5sec_handler);&lt;/p&gt;
&lt;p&gt;I start timer when detect a button press in button_handler():&lt;/p&gt;
&lt;p&gt;err_code = app_timer_start(button_power_5sec_timer_id, APP_TIMER_TICKS(5000,APP_TIMER_PRESCALER), NULL); //start timer, 5 second timeout&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Button long press strange behaviour(SDK12.3)</title><link>https://devzone.nordicsemi.com/thread/116135?ContentTypeID=1</link><pubDate>Thu, 04 Jan 2018 04:31:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19e07b2b-9875-4952-89d1-61802ac56d67</guid><dc:creator>MANGO</dc:creator><description>&lt;p&gt;Hello, can you post your 5sec pressing code so that we can inspect what&amp;#39;s the problem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>