1313#include "buttons.h"
1414#include "lcd.h"
1515
16+ #define TIME_1 2000
17+ #define TIME_2 200
18+ #define TIME_3 300
19+ #define TIME_4 1000
20+
1621#define BUTTONS_CLOCK_MS 20
1722#define MS_TO_TICKS (a ) ((a) / (BUTTONS_CLOCK_MS))
1823
@@ -183,9 +188,6 @@ void buttons_clear_all_events(void)
183188// assuming call every 20ms
184189void buttons_clock (void )
185190{
186- // needed if the event is not cleared anywhere else
187- buttons_clear_onoff_click_long_click_event ();
188-
189191 // exit if any button is pressed after clear event
190192 if ((ui32_m_clear_event ) &&
191193 (buttons_get_up_state () ||
@@ -213,7 +215,7 @@ void buttons_clock(void)
213215 ui32_onoff_button_state_counter ++ ;
214216
215217 // event long click
216- if (ui32_onoff_button_state_counter > MS_TO_TICKS (2000 ))
218+ if (ui32_onoff_button_state_counter > MS_TO_TICKS (TIME_1 ))
217219 {
218220 buttons_set_events (ONOFF_LONG_CLICK );
219221 ui32_onoff_button_state = 2 ;
@@ -224,7 +226,7 @@ void buttons_clock(void)
224226 if (!buttons_get_onoff_state ())
225227 {
226228 // let's validade if will be a quick click + long click
227- if (ui32_onoff_button_state_counter <= MS_TO_TICKS (300 ))
229+ if (ui32_onoff_button_state_counter <= MS_TO_TICKS (TIME_2 ))
228230 {
229231 ui32_onoff_button_state_counter = 0 ;
230232 ui32_onoff_button_state = 3 ;
@@ -261,7 +263,7 @@ void buttons_clock(void)
261263 }
262264
263265 // event click
264- if (ui32_onoff_button_state_counter > MS_TO_TICKS (400 ))
266+ if (ui32_onoff_button_state_counter > MS_TO_TICKS (TIME_3 ))
265267 {
266268 buttons_set_events (ONOFF_CLICK );
267269 ui32_onoff_button_state = 0 ;
@@ -273,7 +275,7 @@ void buttons_clock(void)
273275 ui32_onoff_button_state_counter ++ ;
274276
275277 // event click, but this time it is: click + long click
276- if (ui32_onoff_button_state_counter > MS_TO_TICKS (1000 ))
278+ if (ui32_onoff_button_state_counter > MS_TO_TICKS (TIME_4 ))
277279 {
278280 buttons_set_events (ONOFF_CLICK_LONG_CLICK );
279281 ui32_onoff_button_state = 2 ;
@@ -308,7 +310,7 @@ void buttons_clock(void)
308310 ui32_up_button_state_counter ++ ;
309311
310312 // event long click
311- if (ui32_up_button_state_counter > MS_TO_TICKS (2000 ))
313+ if (ui32_up_button_state_counter > MS_TO_TICKS (TIME_1 ))
312314 {
313315 // up and down button click
314316 if (ui32_down_button_state == 1 )
@@ -330,7 +332,7 @@ void buttons_clock(void)
330332 if (!buttons_get_up_state ())
331333 {
332334 // let's validade if will be a quick click + long click
333- if (ui32_up_button_state_counter <= MS_TO_TICKS (300 ))
335+ if (ui32_up_button_state_counter <= MS_TO_TICKS (TIME_2 ))
334336 {
335337 ui32_up_button_state_counter = 0 ;
336338 ui32_up_button_state = 3 ;
@@ -367,7 +369,7 @@ void buttons_clock(void)
367369 }
368370
369371 // event click
370- if (ui32_up_button_state_counter > MS_TO_TICKS (400 ))
372+ if (ui32_up_button_state_counter > MS_TO_TICKS (TIME_3 ))
371373 {
372374 buttons_set_events (UP_CLICK );
373375 ui32_up_button_state = 0 ;
@@ -379,7 +381,7 @@ void buttons_clock(void)
379381 ui32_up_button_state_counter ++ ;
380382
381383 // event click, but this time it is: click + long click
382- if (ui32_up_button_state_counter > MS_TO_TICKS (1000 ))
384+ if (ui32_up_button_state_counter > MS_TO_TICKS (TIME_4 ))
383385 {
384386 buttons_set_events (UP_CLICK_LONG_CLICK );
385387 ui32_up_button_state = 2 ;
@@ -414,7 +416,7 @@ void buttons_clock(void)
414416 ui32_down_button_state_counter ++ ;
415417
416418 // event long click
417- if (ui32_down_button_state_counter > MS_TO_TICKS (2000 ))
419+ if (ui32_down_button_state_counter > MS_TO_TICKS (TIME_1 ))
418420 {
419421 // up and down button click
420422 if (ui32_up_button_state == 1 )
@@ -436,7 +438,7 @@ void buttons_clock(void)
436438 if (!buttons_get_down_state ())
437439 {
438440 // let's validade if will be a quick click + long click
439- if (ui32_down_button_state_counter <= MS_TO_TICKS (300 ))
441+ if (ui32_down_button_state_counter <= MS_TO_TICKS (TIME_2 ))
440442 {
441443 ui32_down_button_state_counter = 0 ;
442444 ui32_down_button_state = 3 ;
@@ -473,7 +475,7 @@ void buttons_clock(void)
473475 }
474476
475477 // event click
476- if (ui32_down_button_state_counter > MS_TO_TICKS (400 ))
478+ if (ui32_down_button_state_counter > MS_TO_TICKS (TIME_3 ))
477479 {
478480 buttons_set_events (DOWN_CLICK );
479481 ui32_down_button_state = 0 ;
@@ -485,7 +487,7 @@ void buttons_clock(void)
485487 ui32_down_button_state_counter ++ ;
486488
487489 // event click, but this time it is: click + long click
488- if (ui32_down_button_state_counter > MS_TO_TICKS (1000 ))
490+ if (ui32_down_button_state_counter > MS_TO_TICKS (TIME_4 ))
489491 {
490492 buttons_set_events (DOWN_CLICK_LONG_CLICK );
491493 ui32_down_button_state = 2 ;
0 commit comments