hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
 
#include <linux/input.h>
#include <fcntl.h>
#include <dirent.h>
#include "common.h"
#include "key_test.h"
#include "test_case.h"
#include "language.h"
#define test_bit(bit, array)    (array[bit/8] & (1<<(bit%8)))
 
#include "screen_test.h"
 
unsigned char keybitmask[(KEY_MAX + 1) / 8];
struct key key_code[KEY_MAX];
unsigned char key_cnt = 0;        /*key counter */
unsigned int gkey = 0;
static pthread_mutex_t gkeymutex = PTHREAD_MUTEX_INITIALIZER;
 
int g_key_test = 0;
static struct testcase_info *tc_info;
 
int set_gkey(unsigned int code)
{
   int i;
   for (i = 0; i < key_cnt; i++) {
       if (code == key_code[i].code) {
           ui_print_xy_rgba(0, tc_info->y, 0, 255, 0, 255,
               "%s:[%s] key down\n", PCBA_KEY,
               key_code[i].name);
           screenTest_key_detect(code);
           break;
       }
   }
   return 0;
}
 
int scan_key_code(void)
{
   unsigned temp = 0;
 
   pthread_mutex_lock(&gkeymutex);
   if (gkey) {
       temp = gkey;
       gkey = 0;
   }
   pthread_mutex_unlock(&gkeymutex);
 
   return temp;
}
void switch_key(int i)
{
   key_code[key_cnt].code = i;
   switch (i) {
   case KEY_VOLUMEDOWN:
       key_code[key_cnt].name = "vol-";
       break;
   case KEY_VOLUMEUP:
       key_code[key_cnt].name = "vol+";
       break;
   case KEY_POWER:
       key_code[key_cnt].name = "power";
       break;
   case KEY_F1:
       key_code[key_cnt].name = "menu";
#ifdef RK312X_PCBA
       key_code[key_cnt].name = "vol+";
#endif
       break;
   case KEY_HOME:
       key_code[key_cnt].name = "home";
       break;
   case KEY_BACK:
       key_code[key_cnt].name = "ESC";
       break;
   case KEY_UP:
       key_code[key_cnt].name = "UP";
       break;
   case KEY_DOWN:
       key_code[key_cnt].name = "DOWN";
       break;
   case KEY_LEFT:
       key_code[key_cnt].name = "LEFT";
       break;
   case KEY_RIGHT:
       key_code[key_cnt].name = "RIGHT";
       break;
   case KEY_MENU:
       key_code[key_cnt].name = "MENU";
       break;
   case KEY_ENTER:
   case KEY_REPLY:
       key_code[key_cnt].name = "OK";
       break;
   default:
       printf("un supported key:%d\n", i);
       break;
   }
   key_cnt++;
}
int key_code_probe(void)
{
   DIR *dir;
   struct dirent *de;
   int fd;
   char name[80];
   int i;
 
   dir = opendir("/dev/input");
   if (dir != 0) {
       while ((de = readdir(dir))) {
           if (strncmp(de->d_name, "event", 5))
               continue;
           fd = openat(dirfd(dir), de->d_name, O_RDONLY);
           if (fd < 0) {
               continue;
           } else {
               if (ioctl
                   (fd, EVIOCGNAME(sizeof(name) - 1),
                    &name) < 1) {
                   name[0] = '\0';
               }
               /*do not open gsensor here */
               if (!strcmp(name, "gsensor"))
                   continue;
               ioctl(fd,
                     EVIOCGBIT(EV_KEY, sizeof(keybitmask)),
                     keybitmask);
               for (i = 0; i < KEY_MAX; i++) {
                   if (test_bit(i, keybitmask) &&
                       (i != KEY_WAKEUP))
                       switch_key(i);
               }
           }
       }
   }
 
   return 0;
}
void *key_test(void *argc)
{
   int i = 0;
   int code;
   int run = 1;
 
   tc_info = (struct testcase_info *)argc;
 
   if (tc_info->y <= 0)
       tc_info->y = get_cur_print_y();
 
   ui_print_xy_rgba(0, tc_info->y, 255, 255, 0, 255, "%s: Waiting press key...\n", PCBA_KEY);
   key_code_probe();
   g_key_test = 1;
 
   return NULL;
}