<?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>How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/48369/how-to-2-events-based-on-the-same-key</link><description>Hello? 
 I need to create 2 events on the same key with two operation like LONG_PRESSED and RELEASE after pressed it. (With precondition no RELEASE event after event of LONG_PRESSED) 
 I touched several spots like the below, (Custom_board.h, bsp.c, &amp;amp;</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Jun 2019 04:04:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/48369/how-to-2-events-based-on-the-same-key" /><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/194982?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 04:04:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc2376b1-038f-4610-b8e2-5d0bdaf667e9</guid><dc:creator>BrianCS</dc:creator><description>&lt;p&gt;I fixed it with adding a dummy step for release event.&lt;/p&gt;
&lt;p&gt;Thanks !!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/193334?ContentTypeID=1</link><pubDate>Tue, 18 Jun 2019 08:41:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30a8b79d-810e-4a25-b772-f137333612c3</guid><dc:creator>BrianCS</dc:creator><description>&lt;p&gt;That&amp;#39;s right!&lt;/p&gt;
&lt;p&gt;Um...&amp;nbsp; !!! That&amp;#39;s not supported !!!.&amp;nbsp; &amp;nbsp;Thanks&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/193329?ContentTypeID=1</link><pubDate>Tue, 18 Jun 2019 08:30:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc007242-ea02-4908-9a2b-c5e6d53196d3</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="BrianCS"]My question was how to make it, not to happen RELEASE event, after happening the LONG_PRESS event with the same key.[/quote]
&lt;p&gt;The way I understand it you want the following behavior:&lt;/p&gt;
&lt;p&gt;1) If the button is released before 3 seconds, you sill get a RELEASE event.&lt;/p&gt;
&lt;p&gt;2) If the button is released after 3 seconds, you want &lt;em&gt;only&lt;/em&gt; a LONG_PUSH event&amp;nbsp;and &lt;em&gt;not&lt;/em&gt; a RELEASE event when the button is pushed.&lt;/p&gt;
&lt;p&gt;This behavior is not supported by the BSP module. However, you can simply&amp;nbsp;add a tiny piece of logic in your event handling where you ignore the first RELEASE event after a LONG_PUSH event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/193310?ContentTypeID=1</link><pubDate>Tue, 18 Jun 2019 07:33:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92c95c9c-7b3f-4b12-a4b4-dcc0f5629995</guid><dc:creator>BrianCS</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Jun 18:&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s update&lt;/p&gt;
&lt;p&gt;I made 2 events, RELEASE &amp;amp; LONG_PRESS with A Key. (Like the below)&lt;/p&gt;
&lt;p&gt;err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_RELEASE, BSP_EVENT_KEY_MODE); //Mode change&lt;/p&gt;
&lt;p&gt;err_code = bsp_event_to_button_action_assign(num, BSP_BUTTON_ACTION_LONG_PUSH, BSP_EVENT_KEY_EDIT); //Mode edit&lt;/p&gt;
&lt;p&gt;The scenario of reproducing&lt;/p&gt;
&lt;p&gt;1. Press the KEY.&lt;/p&gt;
&lt;p&gt;2. Keep pressing for 3 sec. (programmed) -&amp;gt; Happen LONG_PRESS event.&lt;/p&gt;
&lt;p&gt;3. Then, unpress the KEY. -&amp;gt; Happen RELEASE event.&lt;/p&gt;
&lt;p&gt;Problem : The RELEASE event come out when release the key, after checking LONG_PRESS event . (100% reproduce)&lt;/p&gt;
&lt;p&gt;My question was how to make it, not to happen RELEASE event, after happening the LONG_PRESS event with the same key.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/192549?ContentTypeID=1</link><pubDate>Thu, 13 Jun 2019 06:46:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba536556-583d-4ae3-b0f6-1fde628201bb</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;[quote user="BrianCS"][/quote]&lt;/p&gt;
&lt;p&gt;Did you see my codes upper provided ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;These are the same what you&amp;#39;re suggested in your answer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Yes, though I dod not comment specifically. The question&amp;nbsp;was &amp;quot;&lt;span&gt;Is here anybody who succeed implementing this feature based on KEY input system provided?&lt;/span&gt;&amp;quot;, which is why I pointed to an SDK example where this is used and working.&lt;/p&gt;
[quote user="BrianCS"]Unfortunately there&amp;#39;s a problem in the special case. ( it is not&amp;nbsp; ALWAYS.)[/quote]
&lt;p&gt;This is new information. You write that there is a problem sometimes (not always). Does that mean that one or both events are sometimes missing? Which of the events? How often? Can you say more about how you handle things in your application? There is not much to go on.&lt;/p&gt;
&lt;p&gt;I am having problems understanding how this could happen. How have you verfified that you don&amp;#39;t get the two callbacks (one for each event)? Generally, both these events are based on the same interrupt, so you can at least rule out a problem with a missed interrupt. The BSP itself does not have an event queue, but calls the callback functions directly, so it could not be caused by a full event buffer either.&lt;/p&gt;
[quote user="BrianCS"]I will update some information after debugging more with new one.[/quote]
&lt;p&gt;Sounds good. It will be interesting to know more about what is going on.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/192523?ContentTypeID=1</link><pubDate>Thu, 13 Jun 2019 01:08:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:81406f46-9435-4de1-ad1a-c9e45edc6932</guid><dc:creator>BrianCS</dc:creator><description>&lt;p&gt;Did you see my codes upper provided ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;These are the same what you&amp;#39;re suggested in your answer.&lt;/p&gt;
&lt;p&gt;--------------------------------------&lt;/p&gt;
&lt;p&gt;err_code = bsp_event_to_button_action_assign(&lt;strong&gt;num, BSP_BUTTON_ACTION_RELEASE&lt;/strong&gt;, BSP_EVENT_KEY_MODE); &amp;nbsp;//Mode change&lt;/p&gt;
&lt;p&gt;err_code = bsp_event_to_button_action_assign(&lt;strong&gt;num, BSP_BUTTON_ACTION_LONG_PUSH&lt;/strong&gt;, BSP_EVENT_KEY_EDIT); //Mode edit&lt;/p&gt;
&lt;p&gt;&amp;nbsp;--------------------------------------&lt;/p&gt;
&lt;p&gt;Update Jun 13&lt;/p&gt;
&lt;p&gt;I agree, basically the code (mine and yours) has no problem to implement 2 kind event based on the same key.&lt;/p&gt;
&lt;p&gt;In case of my code, the key events are processing on BSP_EVENT_HANDLER with SYS_MODE created by myself.&lt;/p&gt;
&lt;p&gt;Unfortunately there&amp;#39;s a problem in the special case. ( it is not&amp;nbsp; ALWAYS.) so I think it need to debug more but...&lt;/p&gt;
&lt;p&gt;It seems that debugger tool has a limitation to debug so I ordered new one (no limitation)&lt;/p&gt;
&lt;p&gt;When it arrive in next week,&amp;nbsp;I&amp;#39;m going to go further with it.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;I mean I will update some information after debugging more with new one.&lt;/p&gt;
&lt;p&gt;So THIS REMAIN PENDING until that time.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to 2 events based on the same key</title><link>https://devzone.nordicsemi.com/thread/192110?ContentTypeID=1</link><pubDate>Tue, 11 Jun 2019 14:01:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eb3a23a9-c1fe-4d1e-91d2-def70ef49534</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]Creating 2 events based on ONE KEY, Is it possible on KEY input system provided?[/quote]
&lt;p&gt;Yes. The BSP library supports generating several events like this. For instance, the &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/pwr_mgmt_example.html?cp=5_1_4_6_19"&gt;Power Management Example&lt;/a&gt;&amp;nbsp;in SDK 15.3 generates events one both&amp;nbsp;BSP_BUTTON_ACTION_LONG_PUSH and&amp;nbsp;BSP_BUTTON_ACTION_RELEASE for the same button.&lt;/p&gt;
[quote user=""]Is here anybody who succeed implementing this feature based on KEY input system provided?[/quote]
&lt;p&gt;Yes. I recomend you refer to the Power Management example. In practice it is just to call&amp;nbsp;bsp_event_to_button_action_assign twice, like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                 BSP_BUTTON_ACTION_LONG_PUSH,
                                                 BSP_EVENT_SYSOFF);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(BTN_ID_SLEEP,
                                                 BSP_BUTTON_ACTION_RELEASE,
                                                 BSP_EVENT_SLEEP);
    APP_ERROR_CHECK(err_code);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>