Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug 注意!按键多次抖动导致 长按不调用解决方法 #15

Open
logicDance-mcu opened this issue Sep 12, 2020 · 3 comments
Open

Comments

@logicDance-mcu
Copy link

在multi button .c文件

第132 行!!!!

添加 else {
handle->state = 0;
}
即可解决,

不然会导致长按不生效
!!!!

@logicDance-mcu
Copy link
Author

else if(handle->ticks > SHORT_TICKS){
handle->state = 0;
}

添加成这个

@logicDance-mcu
Copy link
Author

在multi button .c文件

第132 行!!!!

添加 else {
handle->state = 0;
}
即可解决,

不然会导致长按不生效
!!!!

添加成
else if(handle->ticks > SHORT_TICKS){
handle->state = 0;
}

@Jackistang
Copy link

@SSEHX你说的这种情况作者确实没有考虑到,按照代码里的思路,在连续按下、抬起的过程中突然保持按下的动作不变,此时应该切换为状态5也就是长按状态,但是代码卡死在了状态3,因为它必须等待按键抬起。
是不是应该改为下面这种代码呢?当按键按下的时间超过 SHORT_TICKS 个时间后自动切换为状态0,感觉切换成状态1也可以,之后就能够自动处理长按事件了。

	case 3:
		if(handle->button_level != handle->active_level) { //released press up
			handle->event = (uint8_t)PRESS_UP;
			EVENT_CB(PRESS_UP);
			if(handle->ticks < SHORT_TICKS) {
				handle->ticks = 0;
				handle->state = 2; //repeat press
			} else {
				handle->state = 0;
			}
		} else if(handle->ticks > SHORT_TICKS) {
                      handle->state = 0;
                }
		break;

@0x1abin 0x1abin changed the title bug 注意!!!!!按键多次抖动导致 长按不调用解决方法!!!!!!!!!!!!! bug 注意!按键多次抖动导致 长按不调用解决方法 Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants