在 Android 通过 get_event 获得 input 设备 上报event

本文介绍了Android系统中用于获取input设备上报event的工具get_event,包括如何使用该工具以及如何通过静态编译和adb推送进行调试。内容涵盖红外gp2ap、touchscreen、物理按键key和headset的上报event,以及get_event.c源码的调试方法。
摘要由CSDN通过智能技术生成

Android 本身有一个genevnet 和 sendevent 工具用来从内核获取event事件和向内核发送event事件,具体可以参考  Android 下收发input事件的工具 getevent 和 sendevent

o get_evnet 是一个可以获得注册成input设备上报event的调试工具。

o usage: get_event /dev/input/eventX, X is 0, 1, 2,3,  4, 5,6

o 附件为其源代码, 可以采用静态编译,然后通过adb push进 手机, 进行调试。

arm-linux-gcc -static get_event.c -o get_evnet

-> 获得 红外gp2ap 的上报 event
    shell@android:/ # get_event /dev/input/event0
    Input driver version is 1.0.1
    Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0
    Input device name: gp2ap
    Supported events:
      Event type 0 (Sync)
      Event type 3 (Absolute)
        Event code 25 (Distance)
          Value     -1
          Min        0
          Max        1
        Event code 40 (Misc)
          Value      0
          Min        0
          Max    65535

    Testing ... (interrupt to exit)

-> 获得touchscreen 的上报 event
130|shell@android:/ # get_event /dev/input/event1
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x0 product 0x1 version 0x1005
Input device name: mx_ts
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 102 (Home)
    Event code 103 (Up)
    Event code 105 (Left)
    Event code 106 (Right)
    Event code 107 (End)
    Event code 108 (Down)
    Event code 129 (Again)
    Event code 158 (Back)
    Event code 325 (ToolFinger)
    Event code 330 (Touch)
  Event type 3 (Absolute)
    Event code 0 (X)
      Value      0
      Min        0
      Max     1334
    Event code 1 (Y)
      Value      0
      Min        0
      Max     2214
    Event code 24 (Pressure)
      Value      0
      Min        0
      Max      255
    Event code 47 (?)
      Value      0
      Min        0
      Max        9
    Event code 48 (ABS_MT_TOUCH_MAJOR)
      Value      0
      Min        0
      Max       15
    Event code 53 (ABS_MT_POSITION_X)
      Value      0
      Min        0
      Max     1334
    Event code 54 (ABS_MT_POSITION_Y)
      Value      0
      Min        0
      Max     2214
    Event code 57 (ABS_MT_TRACKING_ID)
      Value      0
      Min        0
      Max    65535
    Event code 58 (ABS_MT_PRESSURE)
      Value      0
      Min        0
      Max      255
Testing ... (interrupt to exit)
Event: time 1325376099.794968, type 3 (Absolute), code 57 (ABS_MT_TRACKING_ID), value 0
Event: time 1325376099.794990, type 1 (Key), code 330 (Touch), value 1
Event: time 1325376099.794999, type 1 (Key), code 325 (ToolFinger), value 1
Event: time 1325376099.795009, type 3 (Absolute), code 53 (ABS_MT_POSITION_X), value 738
Event: time 1325376099.795018, type 3 (Absolute), code 54 (ABS_MT_POSITION_Y), value 1487
Event: time 1325376099.795027, type 3 (Absolute), code 58 (ABS_MT_PRESSURE), value 84
Event: time 1325376099.795036, type 3 (Absolute), code 48 (ABS_MT_TOUCH_MAJOR), value 4
Event: time 1325376099.795090, -------------- Report Sync ------------
Event: time 1325376099.903355, type 3 (Absolute), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1325376099.903432, -------------- Report Sync ------------
-> 获得物理按键key 的上报 event
130|shell@android:/ # get_event /dev/input/event2
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x1 product 0x1 version 0x100
Input device name: gpio-keys
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 102 (Home)
    Event code 114 (VolumeDown)
    Event code 115 (VolumeUp)
    Event code 116 (Power)
Testing ... (interrupt to exit)

Event: time 1325376161.600192, type 1 (Key), code 115 (VolumeUp), value 1
Event: time 1325376161.600214, -------------- Report Sync ------------
Event: time 1325376161.794925, type 1 (Key), code 115 (VolumeUp), value 0
Event: time 1325376161.794933, -------------- Report Sync ------------
Event: time 1325376162.645193, type 1 (Key), code 102 (Home), value 1
Event: time 1325376162.645215, -------------- Report Sync ------------
Event: time 1325376162.794977, type 1 (Key), code 102 (Home), value 0
Event: time 1325376162.794995, -------------- Report Sync ------------
Event: time 1325376164.970050, type 1 (Key), code 114 (VolumeDown), value 1
Event: time 1325376164.970072, -------------- Report Sync ------------
Event: time 1325376164.975038, type 1 (Key), code 114 (VolumeDown), value 0
Event: time 1325376164.975058, -------------- Report Sync ------------
Event: time 1325376165.000110, type 1 (Key), code 114 (VolumeDown), value 1
Event: time 1325376165.000135, -------------- Report Sync ------------
Event: time 1325376165.005173, type 1 (Key), code 114 (VolumeDown), value 0
Event: time 1325376165.005190, -------------- Report Sync ------------
Event: time 1325376166.700714, type 1 (Key), code 116 (Power), value 1
Event: time 1325376166.700737, -------------- Report Sync ------------
Event: time 1325376167.005092, type 1 (Key), code 116 (Power), value 0
Event: time 1325376167.005110, -------------- Report Sync ------------
-> 获得headset 的上报 event
130|shell@android:/ # get_event /dev/input/event3
Input driver version is 1.0.1
Input device ID: bus 0x0 vendor 0x0 product 0x0 version 0x0
Input device name: Headset
Supported events:
  Event type 0 (Sync)
  Event type 1 (Key)
    Event code 226 (Media)
    Event code 259
static void input_task(void *priv) { int ret; start_run = 1; aos_sem_new(&g_input_sem, 0); ret = csi_codec_init(&g_codec, 0); if (ret != CSI_OK) { LOG("csi_codec_init error\n"); return; } g_input_hdl.ring_buf = &input_ring_buffer; g_input_hdl.sound_channel_num = INPUT_CHANNELS; ret = csi_codec_input_open(&g_codec, &g_input_hdl, 0); input_check(ret); ret = csi_codec_input_attach_callback(&g_input_hdl, codec_input_event_cb_fun, NULL); input_check(ret); /* input ch config */ g_input_config.bit_width = INPUT_SAMPLE_BITS; g_input_config.sample_rate = INPUT_SAMPLE_RATE; g_input_config.buffer = g_input_buf; g_input_config.buffer_size = INPUT_BUFFER_SIZE; g_input_config.period = INPUT_PERIOD_SIZE; g_input_config.mode = CODEC_INPUT_DIFFERENCE; g_input_config.sound_channel_num = INPUT_CHANNELS; ret = csi_codec_input_config(&g_input_hdl, &g_input_config); input_check(ret); ret = csi_codec_input_analog_gain(&g_input_hdl, 0xcf); input_check(ret); ret = csi_codec_input_digital_gain(&g_input_hdl, 25); input_check(ret); ret = csi_codec_input_link_dma(&g_input_hdl, &dma_ch_input_handle); input_check(ret); ret = csi_codec_input_start(&g_input_hdl); input_check(ret); uint32_t size = 0; uint32_t r_size = 0; g_input_size = 0; // printf("input start(%lld)\n", aos_now_ms()); while (1) { input_wait(); r_size = (g_input_size + INPUT_PERIOD_SIZE) < READ_BUFFER_SIZE ? INPUT_PERIOD_SIZE : (READ_BUFFER_SIZE-g_input_size); size = csi_codec_input_read_async(&g_input_hdl, g_read_buffer + g_input_size, r_size); if (size != INPUT_PERIOD_SIZE) { // printf("input stop, get (%d)ms data (%lld)\n", READ_TIME, aos_now_ms()); printf("read size err(%u)(%u)\n", size, r_size); break; } g_input_size += r_size; } aos_sem_free(&g_input_sem); csi_codec_input_stop(&g_input_hdl); csi_codec_input_link_dma(&g_input_hdl, NULL); csi_codec_input_detach_callback(&g_input_hdl); csi_codec_uninit(&g_codec); start_run = 0; }函数解析
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值