|
查看: 3862|回复: 8

关于添加多个按键

[复制链接]

22

主题

47

回帖

246

积分

华贵铂金

积分
246
发表于 2024-12-2 18:39:08 | 显示全部楼层 |阅读模式 来自 湖南
image.png

image.png
image.png
我添加多个按键如上图,但是打印出的keycode,一直只有1,2,3三个值,而且松开是3这是为啥呢?只有1,2两个按键能用

20

主题

103

回帖

547

积分

超凡大师

积分
547
发表于 2024-12-3 04:18:28 | 显示全部楼层 来自 澳大利亚
本帖最后由 wes58 于 2024-12-3 04:26 编辑

And I assume that you also have this in user_init():
drv_pm_wakeupPinConfig(g_sensorPmCfg, sizeof(g_sensorPmCfg)/sizeof(drv_pm_pinCfg_t));
I have 8 buttons defined this way and it has been working fine.

22

主题

47

回帖

246

积分

华贵铂金

积分
246
 楼主| 发表于 2024-12-4 08:34:59 | 显示全部楼层 来自 湖南
wes58 发表于 2024-12-3 04:18
And I assume that you also have this in user_init():
drv_pm_wakeupPinConfig(g_sensorPmCfg, sizeof(g_ ...

I also drv_pm_wakeupPinConfig(g_sensorPmCfg, sizeof(g_sensorPmCfg)/sizeof(drv_pm_pinCfg_t));
but my button can't used.

22

主题

47

回帖

246

积分

华贵铂金

积分
246
 楼主| 发表于 2024-12-4 09:08:30 | 显示全部楼层 来自 湖南
wes58 发表于 2024-12-3 04:18
And I assume that you also have this in user_init():
drv_pm_wakeupPinConfig(g_sensorPmCfg, sizeof(g_ ...

the keyCode just only printf :1 2 3;
1204.png

20

主题

103

回帖

547

积分

超凡大师

积分
547
发表于 2024-12-4 12:53:33 | 显示全部楼层 来自 澳大利亚
wx_8236422632 发表于 2024-12-4 09:08
the keyCode just only printf :1 2 3;

You could try to disable PM so device doesn't go to sleep in app_cfg.h. This way you can also monitor variables.
/* PM */
#define PM_ENABLE                                                0
and see if it works then.
You could also add Led's to see if pressing the buttons works, or add some variables and check in BDT. You could add the code below (I only show for one button) in app_ui.c and see the variable btnstate when you press and hold a button.

u8 btnstate[8] = {0};
void app_key_handler(void){
        if(0 == drv_gpio_read(GPIO_PB4)){
                btnstate[4] = 1;
                led_on(LED1);
        }
        else{
                btnstate[4] = 1;
                led_off(LED1);
        }
        
'''' add for all buttons        
}

22

主题

47

回帖

246

积分

华贵铂金

积分
246
 楼主| 发表于 2024-12-4 13:17:20 | 显示全部楼层 来自 湖南
wes58 发表于 2024-12-4 12:53
You could try to disable PM so device doesn't go to sleep in app_cfg.h. This way you can also monit ...

Thanks, I will rewrite it according to your method. Here is how it is written in the Demo
120402.png

20

主题

103

回帖

547

积分

超凡大师

积分
547
发表于 2024-12-4 13:27:30 | 显示全部楼层 来自 澳大利亚
wx_8236422632 发表于 2024-12-4 13:17
Thanks, I will rewrite it according to your method. Here is how it is written in the Demo

You don't have to re-write.
Leave existing code as it is. But for your testing just add at the beginning of the function what I posted.This is just for testing. For working app you will need some button debouncing code..

By the way, you should use code tags "<>" when you post the code. This way someone can easily copy your code

22

主题

47

回帖

246

积分

华贵铂金

积分
246
 楼主| 发表于 2024-12-4 14:17:48 | 显示全部楼层 来自 湖南
wes58 发表于 2024-12-4 13:27
You don't have to re-write.
Leave existing code as it is. But for your testing just add at the be ...

OK,thanks

本版积分规则

关注公众号
隐私政策|Telink forum

相关侵权、举报、投诉及建议等,请发 E-mail:forum@telink-semi.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|沪ICP备17008231号-1 |沪公网安备31011502403548号

在本版发帖返回顶部