-
Notifications
You must be signed in to change notification settings - Fork 4
/
plcm_test.c
executable file
·270 lines (261 loc) · 7.42 KB
/
plcm_test.c
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/*
* Lanner Paralle LCM Driver Test Program
*/
#include <sys/file.h>
#include <stdio.h>
#include <string.h>
#include "plcm_ioctl.h"
int main(int argc, char *argv[])
{
int devfd;
unsigned char LCM_Message1[40] = "Lanner@Taiwan";
unsigned char Ret_Message1[40] = "";
unsigned char LCM_Message2[40] = "2013-11-05";
unsigned char Ret_Message2[40] = "";
unsigned char LCM_Message3[40] = "";
int i = 0;
unsigned char Keypad_Value = 0, Pre_Value = 0, Counter = 0;
unsigned char Keypad_Message[40] = "";
unsigned char Up[] = "Up ";
unsigned char Down[] = "Down ";
unsigned char Left[] = "Left ";
unsigned char Right[] = "Right";
unsigned char detect_press;
unsigned char detect_dir;
int MaxTestTime = 15 * 10; // 30 Sec
printf("Lanner Parallel LCM Test Program\n");
devfd = open("/dev/plcm_drv", O_RDWR);
if(devfd == -1)
{
printf("Can't open /dev/plcm_drv\n");
return -1;
}
printf("IOCTRL Testing...\n");
if(argc == 2)
{
if(strcmp("-stop", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_STOP_THREAD, 0);
printf("plcm_drv thread has been stopped.\n");
close(devfd);
return 0;
}
if(strcmp("-On", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_BACKLIGHT, 1);
sleep(3);
close(devfd);
return 0;
}
if(strcmp("-Off", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_BACKLIGHT, 0);
sleep(3);
close(devfd);
return 0;
}
if(strcmp("-LCM1", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
write(devfd, LCM_Message1, strlen(LCM_Message1));
close(devfd);
return 0;
}
if(strcmp("-LCM2", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, LCM_Message2, strlen(LCM_Message2));
close(devfd);
return 0;
}
if(strcmp("-Keypad", argv[1]) == 0)
{
printf("Keypad Testing....\n");
printf(" You only have 15 second to test it.\n");
printf(" Or press Ctrl+C to exit.\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
do{
Keypad_Value = ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
if(Pre_Value != Keypad_Value)
{
ioctl(devfd, PLCM_IOCTL_CLEARDISPLAY, 0);
ioctl(devfd, PLCM_IOCTL_RETURNHOME, 0);
}
detect_press=(Keypad_Value & 0x40);
detect_dir=(Keypad_Value & 0x28);
switch(detect_dir)
{
case 0x00:
strcpy(Keypad_Message,"Up-");
break;
case 0x20:
strcpy(Keypad_Message,"Left-");
break;
case 0x08:
strcpy(Keypad_Message,"Right-");
break;
case 0x28:
strcpy(Keypad_Message,"Down-");
break;
}
switch(detect_press)
{
case 0x40:
strcat(Keypad_Message,"Press ");
break;
case 0x00:
strcat(Keypad_Message,"Release ");
break;
}
write(devfd, Keypad_Message, strlen(Keypad_Message));
Pre_Value = Keypad_Value;
usleep(100000); // 100 msec
MaxTestTime--;
if(MaxTestTime == 0)
{
printf("Keypad Testing Finished.\n");
break;
}
}while(1);
close(devfd);
return 0;
}
printf("Invalid command.\n");
printf("plcm_test [-stop|-On|-Off|-LCM1|-LCM2|-Keypad]\n");
close(devfd);
return 0;
}
printf(" Display Control - Fill Black Character\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_D, 1);
for(i=0;i<40;i++) LCM_Message3[i] = 0xff;
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
write(devfd, LCM_Message3, 40);
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, LCM_Message3, 40);
sleep(2);
printf(" Backlight Control - Backlight Off\n");
ioctl(devfd, PLCM_IOCTL_BACKLIGHT, 0);
sleep(2);
printf(" Backlight Control - Backlight On\n");
ioctl(devfd, PLCM_IOCTL_BACKLIGHT, 1);
sleep(2);
printf(" Display Control - Display Off\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_D, 0);
sleep(2);
ioctl(devfd, PLCM_IOCTL_CLEARDISPLAY, 0);
ioctl(devfd, PLCM_IOCTL_DISPLAY_D, 1);
ioctl(devfd, PLCM_IOCTL_SHIFT_SC, 0);
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
printf(" Display Control - Cursor Off\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 0);
ioctl(devfd, PLCM_IOCTL_DISPLAY_C, 0);
sprintf(Keypad_Message,"Cursor Off:");
write(devfd, Keypad_Message, strlen(Keypad_Message));
sleep(2);
printf(" Display Control - Cursor On\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_C, 1);
sprintf(Keypad_Message,"Cursor On:");
write(devfd, Keypad_Message, strlen(Keypad_Message));
sleep(2);
printf(" Display Control - Blinking On\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 1);
sprintf(Keypad_Message,"Blinking On:");
write(devfd, Keypad_Message, strlen(Keypad_Message));
sleep(2);
printf(" Display Control - Blinking Off\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 0);
sprintf(Keypad_Message,"Blinking Off:");
write(devfd, Keypad_Message, strlen(Keypad_Message));
sleep(2);
printf("Write and Read Testing...\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
write(devfd, LCM_Message1, strlen(LCM_Message1));
printf(" Write: %s\n", LCM_Message1);
read(devfd, Ret_Message1, 40);
printf(" Read: %s\n", Ret_Message1);
sleep(2);
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, LCM_Message2, strlen(LCM_Message2));
printf(" Write: %s\n", LCM_Message2);
read(devfd, Ret_Message2, 40);
printf(" Read: %s\n", Ret_Message2);
sleep(2);
/* In order to hide the cursor, so pan left one word */
ioctl(devfd, PLCM_IOCTL_SHIFT_SC, 1);
printf("CGRAM Test...\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
sprintf(Keypad_Message," CGRAM Testing:");
write(devfd, Keypad_Message, strlen(Keypad_Message));
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
for(i=0;i<40;i++) LCM_Message3[i] = i%8;
write(devfd, LCM_Message3, sizeof(LCM_Message3));
sleep(5);
Counter=0;
printf("Keypad Testing....\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
sprintf(Keypad_Message," Keypad Testing");
write(devfd, Keypad_Message, strlen(Keypad_Message));
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
strcpy(Keypad_Message," Press the 4 buttons");
write(devfd, Keypad_Message, strlen(Keypad_Message));
ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0); //clear previous keypad status
Pre_Value = ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
printf(" You only have 15 second to test it.\n");
printf(" Or press Ctrl+C to exit.\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
do{
Keypad_Value = ioctl(devfd, PLCM_IOCTL_GET_KEYPAD, 0);
if(Pre_Value != Keypad_Value)
{
detect_press=(Keypad_Value & 0x40);
detect_dir=(Keypad_Value & 0x28);
switch(detect_dir){
case 0x00:
strcpy(Keypad_Message," Up ");
Counter |= 0x10 | (detect_press>>6);
break;
case 0x20:
strcpy(Keypad_Message," Left ");
Counter |= 0x20 | (detect_press>>5);
break;
case 0x08:
strcpy(Keypad_Message," Right ");
Counter |= 0x40 | (detect_press>>4);
break;
case 0x28:
strcpy(Keypad_Message," Down ");
Counter |= 0x80 | (detect_press>>3);
break;
}
switch(detect_press){
case 0x40:
strcat(Keypad_Message,"Press");
break;
case 0x00:
strcat(Keypad_Message,"Release");
break;
}
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, Keypad_Message, strlen(Keypad_Message));
Pre_Value = Keypad_Value;
}
if((MaxTestTime%10) == 0){
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
sprintf(Keypad_Message," Keypad Testing....%02d",
MaxTestTime/10);
write(devfd, Keypad_Message, strlen(Keypad_Message));
}
MaxTestTime--;
if(MaxTestTime == 0 || Counter==0xff)
{
printf("Keypad Testing Finished.\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
sprintf(Keypad_Message," Keypad Test Finished");
write(devfd, Keypad_Message, strlen(Keypad_Message));
break;
}
usleep(100000); // 100 msec
}while(1);
close(devfd);
return 0;
}