@@ -37,6 +37,8 @@ void button_init(struct button* handle, uint8_t(*pin_level)(void), uint8_t activ
3737 handle -> hal_button_Level = pin_level ;
3838 handle -> button_level = !active_level ;
3939 handle -> active_level = active_level ;
40+ handle -> short_ticks = SHORT_TICKS ;
41+ handle -> long_ticks = LONG_TICKS ;
4042}
4143
4244/**
@@ -51,6 +53,28 @@ void button_attach(struct button* handle, PressEvent event, BtnCallback cb)
5153 handle -> cb [event ] = cb ;
5254}
5355
56+ /**
57+ * @brief Attach the button adjust ticks
58+ * @param handle: the button handle strcut.
59+ * @param ticks: judge short ticks(unit:ms)
60+ * @retval None
61+ */
62+ void button_set_short_ticks (struct Button * handle , uint16_t ticks )
63+ {
64+ handle -> short_ticks = ticks / TICKS_INTERVAL ;
65+ }
66+
67+ /**
68+ * @brief Attach the button adjust long ticks
69+ * @param handle: the button handle strcut.
70+ * @param ticks: judge long ticks(unit:ms)
71+ * @retval None
72+ */
73+ void button_set_long_ticks (struct Button * handle , uint16_t ticks )
74+ {
75+ handle -> long_ticks = ticks / TICKS_INTERVAL ;
76+ }
77+
5478/**
5579 * @brief Inquire the button event happen.
5680 * @param handle: the button handle struct.
@@ -119,7 +143,7 @@ static void button_handler(struct button* handle)
119143 handle -> ticks = 0 ;
120144 handle -> state = 2 ;
121145 }
122- else if (handle -> ticks > LONG_TICKS )
146+ else if (handle -> ticks > handle -> long_ticks )
123147 {
124148 handle -> event = (uint8_t )LONG_PRESS_START ;
125149 EVENT_CB (LONG_PRESS_START );
@@ -140,7 +164,7 @@ static void button_handler(struct button* handle)
140164 handle -> ticks = 0 ;
141165 handle -> state = 3 ;
142166 }
143- else if (handle -> ticks > SHORT_TICKS )
167+ else if (handle -> ticks > handle -> short_ticks )
144168 {
145169 if (handle -> repeat == 1 )
146170 {
@@ -162,7 +186,7 @@ static void button_handler(struct button* handle)
162186 handle -> event = (uint8_t )PRESS_UP ;
163187 EVENT_CB (PRESS_UP );
164188
165- if (handle -> ticks < SHORT_TICKS )
189+ if (handle -> ticks < handle -> short_ticks )
166190 {
167191 handle -> ticks = 0 ;
168192 handle -> state = 2 ;
@@ -172,7 +196,7 @@ static void button_handler(struct button* handle)
172196 handle -> state = 0 ;
173197 }
174198 }
175- else if (handle -> ticks > SHORT_TICKS ) // SHORT_TICKS < press down hold time < LONG_TICKS
199+ else if (handle -> ticks > handle -> short_ticks ) // SHORT_TICKS < press down hold time < LONG_TICKS
176200 {
177201 handle -> state = 1 ;
178202 }
0 commit comments