author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 21 Jun 2010 17:12:14 +0300 | |
branch | RCL_3 |
changeset 39 | 2bb754abd467 |
parent 19 | 4a8fed1c0ef6 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2004-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 |
// template\Template_Variant\Specific\xyin.cpp |
|
15 |
// Implementation of a digitiser (touch-screen) driver. |
|
16 |
// This code assumes that an interrupt is generated on pen-down and pen-up events. |
|
17 |
// This file is part of the Template Base port |
|
18 |
// We use this driver to exemplify the usage of Resource Management for shared resources, Peripheral "Sleep" |
|
19 |
// and detection and notification of Wakeup events |
|
20 |
// |
|
21 |
// |
|
22 |
||
23 |
||
24 |
#include <assp.h> |
|
25 |
#include <template_assp.h> |
|
26 |
#include <videodriver.h> |
|
27 |
#include "mconf.h" |
|
28 |
#include <drivers/xyin.h> |
|
29 |
#include "template_power.h" |
|
30 |
||
31 |
||
32 |
||
33 |
||
34 |
// |
|
35 |
// TO DO: (mandatory) |
|
36 |
// |
|
37 |
// Define the following constants that describe the digitiser position & dimensions |
|
38 |
// This is only example code... you need to modify it for your hardware |
|
39 |
||
40 |
// digitiser origin & size in pixels |
|
41 |
const TUint KConfigXyOffsetX = 0; // digitiser origin - same as display area |
|
42 |
const TUint KConfigXyOffsetY = 0; |
|
43 |
const TUint KConfigXyWidth = 640; // 640 pixels per line |
|
44 |
const TUint KConfigXyHeight = 480; // 480 lines per panel |
|
45 |
||
46 |
// digitiser dimensions in digitiser co-ordinates |
|
47 |
const TInt KConfigXyBitsX = 12; |
|
48 |
const TInt KConfigXyBitsY = 12; |
|
49 |
const TInt KConfigXySpreadX = 1 << KConfigXyBitsX; // maximum valid X spread |
|
50 |
const TInt KConfigXySpreadY = 1 << KConfigXyBitsY; // maximum valid Y spread |
|
51 |
const TInt KConfigXyMinX = 0; // minimum valid X value |
|
52 |
const TInt KConfigXyMinY = 0; // minimum valid Y value |
|
53 |
const TInt KConfigXyMaxX = KConfigXySpreadX - 1; // maximum valid X value |
|
54 |
const TInt KConfigXyMaxY = KConfigXySpreadY - 1; // maximum valid Y value |
|
55 |
||
56 |
||
57 |
// Define a 2x2 matrix and two constants Tx and Ty to convert digitiser co-ordinates |
|
58 |
// to pixels such that |
|
59 |
// |
|
60 |
// (X<<16 Y<<16) = (x y) x (R11 R12) + (Tx Ty) |
|
61 |
// (R21 R22) |
|
62 |
// or : |
|
63 |
// |
|
64 |
// X = (x*R11 + y*R21 + TX) >> 16; |
|
65 |
// Y = (x*R12 + y*R22 + TY) >> 16; |
|
66 |
||
67 |
// |
|
68 |
// where x,y are digitiser coordinates, Tx,Ty are constant offsets and X,Y are screen |
|
69 |
// coordinates. Left shifting by 16 bits is used so as not to lose precision. |
|
70 |
// |
|
71 |
// These are default values to be used before calibration has taken place |
|
72 |
// These are best set by observation. |
|
73 |
// The example values given below are for a digitiser whose origin is at bottom left |
|
74 |
// (the screen origin is at top left) |
|
75 |
const TInt KConfigXyR11 = (KConfigXyWidth << 16) / KConfigXySpreadX; // 10240 |
|
76 |
const TInt KConfigXyR12 = 0; |
|
77 |
const TInt KConfigXyR21 = 0; |
|
78 |
const TInt KConfigXyR22 = - ((KConfigXyHeight << 16) / KConfigXySpreadY); // -7680 |
|
79 |
const TInt KConfigXyTx = 0; |
|
80 |
const TInt KConfigXyTy = (KConfigXyHeight << 16) / KConfigXySpreadY; |
|
81 |
||
82 |
// |
|
83 |
// TO DO: (optional) |
|
84 |
// |
|
85 |
// Define the following constants that describe the digitiser behaviour |
|
86 |
// This is only example code... you need to modify it for your hardware |
|
87 |
||
88 |
// After taking a sample, wait for the specified number of nano-kernel ticks (normally 1 ms) |
|
89 |
// before taking the next sample |
|
90 |
const TInt KInterSampleTime = 1; |
|
91 |
||
92 |
// After a group of samples has been processed by the DDigitiser::ProcessRawSample() DFC, |
|
93 |
// wait for the specified number of nano-kernel ticks before taking the next sample |
|
94 |
const TInt KInterGroupTime = 1; |
|
95 |
||
96 |
// After a pen-down interrupt, |
|
97 |
// wait for the specified number of nano-kernel ticks before taking the next sample |
|
98 |
const TInt KPenDownDelayTime = 2; |
|
99 |
||
100 |
// If powering up the device with the pen down, |
|
101 |
// wait for the specified number of nano-kernel ticks before taking the next sample |
|
102 |
const TInt KPenUpPollTime = 30; |
|
103 |
||
104 |
// After a pen-up interrupt, |
|
105 |
// wait for the specified number of nano-kernel ticks before calling PenUp() |
|
106 |
const TInt KPenUpDebounceTime = 10; |
|
107 |
||
108 |
// number of samples to discard on pen-down |
|
109 |
const TInt KConfigXyPenDownDiscard = 1; |
|
110 |
||
111 |
// number of samples to discard on pen-up |
|
112 |
const TInt KConfigXyPenUpDiscard = 1; |
|
113 |
||
114 |
// offset in pixels to cause movement in X direction |
|
115 |
const TInt KConfigXyAccThresholdX = 12; |
|
116 |
||
117 |
// offset in pixels to cause movement in Y direction |
|
118 |
const TInt KConfigXyAccThresholdY = 12; |
|
119 |
||
120 |
// number of samples to average - MUST be <= KMaxXYSamples |
|
121 |
const TInt KConfigXyNumXYSamples = 2; |
|
122 |
||
123 |
// disregard extremal values in each 4-sample group |
|
124 |
const TBool KConfigXyDisregardMinMax= EFalse; |
|
125 |
||
126 |
||
127 |
||
128 |
// obsolete constants : |
|
129 |
const TInt KConfigXyDriveXRise = 0; |
|
130 |
const TInt KConfigXyDriveYRise = 0; |
|
131 |
const TInt KConfigXyMaxJumpX = 0; |
|
132 |
const TInt KConfigXyMaxJumpY = 0; |
|
133 |
||
134 |
||
135 |
||
136 |
/****************************************************** |
|
137 |
* Main Digitiser Class |
|
138 |
******************************************************/ |
|
139 |
||
140 |
// |
|
141 |
// TO DO: (optional) |
|
142 |
// |
|
143 |
// Add any private functions and data you require |
|
144 |
// |
|
145 |
NONSHARABLE_CLASS(DTemplateDigitiser) : public DDigitiser |
|
146 |
{ |
|
147 |
public: |
|
148 |
enum TState |
|
149 |
{ |
|
150 |
E_HW_PowerUp, |
|
151 |
E_HW_PenUpDebounce, |
|
152 |
E_HW_CollectSample |
|
153 |
}; |
|
154 |
||
155 |
public: |
|
156 |
// from DDigitiser - initialisation |
|
157 |
DTemplateDigitiser(); |
|
158 |
virtual TInt DoCreate(); |
|
159 |
void SetDefaultConfig(); |
|
160 |
||
161 |
// from DDigitiser - signals to hardware-dependent code |
|
162 |
virtual void WaitForPenDown(); |
|
163 |
virtual void WaitForPenUp(); |
|
164 |
virtual void WaitForPenUpDebounce(); |
|
165 |
virtual void DigitiserOn(); |
|
166 |
virtual void DigitiserOff(); |
|
167 |
virtual void FilterPenMove(const TPoint& aPoint); |
|
168 |
virtual void ResetPenMoveFilter(); |
|
169 |
||
170 |
// from DDigitiser - machine-configuration related things |
|
171 |
virtual TInt DigitiserToScreen(const TPoint& aDigitiserPoint, TPoint& aScreenPoint); |
|
172 |
virtual void ScreenToDigitiser(TInt& aX, TInt& aY); |
|
173 |
virtual TInt SetXYInputCalibration(const TDigitizerCalibration& aCalibration); |
|
174 |
virtual TInt CalibrationPoints(TDigitizerCalibration& aCalibration); |
|
175 |
virtual TInt SaveXYInputCalibration(); |
|
176 |
virtual TInt RestoreXYInputCalibration(TDigitizerCalibrationType aType); |
|
177 |
virtual void DigitiserInfo(TDigitiserInfoV01& aInfo); |
|
178 |
||
179 |
// from DPowerHandler |
|
180 |
virtual void PowerDown(TPowerState); |
|
181 |
virtual void PowerUp(); |
|
182 |
||
183 |
public: |
|
184 |
// implementation |
|
185 |
void TakeSample(); |
|
186 |
void PenInterrupt(); |
|
187 |
void DigitiserPowerUp(); |
|
188 |
void PowerUpDfc(); |
|
189 |
||
190 |
public: |
|
191 |
NTimer iTimer; |
|
192 |
NTimer iTimerInt; |
|
193 |
TDfc iTakeReadingDfc; |
|
194 |
TDfc iPowerDownDfc; |
|
195 |
TDfc iPowerUpDfc; |
|
196 |
TInt iSamplesCount; |
|
197 |
TState iState; |
|
198 |
TUint8 iPoweringDown; |
|
199 |
||
200 |
TSize iScreenSize; |
|
201 |
TActualMachineConfig& iMachineConfig; |
|
202 |
}; |
|
203 |
||
204 |
/****************************************************** |
|
205 |
* Digitiser main code |
|
206 |
******************************************************/ |
|
207 |
/** |
|
208 |
Sample timer callback |
|
209 |
Schedules a DFC to take a sample |
|
210 |
||
211 |
@param aPtr a pointer to DTemplateDigitiser |
|
212 |
*/ |
|
213 |
LOCAL_C void timerExpired(TAny* aPtr) |
|
214 |
{ |
|
215 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
216 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("T")); |
|
217 |
pD->iTakeReadingDfc.Add(); |
|
218 |
} |
|
219 |
||
220 |
/** |
|
221 |
Debounce timer callback |
|
222 |
schedules a DFC to process a pen-down interrupt |
|
223 |
||
224 |
@param aPtr a pointer to DTemplateDigitiser |
|
225 |
*/ |
|
226 |
LOCAL_C void timerIntExpired(TAny* aPtr) |
|
227 |
{ |
|
228 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
229 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("TI")); |
|
230 |
// clear xy interrupt -> re-triggers the interrupt mechanism to catch the next IRQ |
|
231 |
||
232 |
// TO DO: (mandatory) |
|
233 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
234 |
// |
|
235 |
||
236 |
pD->iTakeReadingDfc.Add(); |
|
237 |
} |
|
238 |
||
239 |
/** |
|
240 |
Pen-up/down interrupt handler |
|
241 |
||
242 |
@param aPtr a pointer to DTemplateDigitiser |
|
243 |
*/ |
|
244 |
LOCAL_C void penInterrupt(TAny* aPtr) |
|
245 |
{ |
|
246 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
247 |
pD->PenInterrupt(); |
|
248 |
} |
|
249 |
||
250 |
/** |
|
251 |
DFC for taking a sample |
|
252 |
||
253 |
@param aPtr a pointer to DTemplateDigitiser |
|
254 |
*/ |
|
255 |
LOCAL_C void takeReading(TAny* aPtr) |
|
256 |
{ |
|
257 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
258 |
pD->TakeSample(); |
|
259 |
} |
|
260 |
||
261 |
/** |
|
262 |
DFC for powering down the device |
|
263 |
||
264 |
@param aPtr a pointer to DTemplateDigitiser |
|
265 |
*/ |
|
266 |
LOCAL_C void powerDownDfc(TAny* aPtr) |
|
267 |
{ |
|
268 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
269 |
pD->DigitiserOff(); |
|
270 |
} |
|
271 |
||
272 |
/** |
|
273 |
DFC for powering up the device |
|
274 |
||
275 |
@param aPtr a pointer to DTemplateDigitiser |
|
276 |
*/ |
|
277 |
LOCAL_C void powerUpDfc(TAny* aPtr) |
|
278 |
{ |
|
279 |
DTemplateDigitiser* pD=(DTemplateDigitiser*)aPtr; |
|
280 |
pD->PowerUpDfc(); |
|
281 |
} |
|
282 |
||
283 |
/** |
|
284 |
Creates a new instance of DDigitiser. |
|
285 |
Called by extension entry point (PIL) to create a DDigitiser-derived object. |
|
286 |
||
287 |
@return a pointer to a DTemplateDigitiser object |
|
288 |
*/ |
|
289 |
DDigitiser* DDigitiser::New() |
|
290 |
{ |
|
291 |
return new DTemplateDigitiser; |
|
292 |
} |
|
293 |
||
294 |
/** |
|
295 |
Default constructor |
|
296 |
*/ |
|
297 |
DTemplateDigitiser::DTemplateDigitiser() : |
|
298 |
iTimer(timerExpired,this), |
|
299 |
iTimerInt(timerIntExpired,this), |
|
300 |
iTakeReadingDfc(takeReading,this,5), |
|
301 |
iPowerDownDfc(powerDownDfc,this,5), |
|
302 |
iPowerUpDfc(powerUpDfc,this,5), |
|
303 |
iMachineConfig(TheActualMachineConfig()) |
|
304 |
{ |
|
305 |
iDfcQ = Kern::DfcQue0(); |
|
306 |
iTakeReadingDfc.SetDfcQ(iDfcQ); |
|
307 |
iPowerDownDfc.SetDfcQ(iDfcQ); |
|
308 |
iPowerUpDfc.SetDfcQ(iDfcQ); |
|
309 |
} |
|
310 |
||
311 |
/** |
|
312 |
Perform hardware-dependent initialisation |
|
313 |
||
314 |
Called by platform independent layer |
|
315 |
*/ |
|
316 |
TInt DTemplateDigitiser::DoCreate() |
|
317 |
{ |
|
318 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("DTemplateDigitiser::DoCreate")); |
|
319 |
||
320 |
if (Kern::ColdStart()) |
|
321 |
{ |
|
322 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("Resetting digitiser calibration")); |
|
323 |
||
324 |
// Emergency digitiser calibration values |
|
325 |
iMachineConfig.iCalibration.iR11 = KConfigXyR11; |
|
326 |
iMachineConfig.iCalibration.iR12 = KConfigXyR12; |
|
327 |
iMachineConfig.iCalibration.iR21 = KConfigXyR21; |
|
328 |
iMachineConfig.iCalibration.iR22 = KConfigXyR22; |
|
329 |
iMachineConfig.iCalibration.iTx = KConfigXyTx; |
|
330 |
iMachineConfig.iCalibration.iTy = KConfigXyTy; |
|
331 |
} |
|
332 |
||
333 |
// register power handler |
|
334 |
Add(); |
|
335 |
DigitiserPowerUp(); |
|
336 |
||
337 |
// bind to the pen-up/down interrupt |
|
338 |
TInt r=Interrupt::Bind(KIntIdDigitiser, penInterrupt, this); |
|
339 |
if (r!=KErrNone) |
|
340 |
return r; |
|
341 |
||
342 |
// set up the default configuration |
|
343 |
SetDefaultConfig(); |
|
344 |
||
345 |
return r; |
|
346 |
} |
|
347 |
||
348 |
/** |
|
349 |
Initialise the DDigitiser::iCfg structure |
|
350 |
*/ |
|
351 |
void DTemplateDigitiser::SetDefaultConfig() |
|
352 |
{ |
|
353 |
iCfg.iPenDownDiscard = KConfigXyPenDownDiscard; // number of samples to discard on pen-down |
|
354 |
iCfg.iPenUpDiscard = KConfigXyPenUpDiscard; // number of samples to discard on pen-up |
|
355 |
iCfg.iDriveXRise = KConfigXyDriveXRise; // number of milliseconds to wait when driving horizontal edges |
|
356 |
iCfg.iDriveYRise = KConfigXyDriveYRise; // number of milliseconds to wait when driving vertical edges |
|
357 |
iCfg.iMinX = KConfigXyMinX; // minimum valid X value |
|
358 |
iCfg.iMaxX = KConfigXyMaxX; // maximum valid X value |
|
359 |
iCfg.iSpreadX = KConfigXySpreadX; // maximum valid X spread |
|
360 |
iCfg.iMinY = KConfigXyMinY; // minimum valid Y value |
|
361 |
iCfg.iMaxY = KConfigXyMaxY; // maximum valid Y value |
|
362 |
iCfg.iSpreadY = KConfigXySpreadY; // maximum valid Y spread |
|
363 |
iCfg.iMaxJumpX = KConfigXyMaxJumpX; // maximum X movement per sample (pixels) |
|
364 |
iCfg.iMaxJumpY = KConfigXyMaxJumpY; // maximum Y movement per sample (pixels) |
|
365 |
iCfg.iAccThresholdX = KConfigXyAccThresholdX; // offset in pixels to cause movement in X direction |
|
366 |
iCfg.iAccThresholdY = KConfigXyAccThresholdY; // offset in pixels to cause movement in Y direction |
|
367 |
iCfg.iNumXYSamples = KConfigXyNumXYSamples; // number of samples to average |
|
368 |
iCfg.iDisregardMinMax = KConfigXyDisregardMinMax; // disregard extremal values in each 4-sample group |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
Takes a sample from the digitiser. |
|
373 |
Called in the context of a DFC thread. |
|
374 |
*/ |
|
375 |
void DTemplateDigitiser::TakeSample() |
|
376 |
{ |
|
377 |
TTemplatePowerController::WakeupEvent(); // notify of pendown (wakeup event) and let the power controller sort |
|
378 |
// out if it needs propagation |
|
379 |
||
380 |
TBool penDown = EFalse; |
|
381 |
||
382 |
// TO DO: (mandatory) |
|
383 |
// Read from appropriate hardware register to determine whether digitiser panel is being touched |
|
384 |
// Set penDown to ETrue if touched or EFalse if not touched. |
|
385 |
// |
|
386 |
||
387 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("TS: S%d PD%d Sp%d", (TInt)iState, penDown?1:0, iSamplesCount)); |
|
388 |
||
389 |
if (iState==E_HW_PowerUp) |
|
390 |
{ |
|
391 |
// waiting for pen to go up after switch on due to pen down or through the HAL |
|
392 |
// coverity[dead_error_condition] |
|
393 |
// The next line should be reachable when this template file is edited for use |
|
394 |
if (!penDown) // pen has gone up -> transition to new state |
|
395 |
{ |
|
396 |
iState=E_HW_CollectSample; |
|
397 |
iSamplesCount=0; // reset sample buffer |
|
398 |
||
399 |
// TO DO: (mandatory) |
|
400 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
401 |
// |
|
402 |
||
403 |
// TO DO: (mandatory) |
|
404 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
405 |
// to detect when the digitizer panel is touched |
|
406 |
// |
|
407 |
||
408 |
Interrupt::Enable(KIntIdDigitiser); // enable pen-down interrupt |
|
409 |
||
410 |
// TO DO: (mandatory) |
|
411 |
// Write to the appropriate hardware register to enable the digitiser interrupt |
|
412 |
// |
|
413 |
||
414 |
} |
|
415 |
else // pen is still down, wait a bit longer in this state |
|
416 |
{ |
|
417 |
iTimer.OneShot(KPenUpPollTime); |
|
418 |
} |
|
419 |
return; |
|
420 |
} |
|
421 |
||
422 |
if (!penDown) |
|
423 |
{ |
|
424 |
if (iState==E_HW_PenUpDebounce) |
|
425 |
{ |
|
426 |
iState=E_HW_CollectSample; // back to initial state, no samples collected |
|
427 |
iSamplesCount=0; // reset sample buffer |
|
428 |
// Need to lock the kernel to simulate ISR context and thus defer preemption, |
|
429 |
// since PenUp() expects an ISR context and calls TDfc::Add(). |
|
430 |
NKern::Lock(); |
|
431 |
PenUp(); // adds DFC |
|
432 |
NKern::Unlock(); |
|
433 |
} |
|
434 |
else // iState=E_HW_CollectSample |
|
435 |
{ |
|
436 |
iState=E_HW_PenUpDebounce; |
|
437 |
iTimer.OneShot(KPenUpDebounceTime); // wait a bit to make sure pen still up |
|
438 |
} |
|
439 |
return; |
|
440 |
} |
|
441 |
else if (iState==E_HW_PenUpDebounce) // pen down |
|
442 |
{ |
|
443 |
// false alarm - pen is down again |
|
444 |
iState=E_HW_CollectSample; // take a new set of samples |
|
445 |
iSamplesCount=0; // reset sample buffer |
|
446 |
} |
|
447 |
// default: pen down and iState=E_HW_CollectSample |
|
448 |
||
449 |
// TO DO: (mandatory) |
|
450 |
// Read from appropriate hardware register to get the current digitiser coordinates |
|
451 |
// of the point that is being touched. Set aResults accordingly. |
|
452 |
// This is only example code... you need to modify it for your hardware |
|
453 |
// |
|
454 |
TPoint aResults; |
|
455 |
||
456 |
// X axis |
|
457 |
iX[iSamplesCount] = aResults.iX; |
|
458 |
// Y axis |
|
459 |
iY[iSamplesCount] = aResults.iY; |
|
460 |
||
461 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("Raw: X=%d Y=%d",iX[iSamplesCount],iY[iSamplesCount])); |
|
462 |
||
463 |
// Put the hardware back into pen-detect mode |
|
464 |
||
465 |
// TO DO: (mandatory) |
|
466 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
467 |
// to detect when the digitizer panel is touched |
|
468 |
// |
|
469 |
||
470 |
// count samples collected - if it's less than minimum, |
|
471 |
// schedule the reading of another sample |
|
472 |
if (++iSamplesCount < iCfg.iNumXYSamples) // iX[] and iY[] are 4 levels deep in xyin.h... |
|
473 |
{ |
|
474 |
if(KInterSampleTime > 0) // need to check this config param as it might be zero! |
|
475 |
iTimer.OneShot(KInterSampleTime); // haven't got a complete group yet, so queue timer to sample again |
|
476 |
else |
|
477 |
iTakeReadingDfc.Enque(); |
|
478 |
return; |
|
479 |
} |
|
480 |
||
481 |
// Have a complete group of samples so pass up to processing layer (PIL) |
|
482 |
||
483 |
// Need to lock the kernel to simulate ISR context and thus defer preemption, |
|
484 |
// since RawSampleValid() expects an ISR context and calls TDfc::Add(). |
|
485 |
NKern::Lock(); |
|
486 |
RawSampleValid(); // adds DFC |
|
487 |
NKern::Unlock(); |
|
488 |
} |
|
489 |
||
490 |
/** |
|
491 |
Request for an interrupt to be generated when the pen is next down |
|
492 |
Called by PIL at startup or when pen leaves digitiser after pen-up event issued |
|
493 |
*/ |
|
494 |
void DTemplateDigitiser::WaitForPenDown() |
|
495 |
{ |
|
496 |
// Called at startup or when pen leaves digitiser after pen-up event issued |
|
497 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("WD: PowerDownMask %x",iPoweringDown)); |
|
498 |
if (iPoweringDown) |
|
499 |
{ |
|
500 |
// powering down |
|
501 |
||
502 |
// TO DO: (mandatory) |
|
503 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
504 |
// to detect when the digitizer panel is touched and wakes up the system if in standby |
|
505 |
// |
|
506 |
||
507 |
// |
|
508 |
// TO DO: (optional) |
|
509 |
// |
|
510 |
// Relinquish request on power resources |
|
511 |
// This will place the peripheral hardware in a low power "Sleep" mode which is Interrupt detection capable |
|
512 |
// EXAMPLE ONLY |
|
513 |
// |
|
514 |
TemplateResourceManager* aManager = TTemplatePowerController::ResourceManager(); |
|
515 |
aManager -> ModifyToLevel(TemplateResourceManager::AsynchMlResourceUsedByXOnly, 50 /* a percentage */); |
|
516 |
aManager -> SharedBResource1() -> Release(); |
|
517 |
||
518 |
iPoweringDown = EFalse; |
|
519 |
PowerDownDone(); |
|
520 |
} |
|
521 |
else |
|
522 |
{ |
|
523 |
||
524 |
// TO DO: (mandatory) |
|
525 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
526 |
// |
|
527 |
||
528 |
// TO DO: (mandatory) |
|
529 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
530 |
// to detect when the digitizer panel is touched |
|
531 |
// |
|
532 |
||
533 |
if ((iTimer.iState == NTimer::EIdle) && (iTimerInt.iState == NTimer::EIdle)) |
|
534 |
Interrupt::Enable(KIntIdDigitiser); // enable pen-down interrupt |
|
535 |
} |
|
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
Called by PIL after it has processed a group of raw samples while pen is down. |
|
540 |
Used to indicate that the iX, iY buffers may be re-used |
|
541 |
*/ |
|
542 |
void DTemplateDigitiser::WaitForPenUp() |
|
543 |
{ |
|
544 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("WU")); |
|
545 |
iState = E_HW_CollectSample; |
|
546 |
iSamplesCount = 0; // reset sample buffer |
|
547 |
if(KInterGroupTime > 0) // need to check this config param as it might be zero! |
|
548 |
iTimer.OneShot(KInterGroupTime); |
|
549 |
else |
|
550 |
iTakeReadingDfc.Enque(); |
|
551 |
} |
|
552 |
||
553 |
/** |
|
554 |
Called by PIL if the group of samples collected is not good enough |
|
555 |
Used to indicate that the iX, iY buffers may be re-used |
|
556 |
*/ |
|
557 |
void DTemplateDigitiser::WaitForPenUpDebounce() |
|
558 |
{ |
|
559 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("WUDB")); |
|
560 |
iState = E_HW_CollectSample; |
|
561 |
iSamplesCount = 0; // reset sample buffer |
|
562 |
if(KInterGroupTime > 0) // need to check this config param as it might be zero! |
|
563 |
iTimer.OneShot(KInterGroupTime); |
|
564 |
else |
|
565 |
iTakeReadingDfc.Enque(); |
|
566 |
} |
|
567 |
||
568 |
/** |
|
569 |
Pen up/down interrupt service routine (ISR) |
|
570 |
*/ |
|
571 |
void DTemplateDigitiser::PenInterrupt() |
|
572 |
{ |
|
573 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("I")); |
|
574 |
||
575 |
||
576 |
Interrupt::Clear(KIntIdDigitiser); // should already have been cleared |
|
577 |
||
578 |
// TO DO: (mandatory) |
|
579 |
// Read from appropriate hardware register to determine whether digitiser panel is being touched |
|
580 |
// Set penDown to ETrue if touched or EFalse if not touched. |
|
581 |
// This is only example code... you need to modify it for your hardware |
|
582 |
TBool penDown = EFalse; |
|
583 |
||
584 |
// coverity[dead_error_condition] |
|
585 |
if(!penDown) // pen up |
|
586 |
{ |
|
587 |
||
588 |
// TO DO: (mandatory) |
|
589 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
590 |
// |
|
591 |
||
592 |
// TO DO: (mandatory) |
|
593 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
594 |
// to detect when the digitizer panel is touched |
|
595 |
// |
|
596 |
||
597 |
return; // ... and exit! |
|
598 |
} |
|
599 |
||
600 |
Interrupt::Disable(KIntIdDigitiser); // do NOT disable the capability to generate interrupts at the source |
|
601 |
||
19
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
602 |
// Add the timing of pen interrupts as entropy data for the RNG |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
Interrupt::AddTimingEntropy(); |
4a8fed1c0ef6
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
|
0 | 605 |
if (KPenDownDelayTime>0) // need to check this config param as it might be zero! |
606 |
iTimerInt.OneShot(KPenDownDelayTime); // start a debounce timer which will queue a DFC to process the interrupt |
|
607 |
else |
|
608 |
{ |
|
609 |
||
610 |
// TO DO: (mandatory) |
|
611 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
612 |
// This will re-trigger the interrupt mechanism to catch the next interrupt... |
|
613 |
// |
|
614 |
||
615 |
iTakeReadingDfc.Add(); |
|
616 |
} |
|
617 |
} |
|
618 |
||
619 |
/** |
|
620 |
DPowerHandler pure virtual |
|
621 |
*/ |
|
622 |
void DTemplateDigitiser::PowerUp() |
|
623 |
{ |
|
624 |
iPowerUpDfc.Enque(); // queue a DFC in this driver's context |
|
625 |
} |
|
626 |
||
627 |
/** |
|
628 |
Called by power up DFC |
|
629 |
*/ |
|
630 |
void DTemplateDigitiser::PowerUpDfc() |
|
631 |
{ |
|
632 |
__KTRACE_OPT(KPOWER, Kern::Printf("DTemplateDigitiser::PowerUpDfc()")); |
|
633 |
DigitiserOn(); |
|
634 |
PowerUpDone(); // must be called from a different thread than PowerUp() |
|
635 |
} |
|
636 |
||
637 |
/** |
|
638 |
Turn the digitiser on |
|
639 |
May be called as a result of a power transition or from the HAL |
|
640 |
If called from HAL, then the digitiser may be already be on (iPointerOn == ETrue) |
|
641 |
*/ |
|
642 |
void DTemplateDigitiser::DigitiserOn() |
|
643 |
{ |
|
644 |
__KTRACE_OPT(KPOWER,Kern::Printf("DTemplateDigitiser::DigitiserOn() iPointerOn=%d", iPointerOn)); |
|
645 |
||
646 |
if (!iPointerOn) // may have been powered up already |
|
647 |
DigitiserPowerUp(); |
|
648 |
} |
|
649 |
||
650 |
/** |
|
651 |
Power-up the digitiser. Assumes digitiser is off. |
|
652 |
*/ |
|
653 |
void DTemplateDigitiser::DigitiserPowerUp() |
|
654 |
{ |
|
655 |
__KTRACE_OPT(KPOWER, Kern::Printf("DigitiserPowerUp")); |
|
656 |
iPointerOn = ETrue; // now turned on |
|
657 |
||
658 |
// TO DO: (mandatory) |
|
659 |
// Write to the appropriate hardware register to clear the digitiser interrupt |
|
660 |
// |
|
661 |
||
662 |
// |
|
663 |
// TO DO: (optional) |
|
664 |
// |
|
665 |
// Reassert request on power resources |
|
666 |
// This will move the peripheral hardware out of low power "Sleep" mode back to fully operational |
|
667 |
// EXAMPLE ONLY |
|
668 |
// |
|
669 |
TemplateResourceManager* aManager = TTemplatePowerController::ResourceManager(); |
|
670 |
aManager -> ModifyToLevel(TemplateResourceManager::AsynchMlResourceUsedByXOnly, 100 /* a percentage */); |
|
671 |
aManager -> SharedBResource1() -> Use(); |
|
672 |
||
673 |
// TO DO: (mandatory) |
|
674 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
675 |
// to detect when the digitizer panel is touched |
|
676 |
// |
|
677 |
||
678 |
iState = E_HW_PowerUp; // so we wait for pen up if necessary |
|
679 |
iTakeReadingDfc.Enque(); |
|
680 |
} |
|
681 |
||
682 |
/** |
|
683 |
DPowerHandler pure virtual |
|
684 |
||
685 |
@param aPowerState the current power state |
|
686 |
*/ |
|
687 |
void DTemplateDigitiser::PowerDown(TPowerState /*aPowerState*/) |
|
688 |
{ |
|
689 |
iPoweringDown = ETrue; |
|
690 |
iPowerDownDfc.Enque(); // queue a DFC in this driver's context |
|
691 |
} |
|
692 |
||
693 |
/** |
|
694 |
Turn the digitiser off |
|
695 |
May be called as a result of a power transition or from the HAL |
|
696 |
If called from Power Manager, then the digitiser may be already be off (iPointerOn == EFalse) |
|
697 |
if the platform is in silent running mode |
|
698 |
*/ |
|
699 |
void DTemplateDigitiser::DigitiserOff() |
|
700 |
{ |
|
701 |
__KTRACE_OPT(KPOWER,Kern::Printf("DTemplateDigitiser::DigitiserOff() iPointerOn=%d", iPointerOn)); |
|
702 |
if (iPointerOn) // can have been powered down from HAL |
|
703 |
{ |
|
704 |
iPointerOn = EFalse; |
|
705 |
Interrupt::Disable(KIntIdDigitiser); |
|
706 |
||
707 |
// TO DO: (mandatory) |
|
708 |
// Write to the appropriate hardware register to disable the digitiser interrupt |
|
709 |
// |
|
710 |
||
711 |
iTimer.Cancel(); |
|
712 |
iTimerInt.Cancel(); |
|
713 |
iTakeReadingDfc.Cancel(); |
|
714 |
if (iState != E_HW_CollectSample) |
|
715 |
{ |
|
716 |
// Need to lock the kernel to simulate ISR context and thus defer preemption, |
|
717 |
// since PenUp() expects an ISR context and calls TDfc::Add(). |
|
718 |
NKern::Lock(); |
|
719 |
PenUp(); // adds DFC (will call WaitForPenDown) |
|
720 |
NKern::Unlock(); |
|
721 |
} |
|
722 |
else |
|
723 |
{ |
|
724 |
||
725 |
// TO DO: (mandatory) |
|
726 |
// Write to the appropriate hardware register(s) to allow the hardware |
|
727 |
// to detect when the digitizer panel is touched and wakes up the system if in standby |
|
728 |
// |
|
729 |
||
730 |
// |
|
731 |
// TO DO: (optional) |
|
732 |
// |
|
733 |
// Relinquish request on power resources as we are being powered down |
|
734 |
// This will place the peripheral hardware in a low power "Sleep" mode which is Interrupt detection capable |
|
735 |
// EXAMPLE ONLY |
|
736 |
// |
|
737 |
TemplateResourceManager* aManager = TTemplatePowerController::ResourceManager(); |
|
738 |
aManager -> ModifyToLevel(TemplateResourceManager::AsynchMlResourceUsedByXOnly, 0 /* a percentage */); |
|
739 |
aManager -> SharedBResource1() -> Release(); |
|
740 |
||
741 |
if (iPoweringDown) // came here through PowerDown |
|
742 |
{ |
|
743 |
iPoweringDown = EFalse; |
|
744 |
PowerDownDone(); |
|
745 |
} |
|
746 |
} |
|
747 |
} |
|
748 |
else // already powered down (by HAL) |
|
749 |
{ |
|
750 |
if (iPoweringDown) // came here through PowerDown |
|
751 |
{ |
|
752 |
iPoweringDown = EFalse; |
|
753 |
PowerDownDone(); |
|
754 |
} |
|
755 |
} |
|
756 |
} |
|
757 |
||
758 |
||
759 |
||
760 |
||
761 |
/** |
|
762 |
Convert digitiser coordinates to screen coordinates |
|
763 |
||
764 |
@param aDigitiserPoint the digitiser coordinates |
|
765 |
@param aScreenPoint A TPoint supplied by the caller. |
|
766 |
On return, set to the converted screen coordinates in pixels. |
|
767 |
||
768 |
@return KErrNone if successful |
|
769 |
*/ |
|
770 |
TInt DTemplateDigitiser::DigitiserToScreen(const TPoint& aDigitiserPoint, TPoint& aScreenPoint) |
|
771 |
{ |
|
772 |
NKern::LockSystem(); |
|
773 |
TInt R11 = iMachineConfig.iCalibration.iR11; |
|
774 |
TInt R12 = iMachineConfig.iCalibration.iR12; |
|
775 |
TInt R21 = iMachineConfig.iCalibration.iR21; |
|
776 |
TInt R22 = iMachineConfig.iCalibration.iR22; |
|
777 |
TInt TX = iMachineConfig.iCalibration.iTx; |
|
778 |
TInt TY = iMachineConfig.iCalibration.iTy; |
|
779 |
NKern::UnlockSystem(); |
|
780 |
TInt X = aDigitiserPoint.iX; |
|
781 |
TInt Y = aDigitiserPoint.iY; |
|
782 |
||
783 |
aScreenPoint.iX = (X*R11 + Y*R21 + TX) >> 16; |
|
784 |
aScreenPoint.iY = (X*R12 + Y*R22 + TY) >> 16; |
|
785 |
||
786 |
__KTRACE_OPT(KHARDWARE,Kern::Printf("DtS: Dp.x %d, Dp.y %d, Sp.x %d, Sp.y %d", X,Y,aScreenPoint.iX,aScreenPoint.iY)); |
|
787 |
||
788 |
return KErrNone; |
|
789 |
} |
|
790 |
||
791 |
/** |
|
792 |
Convert screen coordinates back into digitiser coordinates |
|
793 |
using the current constants from the superpage |
|
794 |
||
795 |
@param aX The screen X coordinate in pixels; On return, set to the digitiser X coordinate. |
|
796 |
@param aY The screen Y coordinate in pixels; On return, set to the digitiser Y coordinate. |
|
797 |
*/ |
|
798 |
void DTemplateDigitiser::ScreenToDigitiser(TInt& aX, TInt& aY) |
|
799 |
{ |
|
800 |
NKern::LockSystem(); |
|
801 |
Int64 R11 = iMachineConfig.iCalibration.iR11; |
|
802 |
Int64 R12 = iMachineConfig.iCalibration.iR12; |
|
803 |
Int64 R21 = iMachineConfig.iCalibration.iR21; |
|
804 |
Int64 R22 = iMachineConfig.iCalibration.iR22; |
|
805 |
Int64 TX = iMachineConfig.iCalibration.iTx; |
|
806 |
Int64 TY = iMachineConfig.iCalibration.iTy; |
|
807 |
NKern::UnlockSystem(); |
|
808 |
Int64 X = aX; |
|
809 |
Int64 Y = aY; |
|
810 |
// |
|
811 |
// Xd=(Xs<<16)*R22-(Ys<<16)*R21-(TX*R22)+(TY*R21) |
|
812 |
// ------------------------------------------- |
|
813 |
// (R22*R11)-(R21*R12) |
|
814 |
// |
|
815 |
// |
|
816 |
// Yd=(Xs<<16)*R12-(Ys<<16)*R11-(TX*R12)+(TY*R11) |
|
817 |
// ------------------------------------------- |
|
818 |
// (R21*R12)-(R22*R11) |
|
819 |
// |
|
820 |
// where Xd and Yd are digitiser coordinates |
|
821 |
// Xs and Ys are supplied screen coordinates |
|
822 |
// |
|
823 |
X<<=16; |
|
824 |
Y<<=16; |
|
825 |
||
826 |
Int64 d=Int64(R21)*Int64(R12)-Int64(R22)*Int64(R11); |
|
827 |
||
828 |
Int64 r=(X*R12)-(Y*R11)-(TX*R12)+(TY*R11); |
|
829 |
||
830 |
r=r/d; |
|
831 |
||
832 |
aY=(TInt)r; |
|
833 |
||
834 |
r=(X*R22)-(Y*R21)-(TX*R22)+(TY*R21); |
|
835 |
||
836 |
r=r/(-d); |
|
837 |
||
838 |
aX=(TInt)r; |
|
839 |
} |
|
840 |
||
841 |
/** |
|
842 |
Calculate values for R11, R12, R21, R22, TX and TY |
|
843 |
||
844 |
@param aCalibration the screen coordinates of points touched |
|
845 |
@return KErrNone if successful |
|
846 |
*/ |
|
847 |
TInt DTemplateDigitiser::SetXYInputCalibration(const TDigitizerCalibration& aCalibration) |
|
848 |
{ |
|
849 |
TInt R11,R12,R21,R22,TX,TY; |
|
850 |
// |
|
851 |
// Get coords of expected points |
|
852 |
// |
|
853 |
TDigitizerCalibration cal; |
|
854 |
TInt ret=CalibrationPoints(cal); |
|
855 |
if (ret!=KErrNone) |
|
856 |
return ret; |
|
857 |
||
858 |
TInt Xp1=cal.iTl.iX; |
|
859 |
TInt Yp1=cal.iTl.iY; |
|
860 |
TInt Xp2=cal.iBl.iX; |
|
861 |
TInt Yp2=cal.iBl.iY; |
|
862 |
TInt Xp3=cal.iBr.iX; |
|
863 |
TInt Yp3=cal.iBr.iY; |
|
864 |
// |
|
865 |
// Get coords of points touched in screen coordinates |
|
866 |
// |
|
867 |
TInt X1=aCalibration.iTl.iX; |
|
868 |
TInt Y1=aCalibration.iTl.iY; |
|
869 |
TInt X2=aCalibration.iBl.iX; |
|
870 |
TInt Y2=aCalibration.iBl.iY; |
|
871 |
TInt X3=aCalibration.iBr.iX; |
|
872 |
TInt Y3=aCalibration.iBr.iY; |
|
873 |
// |
|
874 |
// Convert back to raw digitiser coordinates |
|
875 |
// |
|
876 |
ScreenToDigitiser(X1,Y1); |
|
877 |
ScreenToDigitiser(X2,Y2); |
|
878 |
ScreenToDigitiser(X3,Y3); |
|
879 |
// |
|
880 |
// (Y1-Y2)(Xp1-Xp3) - (Y1-Y3)(Xp1-Xp2) |
|
881 |
// ----------------------------------- = R11 |
|
882 |
// (Y1-Y2)(X1-X3) - (Y1-Y3)(X1-X2) |
|
883 |
// |
|
884 |
Int64 r=((Int64(Y1-Y2)*Int64(Xp1-Xp3))-(Int64(Y1-Y3)*Int64(Xp1-Xp2))); |
|
885 |
r<<=16; |
|
886 |
r/=(Int64(Y1-Y2)*Int64(X1-X3)-Int64(Y1-Y3)*Int64(X1-X2)); |
|
887 |
R11=(TInt)r; |
|
888 |
// |
|
889 |
// (Y1-Y2)(Yp1-Yp3) - (Y1-Y3)(Yp1-Yp2) |
|
890 |
// ----------------------------------- = R12 |
|
891 |
// (Y1-Y2)(X1-X3) - (Y1-Y3)(X1-X2) |
|
892 |
// |
|
893 |
r=((Int64(Y1-Y2)*Int64(Yp1-Yp3))-(Int64(Y1-Y3)*Int64(Yp1-Yp2))); |
|
894 |
r<<=16; |
|
895 |
r/=(Int64(Y1-Y2)*Int64(X1-X3)-Int64(Y1-Y3)*Int64(X1-X2)); |
|
896 |
R12=(TInt)r; |
|
897 |
// |
|
898 |
// (X1-X3)(Xp2-Xp3) - (X2-X3)(Xp1-Xp3) |
|
899 |
// ----------------------------------- = R21 |
|
900 |
// (Y2-Y3)(X1-X3) - (Y1-Y3)(X2-X3) |
|
901 |
// |
|
902 |
r=(((X1-X3)*(Xp2-Xp3))-((X2-X3)*(Xp1-Xp3))); |
|
903 |
r<<=16; |
|
904 |
r/=(Int64(Y2-Y3)*Int64(X1-X3)-Int64(Y1-Y3)*Int64(X2-X3)); |
|
905 |
R21=(TInt)r; |
|
906 |
// |
|
907 |
// (X1-X3)(Yp2-Yp3) - (X2-X3)(Yp1-Yp3) |
|
908 |
// ----------------------------------- = R22 |
|
909 |
// (Y2-Y3)(X1-X3) - (Y1-Y3)(X2-X3) |
|
910 |
// |
|
911 |
r=((Int64(X1-X3)*Int64(Yp2-Yp3))-(Int64(X2-X3)*Int64(Yp1-Yp3))); |
|
912 |
r<<=16; |
|
913 |
r/=(Int64(Y2-Y3)*Int64(X1-X3)-Int64(Y1-Y3)*Int64(X2-X3)); |
|
914 |
R22=(TInt)r; |
|
915 |
// |
|
916 |
// TX = Xp1 - X1*R11 - Y1*R21 |
|
917 |
// |
|
918 |
TX=(Xp1<<16)-(X1*R11)-(Y1*R21); |
|
919 |
// |
|
920 |
// TY = Yp1 - X1*R12 - Y1*R22 |
|
921 |
// |
|
922 |
TY=(Yp1<<16)-(X1*R12)-(Y1*R22); |
|
923 |
||
924 |
// |
|
925 |
// Write new values into the superpage |
|
926 |
// |
|
927 |
NKern::LockSystem(); |
|
928 |
iMachineConfig.iCalibration.iR11 = R11; |
|
929 |
iMachineConfig.iCalibration.iR12 = R12; |
|
930 |
iMachineConfig.iCalibration.iR21 = R21; |
|
931 |
iMachineConfig.iCalibration.iR22 = R22; |
|
932 |
iMachineConfig.iCalibration.iTx = TX; |
|
933 |
iMachineConfig.iCalibration.iTy = TY; |
|
934 |
NKern::UnlockSystem(); |
|
935 |
||
936 |
return(KErrNone); |
|
937 |
} |
|
938 |
||
939 |
/** |
|
940 |
Informs the user-side calibration application where to draw |
|
941 |
the cross-hairs on the screen |
|
942 |
||
943 |
@param aCalibration On return contains the for points on the screen (in screen coordinates) |
|
944 |
where the cross-hairs should be drawn |
|
945 |
@return KErrNone if succcessful |
|
946 |
*/ |
|
947 |
TInt DTemplateDigitiser::CalibrationPoints(TDigitizerCalibration& aCalibration) |
|
948 |
{ |
|
949 |
TVideoInfoV01Buf buf; |
|
950 |
TVideoInfoV01& vidinfo=buf(); |
|
951 |
TInt r = Kern::HalFunction(EHalGroupDisplay, EDisplayHalCurrentModeInfo, (TAny*)&buf, NULL); |
|
952 |
if (r!=KErrNone) |
|
953 |
return r; |
|
954 |
iScreenSize=vidinfo.iSizeInPixels; |
|
955 |
||
956 |
aCalibration.iBl.iX = aCalibration.iTl.iX = iScreenSize.iWidth/10; |
|
957 |
aCalibration.iTr.iY = aCalibration.iTl.iY = iScreenSize.iHeight/10; |
|
958 |
aCalibration.iBr.iY = aCalibration.iBl.iY = iScreenSize.iHeight-iScreenSize.iHeight/10; |
|
959 |
aCalibration.iTr.iX = aCalibration.iBr.iX = iScreenSize.iWidth-iScreenSize.iWidth/10; |
|
960 |
return r; |
|
961 |
} |
|
962 |
/** |
|
963 |
Saves the digitiser calibration to the persistent machine configuration area |
|
964 |
so that it can be restored after a power-down/up |
|
965 |
||
966 |
@return KErrNone if succcessful |
|
967 |
*/ |
|
968 |
TInt DTemplateDigitiser::SaveXYInputCalibration() |
|
969 |
{ |
|
970 |
NKern::LockSystem(); |
|
971 |
iMachineConfig.iCalibrationSaved = iMachineConfig.iCalibration; |
|
972 |
NKern::UnlockSystem(); |
|
973 |
return(KErrNone); |
|
974 |
} |
|
975 |
||
976 |
/** |
|
977 |
Restores the digitiser calibration from the persistent machine configuration area |
|
978 |
following a power-up |
|
979 |
||
980 |
@param aType indicates whether to restore factory or saved settings |
|
981 |
@return KErrNone if succcessful |
|
982 |
*/ |
|
983 |
TInt DTemplateDigitiser::RestoreXYInputCalibration(TDigitizerCalibrationType aType) |
|
984 |
{ |
|
985 |
TInt r=KErrNone; |
|
986 |
NKern::LockSystem(); |
|
987 |
switch (aType) |
|
988 |
{ |
|
989 |
case EFactory: |
|
990 |
iMachineConfig.iCalibration=iMachineConfig.iCalibrationFactory; |
|
991 |
break; |
|
992 |
case ESaved: |
|
993 |
iMachineConfig.iCalibration=iMachineConfig.iCalibrationSaved; |
|
994 |
break; |
|
995 |
default: |
|
996 |
r=KErrNotSupported; |
|
997 |
break; |
|
998 |
} |
|
999 |
NKern::UnlockSystem(); |
|
1000 |
return r; |
|
1001 |
} |
|
1002 |
||
1003 |
/** |
|
1004 |
Gets the digitiser configuration information |
|
1005 |
||
1006 |
@param aInfo On return, contains information about the digitiser's dimensions etc. |
|
1007 |
*/ |
|
1008 |
void DTemplateDigitiser::DigitiserInfo(TDigitiserInfoV01& aInfo) |
|
1009 |
{ |
|
1010 |
__KTRACE_OPT(KEXTENSION,Kern::Printf("DTemplateDigitiser::DigitiserInfo")); |
|
1011 |
aInfo.iDigitiserSize.iWidth=KConfigXyWidth; |
|
1012 |
aInfo.iDigitiserSize.iHeight=KConfigXyHeight; |
|
1013 |
aInfo.iOffsetToDisplay.iX=KConfigXyOffsetX; |
|
1014 |
aInfo.iOffsetToDisplay.iY=KConfigXyOffsetY; |
|
1015 |
} |
|
1016 |
||
1017 |
/** |
|
1018 |
Issues a pen move event if the distance from the last point is greater than the threshold |
|
1019 |
||
1020 |
@param aPoint the pen position in screen coordinates |
|
1021 |
*/ |
|
1022 |
void DTemplateDigitiser::FilterPenMove(const TPoint& aPoint) |
|
1023 |
{ |
|
1024 |
TPoint offset=aPoint; |
|
1025 |
offset.iX-=iLastPos.iX; |
|
1026 |
offset.iY-=iLastPos.iY; |
|
1027 |
if (Abs(offset.iX)>=iCfg.iAccThresholdX || Abs(offset.iY)>=iCfg.iAccThresholdY) |
|
1028 |
{ |
|
1029 |
iLastPos=aPoint; |
|
1030 |
IssuePenMoveEvent(aPoint); |
|
1031 |
} |
|
1032 |
} |
|
1033 |
||
1034 |
/** |
|
1035 |
Reset the pen move filter |
|
1036 |
*/ |
|
1037 |
void DTemplateDigitiser::ResetPenMoveFilter() |
|
1038 |
{ |
|
1039 |
} |
|
1040 |