static
void
PddpTouchPanelEvaluateSamples(
TOUCH_PANEL_SAMPLE_FLAGS *pSampleFlags, //@PARM Pointer to where the tip state information will be returned.
INT *pUncalX, //@PARM Pointer to where the x coordinate will be returned.
INT *pUncalY //@PARM Pointer to where the y coordinate will be returned.
)
{
LONG dlXDiff0;
LONG dlXDiff1;
LONG dlXDiff2;
LONG dlYDiff0;
LONG dlYDiff1;
LONG dlYDiff2;
TOUCHPANEL_POINT_SAMPLES rgPointSamples;
//
// Get the sample.
//
PddpTouchPanelGetSamples( rgPointSamples );
//
// Calcuate the differences for the X samples and insure that
// the resulting number is positive.
//
dlXDiff0 = rgPointSamples[ 0 ].XSample - rgPointSamples[ 1 ].XSample;
dlXDiff1 = rgPointSamples[ 1 ].XSample - rgPointSamples[ 2 ].XSample;
dlXDiff2 = rgPointSamples[ 2 ].XSample - rgPointSamples[ 0 ].XSample;
dlXDiff0 = dlXDiff0 > 0 ? dlXDiff0 : -dlXDiff0;
dlXDiff1 = dlXDiff1 > 0 ? dlXDiff1 : -dlXDiff1;
dlXDiff2 = dlXDiff2 > 0 ? dlXDiff2 : -dlXDiff2;
//
// Calcuate the differences for the Y samples and insure that
// the resulting number is positive.
//
dlYDiff0 = rgPointSamples[ 0 ].YSample - rgPointSamples[ 1 ].YSample;
dlYDiff1 = rgPointSamples[ 1 ].YSample - rgPointSamples[ 2 ].YSample;
dlYDiff2 = rgPointSamples[ 2 ].YSample - rgPointSamples[ 0 ].YSample;
dlYDiff0 = dlYDiff0 > 0 ? dlYDiff0 : -dlYDiff0;
dlYDiff1 = dlYDiff1 > 0 ? dlYDiff1 : -dlYDiff1;
dlYDiff2 = dlYDiff2 > 0 ? dlYDiff2 : -dlYDiff2;
//
// The final X coordinate is the average of coordinates of
// the two MIN of the differences.
//
if ( dlXDiff0 < dlXDiff1 )
{
if ( dlXDiff2 < dlXDiff0 )
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
else
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 1 ].XSample ) >> 1 ) );
}
}
else if ( dlXDiff2 < dlXDiff1 )
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 0 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
else
{
*pUncalX = (ULONG)( ( ( rgPointSamples[ 1 ].XSample + rgPointSamples[ 2 ].XSample ) >> 1 ) );
}
//
//
// The final Y coordinate is the average of coordinates of
// the two MIN of the differences.
//
if ( dlYDiff0 < dlYDiff1 )
{
if ( dlYDiff2 < dlYDiff0 )
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
else
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 1 ].YSample ) >> 1 ) );
}
}
else if ( dlYDiff2 < dlYDiff1 )
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 0 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
else
{
*pUncalY = (ULONG)( ( ( rgPointSamples[ 1 ].YSample + rgPointSamples[ 2 ].YSample ) >> 1 ) );
}
//
// Validate the coordinates and set the tip state accordingly.
//
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE ||
dlXDiff1 > DELTA_X_COORD_VARIANCE ||
dlXDiff2 > DELTA_X_COORD_VARIANCE ||
dlYDiff0 > DELTA_Y_COORD_VARIANCE ||
dlYDiff1 > DELTA_Y_COORD_VARIANCE ||
dlYDiff2 > DELTA_Y_COORD_VARIANCE )
{
//#ifdef DBGPOINTS1
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 0: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 0 ].XSample, rgPointSamples[ 0 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 1: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 1 ].XSample, rgPointSamples[ 1 ].YSample) );
DEBUGMSG( ZONE_SAMPLES, (TEXT("Sample 2: X 0x%x Y 0x%x\r\n"),
rgPointSamples[ 2 ].XSample, rgPointSamples[ 2 ].YSample) );
if ( dlXDiff0 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff0 too large 0x%x\r\n"), dlXDiff0) );
if ( dlXDiff1 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff1 too large 0x%x\r\n"), dlXDiff1) );
if ( dlXDiff2 > DELTA_X_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("XDiff2 too large 0x%x\r\n"), dlXDiff2) );
if ( dlYDiff0 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff0 too large 0x%x\r\n"), dlYDiff0) );
if ( dlYDiff1 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff1 too large 0x%x\r\n"), dlYDiff1) );
if ( dlYDiff2 > DELTA_Y_COORD_VARIANCE )
DEBUGMSG( ZONE_SAMPLES, (TEXT("YDiff2 too large 0x%x\r\n"), dlYDiff2) );
//#endif // DBGPOINTS1
}
else
{
//
// Sample is valid. Set tip state accordingly.
//
*pSampleFlags = TouchSampleValidFlag | TouchSampleDownFlag;
}
DEBUGMSG( ZONE_SAMPLES, (TEXT("Filtered - SampleFlags: 0x%x X: 0x%x Y: 0x%x\r\n"),
*pSampleFlags, *pUncalX, *pUncalY) );
}
//
// PddpSetupPenDownIntr()
//
// Set up the UCB to give pen down interrupts. If EnableIntr flag is set, enable
// the interrupt, otherwise, leave it disabled. Note: - Caller must hold semaphore
// when this function is called to protect access to the shared UCB registers.
//
BOOL
PddpSetupPenDownIntr(BOOL EnableIntr)
{
// USHORT intrMask;
// I don't know why we enable the interrupt here.
//
// Setup ADC register
//
// kang code
// Enable Prescaler,Prescaler,AIN5/7 fix,Normal,Disable read start,No operation
// Down,YM:GND,YP:AIN5,XM:Hi-z,XP:AIN7,XP pullup En,Normal,Waiting for interrupt mode
// kang code end
// Down Int, YMON:0, nYPON:1, XMON:0;nXPON:1, Pullup:1, Auto Conv.,Waiting.
v_pADCregs->rADCTSC =(0 CalibrationY));
return TRUE;
}