1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/window/t_calib.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,177 @@
1.4 +// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\window\t_calib.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32test.h>
1.22 +#include <e32twin.h>
1.23 +#include <e32hal.h>
1.24 +#include <e32svr.h>
1.25 +
1.26 +RConsole w;
1.27 +
1.28 +enum TFault
1.29 + {
1.30 + EConnect,
1.31 + EConsole
1.32 + };
1.33 +
1.34 +LOCAL_C void printf(TRefByValue<const TDesC> aFmt,...)
1.35 +//
1.36 +// Print to the console
1.37 +//
1.38 + {
1.39 +
1.40 + VA_LIST list;
1.41 + VA_START(list,aFmt);
1.42 + TBuf<0x100> aBuf;
1.43 + aBuf.AppendFormatList(aFmt,list);
1.44 + TInt r=w.Write(aBuf);
1.45 + __ASSERT_ALWAYS(r==KErrNone,User::Panic(_L("Write-Console"),0));
1.46 + }
1.47 +
1.48 +LOCAL_C void Fault(TFault aFault)
1.49 +//
1.50 +// Panic the program.
1.51 +//
1.52 + {
1.53 +
1.54 + User::Panic(_L("T_CALIB fault"),aFault);
1.55 + }
1.56 +
1.57 +GLDEF_C void DrawBlob(TPoint aPos)
1.58 + {
1.59 + TPoint pos(aPos.iX/8-1,aPos.iY/10-1);
1.60 + w.SetCursorPosAbs(TPoint(0,0));
1.61 + TBuf<0x100> aBuf;
1.62 + aBuf.AppendFormat(_L("(%d,%d) "),aPos.iX,aPos.iY);
1.63 + w.Write(aBuf);
1.64 + if (pos.iX!=0)
1.65 + {
1.66 + w.SetCursorPosAbs(pos);
1.67 + w.Write(_L("*"));
1.68 + }
1.69 + }
1.70 +
1.71 +GLDEF_C void TestBlob()
1.72 +//
1.73 +// Draw blob when digitizer pressed
1.74 +//
1.75 + {
1.76 +
1.77 + FOREVER
1.78 + {
1.79 + TConsoleKey k;
1.80 + w.Read(k);
1.81 + if((TInt)k.Code()==27 && k.Type()==EKeyPress)
1.82 + break;
1.83 + if(k.Type()==EMouseClick)
1.84 + DrawBlob(k.MousePos());
1.85 + };
1.86 + w.ClearScreen();
1.87 + }
1.88 +
1.89 +GLDEF_C TInt E32Main()
1.90 +//
1.91 +// Calibrate digitizer
1.92 +//
1.93 + {
1.94 +
1.95 + TInt r=w.Create();
1.96 + __ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
1.97 + r=w.Init(_L("T_CALIB window"),TSize(KConsFullScreen,KConsFullScreen));
1.98 + __ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
1.99 + r=w.Control(_L("+Maximised"));
1.100 + __ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
1.101 + r=w.Control(_L("+Inform"));
1.102 + __ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
1.103 + r=w.Control(_L("+Pointer"));
1.104 + __ASSERT_ALWAYS(r==KErrNone,Fault(EConsole));
1.105 + TConsoleKey k;
1.106 +
1.107 + TestBlob();
1.108 +
1.109 + printf(_L("Please touch the three points, in the order TL, BL, BR\r\n"));
1.110 +
1.111 + TDigitizerCalibration cal;
1.112 + UserHal::CalibrationPoints(cal);
1.113 +
1.114 + printf(_L("Points are at: (%d,%d), (%d,%d), (%d,%d)\r\n")
1.115 + ,cal.iTl.iX,cal.iTl.iY
1.116 + ,cal.iBl.iX,cal.iBl.iY
1.117 + ,cal.iBr.iX,cal.iBr.iY);
1.118 +
1.119 + DrawBlob(cal.iTl);
1.120 + DrawBlob(cal.iBl);
1.121 + DrawBlob(cal.iBr);
1.122 +
1.123 + // Set digitiser to 'bypass' calibration
1.124 +
1.125 +// UserHal::SetXYInputCalibration(cal);
1.126 +
1.127 + TPoint pos(0,6);
1.128 +
1.129 + w.SetCursorPosAbs(pos);
1.130 +
1.131 + TInt count=0;
1.132 + do
1.133 + {
1.134 + w.Read(k);
1.135 + if(k.Type()==EMouseClick)
1.136 + {
1.137 + TPoint mouse=k.MousePos();
1.138 + printf(_L("You touched point %d,%d\r\n"),mouse.iX,mouse.iY);
1.139 + switch(count++)
1.140 + {
1.141 + case 0:
1.142 + cal.iTl=mouse;
1.143 + break;
1.144 + case 1:
1.145 + cal.iBl=mouse;
1.146 + break;
1.147 + case 2:
1.148 + cal.iBr=mouse;
1.149 + }
1.150 + }
1.151 + } while(count!=3);
1.152 +
1.153 + UserHal::SetXYInputCalibration(cal);
1.154 +
1.155 + printf(_L("Digitizer calibrated! Click away!\r\n"));
1.156 +
1.157 + // Test to validate when invalid calibration input values are supplied.
1.158 +
1.159 + cal.iTl.iX = 10;
1.160 + cal.iTl.iY = 20;
1.161 +
1.162 + cal.iBl.iX = 10;
1.163 + cal.iBl.iY = 20;
1.164 +
1.165 + cal.iBr.iX = 10;
1.166 + cal.iBr.iY = 20;
1.167 +
1.168 + r = UserHal::SetXYInputCalibration(cal);
1.169 +
1.170 + if (r != KErrArgument)
1.171 + // Test failure panic.
1.172 + User::Panic(_L("T_CALIB Test Failure"),84);
1.173 +
1.174 +
1.175 + TestBlob();
1.176 +
1.177 + w.Read(k);
1.178 + return(0);
1.179 + }
1.180 +