ecsimsw / JNI-JellyBean-HBE-SM5-S4210

Customized JellyBean with Hanback device driver.
0 stars 0 forks source link

Usb keyboard driver test, event listen in android #4

Closed ecsimsw closed 2 years ago

ecsimsw commented 2 years ago
  1. keyboard input driver test
  2. handling event in android studio
ecsimsw commented 2 years ago

https://stackoverflow.com/questions/66541256/in-android-how-to-find-what-dev-input-event-is-used-for-touchscreen-using-c-fu dev/input/event0 : keyboard event dev/input/event1 : touch screen event dev/input/event2 : keypad event

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>

 #define EVENT_BUF_NUM 64

 int main(void) {
  int i, quit = 1;
  int fd = -1;

  size_t read_bytes;
     struct input_event event_buf[EVENT_BUF_NUM];

     fd = open("/dev/input/event0", O_RDONLY);

     if(fd < 0) {
         printf("application : keypad driver open fail!\n");
         exit(1);
     }

     read(fd, event_buf, sizeof(struct input_event) * EVENT_BUF_NUM);

     printf("press the key button!\n");

     quit = 1;
     while(quit) {
         read_bytes = read(fd, event_buf, (sizeof(struct input_event)*EVENT_BUF_NUM) );
         for(i=0; i<(read_bytes/sizeof(struct input_event)); i++ ) {
             if ((event_buf[i].type == EV_KEY) && (event_buf[i].value == 0)) {
                 printf("\n  Button key : %d\n", event_buf[i].code);

                 if(event_buf[i].code == 16) {
                     quit = 0;
                 }
             }
         }
     }
     close(fd);
     return 0;
 }
ecsimsw commented 2 years ago

Num pad 1~9, KeyEvent object

D/KeyUP Event: 145
D/KeyUP Event: 146
D/KeyUP Event: 147
D/KeyUP Event: 148
D/KeyUP Event: 149
D/KeyUP Event: 150
D/KeyUP Event: 151
D/KeyUP Event: 152
D/KeyUP Event: 153
YGwan commented 2 years ago

cat /proc/bus/input/devices

I: Bus=0018 Vendor=0001 Product=0002 Version=0100
N: Name="zinitix_touch"
P: Phys=input(ts)
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=b
B: KEY=2000000 0 40000800 40 0 0 0
B: ABS=650000 10000000

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="im3640"
P: Phys=
S: Sysfs=/devices/virtual/input/input1
U: Uniq=
H: Handlers=event1
B: PROP=0
B: EV=9
B: ABS=3043f

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="mpu3050"
P: Phys=
S: Sysfs=/devices/virtual/input/input2
U: Uniq=
H: Handlers=event2
B: PROP=0
B: EV=5
B: REL=38

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="proximity"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=event3
B: PROP=0
B: EV=9
B: ABS=2000000

I: Bus=0019 Vendor=1002 Product=1002 Version=0000
N: Name="fpga-keypad"
P: Phys=keypad/input1
S: Sysfs=/devices/virtual/input/input4
U: Uniq=
H: Handlers=sysrq kbd event4
B: PROP=0
B: EV=3
B: KEY=3ffffffe

I: Bus=0019 Vendor=16b4 Product=0701 Version=0001
N: Name="s4210-keypad"
P: Phys=s4210-keypad/input0
S: Sysfs=/devices/virtual/input/input5
U: Uniq=
H: Handlers=kbd event5
B: PROP=0
B: EV=23
B: KEY=1c0000 0 0 0
B: SW=1

I: Bus=0003 Vendor=0a5c Product=4502 Version=0111
N: Name="HID 0a5c:4502"
P: Phys=usb-s5p-ehci-1.3.1/input0
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.3/1-1.3.1/1-1.3.1:1.0/input/input6
U: Uniq=
H: Handlers=sysrq kbd event6
B: PROP=0
B: EV=120013
B: KEY=10000 7 ff800000 7ff febeffdf f3cfffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=0a5c Product=4503 Version=0111
N: Name="HID 0a5c:4503"
P: Phys=usb-s5p-ehci-1.3.2/input0
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input7
U: Uniq=
H: Handlers=event7
B: PROP=0
B: EV=17
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=3
B: MSC=10
YGwan commented 2 years ago

find keycode in linux/input.h with cscope

image

ecsimsw commented 2 years ago

KEYPAD event file 위치는 계속 바뀐다.

cat /proc/bus/input/devices

I: Bus=0018 Vendor=0001 Product=0002 Version=0100
N: Name="zinitix_touch"
P: Phys=input(ts)
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=kbd event0
B: PROP=0
B: EV=b
B: KEY=2000000 0 40000800 40 0 0 0
B: ABS=650000 10000000

I: Bus=0003 Vendor=413c Product=2113 Version=0111
N: Name="Dell KB216 Wired Keyboard"
P: Phys=usb-s5p-ehci-1.1/input0
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.1/1-1.1:1.0/input/input1
U: Uniq=
H: Handlers=sysrq kbd event1
B: PROP=0
B: EV=120013
B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=413c Product=2113 Version=0111
N: Name="Dell KB216 Wired Keyboard"
P: Phys=usb-s5p-ehci-1.1/input1
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.1/1-1.1:1.1/input/input2
U: Uniq=
H: Handlers=kbd event2
B: PROP=0
B: EV=13
B: KEY=800 2000000 387a d801d001 1e0000 0 0 0
B: MSC=10

I: Bus=0018 Vendor=0000 Product=0000 Version=0000
N: Name="im3640"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=event3
B: PROP=0
B: EV=9
B: ABS=3043f

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="mpu3050"
P: Phys=
S: Sysfs=/devices/virtual/input/input4
U: Uniq=
H: Handlers=event4
B: PROP=0
B: EV=5
B: REL=38

I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="proximity"
P: Phys=
S: Sysfs=/devices/virtual/input/input5
U: Uniq=
H: Handlers=event5
B: PROP=0
B: EV=9
B: ABS=2000000

I: Bus=0019 Vendor=1002 Product=1002 Version=0000
N: Name="fpga-keypad"
P: Phys=keypad/input1
S: Sysfs=/devices/virtual/input/input6
U: Uniq=
H: Handlers=sysrq kbd event6
B: PROP=0
B: EV=3
B: KEY=3ffffffe

I: Bus=0019 Vendor=16b4 Product=0701 Version=0001
N: Name="s4210-keypad"
P: Phys=s4210-keypad/input0
S: Sysfs=/devices/virtual/input/input7
U: Uniq=
H: Handlers=kbd event7
B: PROP=0
B: EV=23
B: KEY=1c0000 0 0 0
B: SW=1

I: Bus=0003 Vendor=0a5c Product=4502 Version=0111
N: Name="HID 0a5c:4502"
P: Phys=usb-s5p-ehci-1.3.1/input0
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.3/1-1.3.1/1-1.3.1:1.0/input/input8
U: Uniq=
H: Handlers=sysrq kbd event8
B: PROP=0
B: EV=120013
B: KEY=10000 7 ff800000 7ff febeffdf f3cfffff ffffffff fffffffe
B: MSC=10
B: LED=7

I: Bus=0003 Vendor=0a5c Product=4503 Version=0111
N: Name="HID 0a5c:4503"
P: Phys=usb-s5p-ehci-1.3.2/input0
S: Sysfs=/devices/platform/s5p-ehci/usb1/1-1/1-1.3/1-1.3.2/1-1.3.2:1.0/input/input9
U: Uniq=
H: Handlers=event9
B: PROP=0
B: EV=17
B: KEY=70000 0 0 0 0 0 0 0 0
B: REL=3
B: MSC=10
ecsimsw commented 2 years ago
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/ioctl.h>
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <linux/input.h>
10 #include <linux/kernel.h>
11
12 #define EVENT_BUF_NUM 64
13
14 int main(void) {
15  int i, quit = 1;
16  int fd = -1;
17
18  size_t read_bytes;
19     struct input_event event_buf[EVENT_BUF_NUM];
20
21     fd = open("/dev/input/event6", O_RDONLY);
22
23     if(fd < 0) {
24         printf("application : keypad driver open fail!\n");
25         exit(1);
26     }
27
28     read(fd, event_buf, sizeof(struct input_event) * EVENT_BUF_NUM);
29
30     quit = 1;
31     while(quit) {
32         read_bytes = read(fd, event_buf, (sizeof(struct input_event)*EVENT_BUF_NUM) );
33         for(i=0; i<(read_bytes/sizeof(struct input_event)); i++ ) {
34             if ((event_buf[i].type == EV_KEY) && (event_buf[i].value == 0)) {
35                 printf("\n  Button key : %d\n", event_buf[i].code);
36
37                  if(event_buf[i].code == 13) {
38                     quit = 0;
39                 }
40             }
41         }
42     }
43     close(fd);
44     return 0;
45 }

image