Skip to main content

ADC_KEY验证

1 按键添加

可以在iconfig添加ADC按键驱动,根据原理图电压值,来设置按键值

2

以x2000_darwin_factory_defconfig为例. 打开IConfigTool工具,选择配置文件

3

1

勾选按键相关辅助命令

4

保存配置

5

重新编译配置

bhu@bhu-PC:~/work/build$ make x2000_darwin_factory_defconfig 

bhu@bhu-PC:~/work/build$ make

烧录固件, 没烧录过见烧录说明

2 添加按键验证

#模板:cmd_keyboard_test [key_code] <timeout=[time_value]> 

#测试adc按键是否正常 key_code对应表如下 time_value为等待时间 单位为s

#"[]"内为必填项,"<>"内为选填项

#该代码表⽰ key_code 必填,"timeout="选填,但若填了"timeout="必需填time_value

cmd_keyboard_test 102 103 108 105 106 139 timeout=15

板子按键对应key_code值

MENU_KEY   //139
UP_KEY //103
DOWN_KEY //108
LEFT_KEY //105
RIGHT_KEY //106
OK_KEY //102

测试按键:

# cmd_keyboard_test 102 103 108 105 106 139 timeout=15               //15秒内依次按下六个按键,按键全部打印出来,测试退出
the keys which you want to test : 102 103 108 105 106 139 //若按下某个按键无打印信息,则表示该按键故障
code of 139 has been press
code of 103 has been press
code of 108 has been press
code of 105 has been press
code of 106 has been press
code of 102 has been press
# cmd_keyboard_test 102 103 108 105 106 139 timeout=5            //5秒内依次按下六个按键
code of 139 has been press
code of 103 has been press
has been timeout now //超时未完成按键验证
the keys are not pressed : 102 108 105 106 //未按下的按键键值

若不设置时间,默认为10s

3 KEYBOARD shell 命令详解

相关源码见libhardware2/src/cmds下的keyboard_main.c

cmd_keyboard  [timeout]
功能:监测键盘输入
参数:timeout //阻塞时间,默认为-1,一直阻塞。为0直接退出
example:
cmd_keyboard timeout=3000
cmd_keyboard wait_key_press <key_code> [timeout]
功能:等待指定按键按下
参数: key_code //按键值
timeout //阻塞时间,默认为-1,一直阻塞。为0直接退出
example:
cmd_keyboard wait_key_press 102
cmd_keyboard wait_key_release <key_code> [timeout]
功能:等待指定按键松开
参数: key_code //按键值
timeout //阻塞时间,默认为-1,一直阻塞。为0直接退出
example:
cmd_keyboard wait_key_release 102 timeout=3000

4 KEYBOARD应用接口分析

相关源码见libhardware2/src/lib/keyboard下的keyboard.c

long keys_open(void)
功能:查找并打开多个按键的设备
参数:无
返回值:成功:按键设备句柄
失败:-1
void keys_close(long handle)
功能:关闭按键设备
参数:handle //按键设备句柄,由keys_open()获得
返回值:无
int read_key_event(long handle, struct key_event *key_event, int timeout)
功能:读取按键事件
参数:handle //按键设备句柄,由keys_open()获得
key_event //按键值和状态的结构体,结构体成员详见中间参数详解
timeout //阻塞时间(-1:一直阻塞)(单位:ms)
返回值:成功:1
超时:0
失败:负数

中间参数详解:

/*按键值和状态结构体*/
struct key_event {
int key_type; //按键值
int is_press; //状态(是否按下)
};

包含头文件:

#include <libhardware2/keyboard.h>