mirror of
https://github.com/0x1abin/MultiButton.git
synced 2025-01-25 08:32:55 +08:00
格式化代码
1,给button_handler()添加静态属性。 2,函数声明和定义格式统一。 3,删除不必要的空行。 4,源码采用统一的tab替代空格键。 5,为else添加大括号。
This commit is contained in:
parent
3ec5425cdf
commit
41514fed4b
@ -18,7 +18,7 @@ uint8_t read_button_GPIO(uint8_t button_id)
|
||||
|
||||
int main()
|
||||
{
|
||||
static uint8_t btn1_event_val;
|
||||
static PressEvent btn1_event_val;
|
||||
|
||||
button_init(&btn1, read_button_GPIO, 0, btn1_id);
|
||||
button_start(&btn1);
|
||||
|
@ -10,6 +10,8 @@
|
||||
//button handle list head.
|
||||
static struct Button* head_handle = NULL;
|
||||
|
||||
static void button_handler(struct Button* handle);
|
||||
|
||||
/**
|
||||
* @brief Initializes the button struct handle.
|
||||
* @param handle: the button handle struct.
|
||||
@ -55,7 +57,7 @@ PressEvent get_button_event(struct Button* handle)
|
||||
* @param handle: the button handle struct.
|
||||
* @retval None
|
||||
*/
|
||||
void button_handler(struct Button* handle)
|
||||
static void button_handler(struct Button* handle)
|
||||
{
|
||||
uint8_t read_gpio_level = handle->hal_button_Level(handle->button_id);
|
||||
|
||||
@ -93,7 +95,6 @@ void button_handler(struct Button* handle)
|
||||
EVENT_CB(PRESS_UP);
|
||||
handle->ticks = 0;
|
||||
handle->state = 2;
|
||||
|
||||
} else if(handle->ticks > LONG_TICKS) {
|
||||
handle->event = (uint8_t)LONG_PRESS_START;
|
||||
EVENT_CB(LONG_PRESS_START);
|
||||
@ -131,7 +132,7 @@ void button_handler(struct Button* handle)
|
||||
} else {
|
||||
handle->state = 0;
|
||||
}
|
||||
}else if(handle->ticks > SHORT_TICKS){ // long press up
|
||||
} else if(handle->ticks > SHORT_TICKS) { // long press up
|
||||
handle->state = 0;
|
||||
}
|
||||
break;
|
||||
@ -141,16 +142,15 @@ void button_handler(struct Button* handle)
|
||||
//continue hold trigger
|
||||
handle->event = (uint8_t)LONG_PRESS_HOLD;
|
||||
EVENT_CB(LONG_PRESS_HOLD);
|
||||
|
||||
} else { //releasd
|
||||
handle->event = (uint8_t)PRESS_UP;
|
||||
EVENT_CB(PRESS_UP);
|
||||
handle->state = 0; //reset
|
||||
}
|
||||
break;
|
||||
default:
|
||||
handle->state = 0; //reset
|
||||
break;
|
||||
default:
|
||||
handle->state = 0; //reset
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,12 +181,13 @@ void button_stop(struct Button* handle)
|
||||
struct Button** curr;
|
||||
for(curr = &head_handle; *curr; ) {
|
||||
struct Button* entry = *curr;
|
||||
if (entry == handle) {
|
||||
if(entry == handle) {
|
||||
*curr = entry->next;
|
||||
// free(entry);
|
||||
return;//glacier add 2021-8-18
|
||||
} else
|
||||
} else {
|
||||
curr = &entry->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +196,7 @@ void button_stop(struct Button* handle)
|
||||
* @param None.
|
||||
* @retval None
|
||||
*/
|
||||
void button_ticks()
|
||||
void button_ticks(void)
|
||||
{
|
||||
struct Button* target;
|
||||
for(target=head_handle; target; target=target->next) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user