summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <trotsenkoa@gmail.com>2022-06-29 15:03:43 +0300
committerAlexander <trotsenkoa@gmail.com>2022-06-29 15:03:43 +0300
commit1a9490c54aa3aa75fde1778b3a41441bb10e157a (patch)
tree9ad7aab8f5190f5a2547812d0cfabf69cee77088
parent1702ce6ce430a66bb7af51644b91b7c196e719d9 (diff)
Работает. Дребезг сенсорных кнопок работает теперь.
-rw-r--r--Libraries/Button/button_handler.c3
-rw-r--r--Libraries/Button/button_task.c107
-rw-r--r--Libraries/LTimers/ltimers.h1
3 files changed, 89 insertions, 22 deletions
diff --git a/Libraries/Button/button_handler.c b/Libraries/Button/button_handler.c
index e25c2c8..8df1e6b 100644
--- a/Libraries/Button/button_handler.c
+++ b/Libraries/Button/button_handler.c
@@ -61,7 +61,8 @@ void ButtonInit ( void )
// -
// Note:
// , ..
-//
+// ( , ,
+// )
// ----------------------------------------------------------------------------
void Button_ProcessFSM ( void )
{
diff --git a/Libraries/Button/button_task.c b/Libraries/Button/button_task.c
index fb5a8c9..4a06a3b 100644
--- a/Libraries/Button/button_task.c
+++ b/Libraries/Button/button_task.c
@@ -3,6 +3,7 @@
#include "nixie_driver_process.h"
#include "button_handler.h"
+#include "ltimers.h"
// FreeRTOS includes
#include "FreeRTOS.h"
@@ -20,6 +21,8 @@
#define TKEY_NUM_1 0
#define TKEY_NUM_2 1
+#define TIME_SENSOR_BUT_DEBOUNCE 50 //ms
+
// - Button_Module
#define TEST_TKEY(NB) ((MyTKeys[(NB)].p_Data->StateId == TSL_STATEID_DETECT) ||\
@@ -40,6 +43,7 @@ static volatile uint8_t tkey_buttons_bits = 0;
static void ProcessSensors ( void );
+static void TkeyDebounce ( void );
// ----------------------------------------------------------------------------
@@ -118,31 +122,31 @@ static void ProcessSensors ( void )
}
#endif
-
+ // ( ,
+ // GROUP5 - )
+
+ TkeyDebounce();
+
//
- if (TEST_TKEY(TKEY_NUM_2))
- {
- tkey_buttons_bits |= 1 << TKEY_NUM_1;
- GPIOB->ODR ^= GPIO_Pin_2;
- }
- else
- {
- tkey_buttons_bits &= ~(1 << TKEY_NUM_1);
- GPIOB->ODR ^= GPIO_Pin_2;
- }
+ // if (TEST_TKEY(TKEY_NUM_2))
+ // {
+ // tkey_buttons_bits |= 1 << TKEY_NUM_1;
+ // }
+ // else
+ // {
+ // tkey_buttons_bits &= ~(1 << TKEY_NUM_1);
+ // }
- if (TEST_TKEY(TKEY_NUM_1))
- {
- tkey_buttons_bits |= 1 << TKEY_NUM_2;
- GPIOB->ODR ^= GPIO_Pin_2;
+ // if (TEST_TKEY(TKEY_NUM_1))
+ // {
+ // tkey_buttons_bits |= 1 << TKEY_NUM_2;
- }
- else
- {
- tkey_buttons_bits &= ~(1 << TKEY_NUM_2);
- GPIOB->ODR ^= GPIO_Pin_2;
- }
+ // }
+ // else
+ // {
+ // tkey_buttons_bits &= ~(1 << TKEY_NUM_2);
+ // }
}
@@ -197,6 +201,67 @@ void MyLinRots_ErrorStateProcess(void)
// ----------------------------------------------------------------------------
+// -
+// ----------------------------------------------------------------------------
+void TkeyDebounce ( void )
+{
+ static uint8_t tkey_db_state = 1;
+ static uint8_t tkey_code = 0;
+ static uint8_t _tkey_code = 1; //
+
+ if (TEST_TKEY(TKEY_NUM_2))
+ {
+ tkey_code |= 1 << TKEY_NUM_1;
+ }
+ else
+ {
+ tkey_code &= ~(1 << TKEY_NUM_1);
+ }
+
+ if (TEST_TKEY(TKEY_NUM_1))
+ {
+ tkey_code |= 1 << TKEY_NUM_2;
+ }
+ else
+ {
+ tkey_code &= ~(1 << TKEY_NUM_2);
+ }
+
+ switch (tkey_db_state)
+ {
+ case 1:
+ if ( tkey_code != _tkey_code ) //
+ {
+ _tkey_code = tkey_code;
+ tkey_db_state = 2;
+ StartLTimer (LTIMER_SENSOR_BUT_DEBOUNCE);
+ }
+ break;
+
+ case 2:
+ if( GetLTimer( LTIMER_SENSOR_BUT_DEBOUNCE ) >= TIME_SENSOR_BUT_DEBOUNCE )
+ {
+ tkey_db_state = 3;
+ }
+ break;
+
+ case 3:
+ if( _tkey_code == tkey_code )
+ {
+ tkey_db_state = 1;
+ tkey_buttons_bits = _tkey_code;
+
+ }
+ else { tkey_db_state = 1; }
+ break;
+
+ default:
+ break;
+ } // end switch
+}
+
+
+// ----------------------------------------------------------------------------
// ,
//
// ----------------------------------------------------------------------------
diff --git a/Libraries/LTimers/ltimers.h b/Libraries/LTimers/ltimers.h
index 9cb6eed..a0370b2 100644
--- a/Libraries/LTimers/ltimers.h
+++ b/Libraries/LTimers/ltimers.h
@@ -15,6 +15,7 @@ typedef enum {
LTIMER_INDIC_MODE_BLINK_ON,
LTIMER_MENU_ADJ_TIME_OUT,
LTIMER_LIGHT_SENSOR,
+ LTIMER_SENSOR_BUT_DEBOUNCE,
MAX_LTIMERS