0
|
1 |
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\window\t_calib.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <e32test.h>
|
|
19 |
#include <e32twin.h>
|
|
20 |
#include <e32hal.h>
|
|
21 |
#include <e32svr.h>
|
|
22 |
|
|
23 |
RConsole w;
|
|
24 |
|
|
25 |
enum TFault
|
|
26 |
{
|
|
27 |
EConnect,
|
|
28 |
EConsole
|
|
29 |
};
|
|
30 |
|
|
31 |
LOCAL_C void printf(TRefByValue<const TDesC> aFmt,...)
|
|
32 |
//
|
|
33 |
// Print to the console
|
|
34 |
//
|
|
35 |
{
|
|
36 |
|
|
37 |
VA_LIST list;
|
|
38 |
VA_START(list,aFmt);
|
|
39 |
TBuf<0x100> aBuf;
|
|
40 |
aBuf.AppendFormatList(aFmt,list);
|
|
41 |
TInt r=w.Write(aBuf);
|
|
42 |
__ASSERT_ALWAYS(r==KErrNone,User::Panic(_L("Write-Console"),0));
|
|
43 |
}
|
|
44 |
|
|
45 |
LOCAL_C void Fault(TFault aFault)
|
|
46 |
//
|
|
47 |
// Panic the program.
|
|
48 |
//
|
|
49 |
{
|
|
50 |
|
|
51 |
User::Panic(_L("T_CALIB fault"),aFault);
|
|
52 |
}
|
|
53 |
|
|
54 |
GLDEF_C void DrawBlob(TPoint aPos)
|
|
55 |
{
|
|
56 |
TPoint pos(aPos.iX/8-1,aPos.iY/10-1);
|
|
57 |
w.SetCursorPosAbs(TPoint(0,0));
|
|
58 |
TBuf<0x100> aBuf;
|
|
59 |
aBuf.AppendFormat(_L("(%d,%d) "),aPos.iX,aPos.iY);
|
|
60 |
w.Write(aBuf);
|
|
61 |
if (pos.iX!=0)
|
|
62 |
{
|
|
63 |
w.SetCursorPosAbs(pos);
|
|
64 |
w.Write(_L("*"));
|
|
65 |
}
|
|
66 |
}
|
|
67 |
|
|
68 |
GLDEF_C void TestBlob()
|
|
69 |
//
|
|
70 |
// Draw blob when digitizer pressed
|
|
71 |
//
|
|
72 |
{
|
|
73 |
|
|
74 |
FOREVER
|
|
75 |
{
|
|
76 |
TConsoleKey k;
|
|
77 |
w.Read(k);
|
|
78 |
if((TInt)k.Code()==27 && k.Type()==EKeyPress)
|
|
79 |
break;
|
|
80 |
if(k.Type()==EMouseClick)
|
|
81 |
DrawBlob(k.MousePos());
|
|
82 |
};
|
|
83 |
w.ClearScreen();
|
|
84 |
}
|
|
85 |
|
|
86 |
GLDEF_C TInt E32Main()
|
|
87 |
//
|
|
88 |
// Calibrate digitizer
|
|
89 |
//
|
|
90 |
{
|
|
91 |
|
|
92 |
TInt r=w.Create();
|
|
93 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
|
|
94 |
r=w.Init(_L("T_CALIB window"),TSize(KConsFullScreen,KConsFullScreen));
|
|
95 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
|
|
96 |
r=w.Control(_L("+Maximised"));
|
|
97 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
|
|
98 |
r=w.Control(_L("+Inform"));
|
|
99 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
|
|
100 |
r=w.Control(_L("+Pointer"));
|
|
101 |
__ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
|
|
102 |
TConsoleKey k;
|
|
103 |
|
|
104 |
TestBlob();
|
|
105 |
|
|
106 |
printf(_L("Please touch the three points, in the order TL, BL, BR\r\n"));
|
|
107 |
|
|
108 |
TDigitizerCalibration cal;
|
|
109 |
UserHal::CalibrationPoints(cal);
|
|
110 |
|
|
111 |
printf(_L("Points are at: (%d,%d), (%d,%d), (%d,%d)\r\n")
|
|
112 |
,cal.iTl.iX,cal.iTl.iY
|
|
113 |
,cal.iBl.iX,cal.iBl.iY
|
|
114 |
,cal.iBr.iX,cal.iBr.iY);
|
|
115 |
|
|
116 |
DrawBlob(cal.iTl);
|
|
117 |
DrawBlob(cal.iBl);
|
|
118 |
DrawBlob(cal.iBr);
|
|
119 |
|
|
120 |
// Set digitiser to 'bypass' calibration
|
|
121 |
|
|
122 |
// UserHal::SetXYInputCalibration(cal);
|
|
123 |
|
|
124 |
TPoint pos(0,6);
|
|
125 |
|
|
126 |
w.SetCursorPosAbs(pos);
|
|
127 |
|
|
128 |
TInt count=0;
|
|
129 |
do
|
|
130 |
{
|
|
131 |
w.Read(k);
|
|
132 |
if(k.Type()==EMouseClick)
|
|
133 |
{
|
|
134 |
TPoint mouse=k.MousePos();
|
|
135 |
printf(_L("You touched point %d,%d\r\n"),mouse.iX,mouse.iY);
|
|
136 |
switch(count++)
|
|
137 |
{
|
|
138 |
case 0:
|
|
139 |
cal.iTl=mouse;
|
|
140 |
break;
|
|
141 |
case 1:
|
|
142 |
cal.iBl=mouse;
|
|
143 |
break;
|
|
144 |
case 2:
|
|
145 |
cal.iBr=mouse;
|
|
146 |
}
|
|
147 |
}
|
|
148 |
} while(count!=3);
|
|
149 |
|
|
150 |
UserHal::SetXYInputCalibration(cal);
|
|
151 |
|
|
152 |
printf(_L("Digitizer calibrated! Click away!\r\n"));
|
|
153 |
|
|
154 |
// Test to validate when invalid calibration input values are supplied.
|
|
155 |
|
|
156 |
cal.iTl.iX = 10;
|
|
157 |
cal.iTl.iY = 20;
|
|
158 |
|
|
159 |
cal.iBl.iX = 10;
|
|
160 |
cal.iBl.iY = 20;
|
|
161 |
|
|
162 |
cal.iBr.iX = 10;
|
|
163 |
cal.iBr.iY = 20;
|
|
164 |
|
|
165 |
r = UserHal::SetXYInputCalibration(cal);
|
|
166 |
|
|
167 |
if (r != KErrArgument)
|
|
168 |
// Test failure panic.
|
|
169 |
User::Panic(_L("T_CALIB Test Failure"),84);
|
|
170 |
|
|
171 |
|
|
172 |
TestBlob();
|
|
173 |
|
|
174 |
w.Read(k);
|
|
175 |
return(0);
|
|
176 |
}
|
|
177 |
|