xref: /OK3568_Linux_fs/external/rk_pcba_test/pcba_minui/screen_test.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include "screen_test.h"
6 #include "test_case.h"
7 #include "common.h"
8 #include "language.h"
9 #include "minui/minui.h"
10 
11 #include <linux/input.h>
12 #include "script.h"
13 
14 /*  variable for test_config.cfg  */
15 int key_times;
16 int all_key_change;
17 unsigned int start_key;
18 
19 unsigned int code_tmp = 0;
20 unsigned int picture_change_key;
21 
22 unsigned char code_cnt = 0;
23 unsigned char screen_start = 0;
24 
25 int w1, h1, lcd_y;
26 
screen_change(uint8_t screen_cnt)27 void screen_change(uint8_t screen_cnt)
28 {
29 //    printf("////////// screen_chage : %d ///////////\n",screen_cnt);
30 	switch (screen_cnt) {
31 	case  0:
32 		FillColor(255, 0, 0, 255, 0, 0, w1, h1);    /*red*/
33 		break;
34 	case  1:
35 		tiles_count--;
36 		FillColor(0, 255, 0, 255, 0, 0, w1, h1);    /*green*/
37 		break;
38 	case  2:
39 		tiles_count--;
40 		FillColor(0, 0, 255, 255, 0, 0, w1, h1);    /*blue*/
41 		break;
42 	case  3:
43 		tiles_count--;
44 		FillColor(0, 0, 0, 255, 0, 0, w1, h1);      /*black*/
45 		break;
46 	case  4:
47 		tiles_count--;
48 		FillColor(255, 255, 255, 255, 0, 0, w1, h1);/*white*/
49 		break;
50 	case  5:
51 		tiles_count--;
52 		ui_print_xy_rgba(0, lcd_y, 0, 255, 0, 255,
53 			            "%s:[%s]\n", PCBA_LCD, PCBA_TESTED);
54 		break;
55 	default:
56 		screen_start = 0;
57 		ui_print_xy_rgba(0, lcd_y, 0, 255, 0, 255,
58 			            "%s:[%s]\n", PCBA_LCD, PCBA_TESTED);
59 		break;
60 	}
61 	/*printf("-----------%s--%s---screen_cnt=%d----------\n",
62 		__FILE__,__FUNCTION__,screen_cnt);*/
63 }
64 
get_key_code(char * key_char)65 unsigned int get_key_code(char *key_char)
66 {
67 	if (!strcmp(key_char, "KEY_VOLUMEDOWN"))
68 		return KEY_VOLUMEDOWN;
69 	else if (!strcmp(key_char, "KEY_VOLUMEUP"))
70 		return KEY_VOLUMEUP;
71 	else if (!strcmp(key_char, "KEY_POWER"))
72 		return KEY_POWER;
73 	else if (!strcmp(key_char, "KEY_F1"))
74 		return KEY_F1;
75 	else if (!strcmp(key_char, "KEY_HOME"))
76 		return KEY_HOME;
77 	else if (!strcmp(key_char, "KEY_BACK"))
78 		return KEY_BACK;
79 	else if (!strcmp(key_char, "KEY_UP"))
80 		return KEY_UP;
81 	else if (!strcmp(key_char, "KEY_DOWN"))
82 		return KEY_DOWN;
83 	else if (!strcmp(key_char, "KEY_LEFT"))
84 		return KEY_LEFT;
85 	else if (!strcmp(key_char, "KEY_RIGHT"))
86 		return KEY_RIGHT;
87 	else if (!strcmp(key_char, "KEY_MENU"))
88 		return KEY_MENU;
89 	else if (!strcmp(key_char, "KEY_ENTER"))
90 		return KEY_ENTER;
91 	else if (!strcmp(key_char, "KEY_ALL"))
92 		return 0;
93 	else {
94 		printf("un supported key:%s\n", key_char);
95 		return 0;
96 	}
97 }
98 
99 /*  key detect
100 *   start the test and change the picture
101 */
screenTest_key_detect(unsigned int code)102 void screenTest_key_detect(unsigned int code)
103 {
104 	if (!screen_start) {
105 		if (code != code_tmp) {
106 			code_tmp = code;
107 			code_cnt = 0;
108 		} else {
109 			if ((!start_key) || (code == start_key)) {
110 				if (++code_cnt >= (key_times-1)) {
111 					picture_change_key = code;
112 					screen_start = 1;
113 					code_cnt = 0;
114 					screen_change(code_cnt);
115 				}
116 			}
117 		}
118 	} else {
119 		if ((code == picture_change_key) || all_key_change) {
120 			code_cnt++;
121 			screen_change(code_cnt);
122 			if (code_cnt >= 5) {
123 				code_cnt = 0;
124 				screen_start = 0;
125 				code_tmp = !code;
126 			}
127 		}
128 	}
129 }
130 
screen_test(void * argv)131 void *screen_test(void *argv)
132 {
133 	struct testcase_info *tc_info = (struct testcase_info *)argv;
134 	char key_name[16];
135 
136 	if (script_fetch("Lcd", "start_key", (int *)key_name, 4) != 0) {
137 		printf("%s: key_times err : %s !!!\r\n",__func__, key_name);
138 		strcpy(key_name, "KEY_ALL");
139 	}
140 	printf("=========== code_cnt is:   %d ==========\n", code_cnt);
141 	start_key = get_key_code(key_name);
142 
143 	if (script_fetch("Lcd", "key_times", &key_times, 1) != 0) {
144 		printf("%s: key_times err : %d !!!\r\n",__func__, key_times);
145 		key_times = 3;
146 	}
147 	if (script_fetch("Lcd", "all_key_change", &all_key_change, 1) != 0) {
148 		printf("%s: all_key_change err : %d !!!\r\n",__func__, all_key_change);
149 		all_key_change = 0;
150 	}
151 
152 	w1 =  gr_fb_width();
153 	h1 =  gr_fb_height();
154 
155 	if (tc_info->y <= 0)
156 		tc_info->y = get_cur_print_y();
157 
158 	ui_print_xy_rgba(0, tc_info->y, 255, 255, 0, 255, \
159 	                "%s: pls press [%s] %d times to start test.\n", \
160 	                PCBA_LCD, key_name, key_times);
161 	lcd_y = tc_info->y;
162 
163 	int x =  gr_fb_width() >> 1;
164 	int y = (gr_fb_height()*2)/3;
165 	int w =  gr_fb_width() >> 1;
166 	int h = gr_fb_height()/3;
167 
168 	FillColor(255, 0, 0, 255, x, y, w/3, h);
169 	FillColor(0, 255, 0, 255, x+w/3, y, w/3, h);
170 	FillColor(0, 0, 255, 255, x+(2*w)/3, y, w/3, h);
171 	sleep(3);
172 
173 	tc_info->result = 0;
174 	return argv;
175 }
176