fix spelling mistakes

pull/10/head
wildfarmer 6 years ago
parent 807a6cb20a
commit 054e1cca68

@ -33,7 +33,7 @@ while(1) {
...
if(timer_ticks == 5) {
timer_ticks = 0;
button_ticks();
}
}
@ -49,7 +49,7 @@ struct Button {
uint8_t repeat: 4;
uint8_t event : 4;
uint8_t state : 3;
uint8_t debounce_cnt : 3;
uint8_t debounce_cnt : 3;
uint8_t active_level : 1;
uint8_t button_level : 1;
uint8_t (*hal_button_Level)(void);
@ -69,7 +69,7 @@ PRESS_UP | 按键弹起,每次松开都触发
PRESS_REPEAT | 重复按下触发变量repeat计数连击次数
SINGLE_CLICK | 单击按键事件
DOUBLE_CLICK | 双击按键事件
LONG_RRESS_START | 达到长按时间阈值时触发一次
LONG_PRESS_START | 达到长按时间阈值时触发一次
LONG_PRESS_HOLD | 长按期间一直触发
@ -80,7 +80,7 @@ LONG_PRESS_HOLD | 长按期间一直触发
struct Button btn1;
int read_button1_GPIO()
int read_button1_GPIO()
{
return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
}
@ -93,15 +93,15 @@ int main()
button_attach(&btn1, PRESS_REPEAT, BTN1_PRESS_REPEAT_Handler);
button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_Click_Handler);
button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler);
button_attach(&btn1, LONG_RRESS_START, BTN1_LONG_RRESS_START_Handler);
button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler);
button_attach(&btn2, LONG_PRESS_HOLD, BTN1_LONG_PRESS_HOLD_Handler);
button_start(&btn1);
//make the timer invoking the button_ticks() interval 5ms.
//This function is implemented by yourself.
__timer_start(button_ticks, 0, 5);
while(1)
__timer_start(button_ticks, 0, 5);
while(1)
{}
}

@ -3,12 +3,12 @@
struct Button btn1;
struct Button btn2;
uint8_t read_button1_GPIO()
uint8_t read_button1_GPIO()
{
return HAL_GPIO_ReadPin(B1_GPIO_Port, B1_Pin);
}
uint8_t read_button2_GPIO()
uint8_t read_button2_GPIO()
{
return HAL_GPIO_ReadPin(B2_GPIO_Port, B2_Pin);
}
@ -17,31 +17,31 @@ int main()
{
button_init(&btn1, read_button1_GPIO, 0);
button_init(&btn2, read_button2_GPIO, 0);
button_attach(&btn1, PRESS_DOWN, BTN1_PRESS_DOWN_Handler);
button_attach(&btn1, PRESS_UP, BTN1_PRESS_UP_Handler);
button_attach(&btn1, PRESS_REPEAT, BTN1_PRESS_REPEAT_Handler);
button_attach(&btn1, SINGLE_CLICK, BTN1_SINGLE_Click_Handler);
button_attach(&btn1, DOUBLE_CLICK, BTN1_DOUBLE_Click_Handler);
button_attach(&btn1, LONG_RRESS_START, BTN1_LONG_RRESS_START_Handler);
button_attach(&btn1, LONG_PRESS_START, BTN1_LONG_PRESS_START_Handler);
button_attach(&btn1, LONG_PRESS_HOLD, BTN1_LONG_PRESS_HOLD_Handler);
button_attach(&btn2, PRESS_DOWN, BTN2_PRESS_DOWN_Handler);
button_attach(&btn2, PRESS_UP, BTN2_PRESS_UP_Handler);
button_attach(&btn2, PRESS_REPEAT, BTN2_PRESS_REPEAT_Handler);
button_attach(&btn2, SINGLE_CLICK, BTN2_SINGLE_Click_Handler);
button_attach(&btn2, DOUBLE_CLICK, BTN2_DOUBLE_Click_Handler);
button_attach(&btn2, LONG_RRESS_START, BTN2_LONG_RRESS_START_Handler);
button_attach(&btn2, LONG_PRESS_START, BTN2_LONG_PRESS_START_Handler);
button_attach(&btn2, LONG_PRESS_HOLD, BTN2_LONG_PRESS_HOLD_Handler);
button_start(&btn1);
button_start(&btn2);
//make the timer invoking the button_ticks() interval 5ms.
//This function is implemented by yourself.
__timer_start(button_ticks, 0, 5);
while(1)
__timer_start(button_ticks, 0, 5);
while(1)
{}
}

@ -6,7 +6,7 @@
#include "multi_button.h"
#define EVENT_CB(ev) if(handle->cb[ev])handle->cb[ev]((Button*)handle)
//button handle list head.
static struct Button* head_handle = NULL;
@ -93,8 +93,8 @@ void button_handler(struct Button* handle)
handle->state = 2;
} else if(handle->ticks > LONG_TICKS) {
handle->event = (uint8_t)LONG_RRESS_START;
EVENT_CB(LONG_RRESS_START);
handle->event = (uint8_t)LONG_PRESS_START;
EVENT_CB(LONG_PRESS_START);
handle->state = 5;
}
break;
@ -103,7 +103,7 @@ void button_handler(struct Button* handle)
if(handle->button_level == handle->active_level) { //press down again
handle->event = (uint8_t)PRESS_DOWN;
EVENT_CB(PRESS_DOWN);
handle->repeat++;
handle->repeat++;
EVENT_CB(PRESS_REPEAT); // repeat hit
handle->ticks = 0;
handle->state = 3;

@ -2,7 +2,7 @@
* Copyright (c) 2016 Zibin Zheng <znbin@qq.com>
* All rights reserved
*/
#ifndef _MULTI_BUTTON_H_
#define _MULTI_BUTTON_H_
@ -24,7 +24,7 @@ typedef enum {
PRESS_REPEAT,
SINGLE_CLICK,
DOUBLE_CLICK,
LONG_RRESS_START,
LONG_PRESS_START,
LONG_PRESS_HOLD,
number_of_event,
NONE_PRESS
@ -35,7 +35,7 @@ typedef struct Button {
uint8_t repeat : 4;
uint8_t event : 4;
uint8_t state : 3;
uint8_t debounce_cnt : 3;
uint8_t debounce_cnt : 3;
uint8_t active_level : 1;
uint8_t button_level : 1;
uint8_t (*hal_button_Level)(void);
@ -43,9 +43,9 @@ typedef struct Button {
struct Button* next;
}Button;
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
extern "C" {
#endif
void button_init(struct Button* handle, uint8_t(*pin_level)(), uint8_t active_level);
void button_attach(struct Button* handle, PressEvent event, BtnCallback cb);
@ -55,7 +55,7 @@ void button_stop(struct Button* handle);
void button_ticks(void);
#ifdef __cplusplus
}
}
#endif
#endif

Loading…
Cancel
Save