-
Notifications
You must be signed in to change notification settings - Fork 1
/
plcm_test.c
233 lines (230 loc) · 5.56 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
/*
* 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] = "2010-09-07";
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";
int MaxTestTime = 15 * 10; // 30 Sec
for(i = 0; i < 5; i++)
{
LCM_Message3[i*8 + 0] = 0;
LCM_Message3[i*8 + 1] = 1;
LCM_Message3[i*8 + 2] = 2;
LCM_Message3[i*8 + 3] = 3;
LCM_Message3[i*8 + 4] = 4;
LCM_Message3[i*8 + 5] = 5;
LCM_Message3[i*8 + 6] = 6;
LCM_Message3[i*8 + 7] = 7;
}
iopl(3);
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, sizeof(LCM_Message1));
close(devfd);
return 0;
}
if(strcmp("-LCM2", argv[1]) == 0)
{
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, LCM_Message2, sizeof(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);
printf("receive value is %x\n",Keypad_Value);
/*if(Pre_Value != Keypad_Value)
{
ioctl(devfd, PLCM_IOCTL_CLEARDISPLAY, 0);
ioctl(devfd, PLCM_IOCTL_RETURNHOME, 0);
Counter = 0;
}
else
{
Counter++;
}
switch(Keypad_Value)
{
case 0xC7:
strcpy(Keypad_Message, Up);
break;
case 0xE7:
strcpy(Keypad_Message, Left);
break;
case 0xEF:
strcpy(Keypad_Message, Right);
break;
case 0xCF:
strcpy(Keypad_Message, Down);
break;
}
if(Counter > 5)
{
write(devfd, Keypad_Message, 40);
}
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(" Backlight Control - Off\n");
ioctl(devfd, PLCM_IOCTL_BACKLIGHT, 0);
sleep(2);
printf(" Backlight Control - 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);
printf(" Display Control - Display On\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_D, 1);
sleep(2);
printf(" Display Control - Cursor Off\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_C, 0);
sleep(2);
printf(" Display Control - Cursor On\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_C, 1);
sleep(2);
printf(" Display Control - Blinking Off\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 0);
sleep(2);
printf(" Display Control - Blinking On\n");
ioctl(devfd, PLCM_IOCTL_DISPLAY_B, 1);
sleep(2);
printf("Write and Read Testing...\n");
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
write(devfd, LCM_Message1, sizeof(LCM_Message1));
printf(" Write: %s\n", LCM_Message1);
sleep(2);
#if 0
read(devfd, Ret_Message1, sizeof(Ret_Message1));
printf(" Read: %s\n", Ret_Message1);
sleep(2);
#endif
ioctl(devfd, PLCM_IOCTL_SET_LINE, 2);
write(devfd, LCM_Message2, sizeof(LCM_Message2));
printf(" Write: %s\n", LCM_Message2);
sleep(2);
#if 0
read(devfd, Ret_Message2, sizeof(Ret_Message2));
printf(" Read: %s\n", Ret_Message2);
sleep(2);
ioctl(devfd, PLCM_IOCTL_SET_LINE, 1);
printf("CGRAM Test...\n");
write(devfd, LCM_Message3, sizeof(LCM_Message3));
sleep(5);
#endif
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);
printf("receive value is %x\n",Keypad_Value);
/*if(Pre_Value != Keypad_Value)
{
ioctl(devfd, PLCM_IOCTL_CLEARDISPLAY, 0);
ioctl(devfd, PLCM_IOCTL_RETURNHOME, 0);
Counter = 0;
}
else
{
Counter++;
}
switch(Keypad_Value)
{
case 0xC7:
strcpy(Keypad_Message, Up);
break;
case 0xE7:
strcpy(Keypad_Message, Left);
break;
case 0xEF:
strcpy(Keypad_Message, Right);
break;
case 0xCF:
strcpy(Keypad_Message, Down);
break;
}
if(Counter > 5)
{
write(devfd, Keypad_Message, 40);
}
Pre_Value = Keypad_Value;*/
usleep(100000); // 100 msec
MaxTestTime--;
if(MaxTestTime == 0)
{
printf("Keypad Testing Finished.\n");
break;
}
}while(1);
close(devfd);
return 0;
}