@@ -37,6 +37,8 @@ void button_init(struct button* handle, uint8_t(*pin_level)(void), uint8_t activ
37
37
handle -> hal_button_Level = pin_level ;
38
38
handle -> button_level = !active_level ;
39
39
handle -> active_level = active_level ;
40
+ handle -> short_ticks = SHORT_TICKS ;
41
+ handle -> long_ticks = LONG_TICKS ;
40
42
}
41
43
42
44
/**
@@ -51,6 +53,28 @@ void button_attach(struct button* handle, PressEvent event, BtnCallback cb)
51
53
handle -> cb [event ] = cb ;
52
54
}
53
55
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
+
54
78
/**
55
79
* @brief Inquire the button event happen.
56
80
* @param handle: the button handle struct.
@@ -119,7 +143,7 @@ static void button_handler(struct button* handle)
119
143
handle -> ticks = 0 ;
120
144
handle -> state = 2 ;
121
145
}
122
- else if (handle -> ticks > LONG_TICKS )
146
+ else if (handle -> ticks > handle -> long_ticks )
123
147
{
124
148
handle -> event = (uint8_t )LONG_PRESS_START ;
125
149
EVENT_CB (LONG_PRESS_START );
@@ -140,7 +164,7 @@ static void button_handler(struct button* handle)
140
164
handle -> ticks = 0 ;
141
165
handle -> state = 3 ;
142
166
}
143
- else if (handle -> ticks > SHORT_TICKS )
167
+ else if (handle -> ticks > handle -> short_ticks )
144
168
{
145
169
if (handle -> repeat == 1 )
146
170
{
@@ -162,7 +186,7 @@ static void button_handler(struct button* handle)
162
186
handle -> event = (uint8_t )PRESS_UP ;
163
187
EVENT_CB (PRESS_UP );
164
188
165
- if (handle -> ticks < SHORT_TICKS )
189
+ if (handle -> ticks < handle -> short_ticks )
166
190
{
167
191
handle -> ticks = 0 ;
168
192
handle -> state = 2 ;
@@ -172,7 +196,7 @@ static void button_handler(struct button* handle)
172
196
handle -> state = 0 ;
173
197
}
174
198
}
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
176
200
{
177
201
handle -> state = 1 ;
178
202
}
0 commit comments