📄 tchmain.c
字号:
// Signal the Power Manager activity event if one has been set up
if ( ghevCalibrationActivity != NULL)
{
SetEvent(ghevCalibrationActivity);
}
// Must see down transition.
if ( (SampleFlags & (TouchSampleDownFlag|TouchSamplePreviousDownFlag)) ==
TouchSampleDownFlag )
{
CalibrationState = CalibrationDown;
fSetBase = TRUE;
CalibrationSampleCount = 0;
fGotSample = FALSE;
}
// Only look at stuff if we saw a down transition.
if ( (CalibrationState == CalibrationDown) && !fGotSample )
{
if ( SampleFlags & TouchSampleDownFlag )
{
long DeltaX, DeltaY;
CalibrationSampleCount++;
CX = RawX;
CY = RawY;
if ( fSetBase )
{
XBase = CX;
YBase = CY;
BaseTime = GetTickCount();
fSetBase = FALSE;
}
DeltaX = CX - XBase;
DeltaY = CY - YBase;
if ( (GetTickCount() - BaseTime) > CAL_HOLD_STEADY_TIME )
{
fGotSample = TRUE;
}
else if ( ( ABS(DeltaX) > CAL_DELTA_RESET ) ||
( ABS(DeltaY) > CAL_DELTA_RESET ) )
{
RETAILMSG(1, (TEXT("M %ld,%ld %ld,%ld %ld,%ld"),
XBase,YBase, CX,CY, DeltaX,DeltaY));
fSetBase = TRUE;
}
}
else
{
// They lifted the pen, see if we will accept coordinate.
if ( CalibrationSampleCount >= MIN_CAL_COUNT )
{
fGotSample = TRUE;
}
else
{
CalibrationState = CalibrationWaiting;
}
}
if ( fGotSample )
{
CalibrationState = CalibrationValid;
lCalibrationXCoord = CX;
lCalibrationYCoord = CY;
SetEvent(hCalibrationSampleAvailable);
}
}
LeaveCriticalSection( &csMutex );
}
else
{
pfnCallback = v_pfnPointCallback;
if ( pfnCallback != NULL )
{
if( SampleFlags & TouchSampleIsCalibratedFlag )
{ // Sample already calibrated by PDD
CalX = RawX;
CalY = RawY;
}
else
{ // Not previously calibrated, do it now.
TouchPanelCalibrateAPoint( RawX, RawY, &CalX, &CalY );
SampleFlags |= TouchSampleIsCalibratedFlag;
}
LeaveCriticalSection( &csMutex );
// Bounds check this value
if( CalX < 0 )
CalX = 0;
else if( MaxX && ((UINT32)CalX >= MaxX) )
CalX = MaxX - X_SCALE_FACTOR;
if( CalY < 0 )
CalY = 0;
else if( MaxY && ((UINT32)CalY >= MaxY) )
CalY = MaxY - Y_SCALE_FACTOR ;
DEBUGMSG( ZONE_SAMPLES,
(TEXT("**** Queuing point (%d, %d), flags 0x%4.4X\r\n"),
CalX, CalY, SampleFlags) );
#ifdef DEBUG
{
static DWORD SampleCt;
if( SampleFlags & TouchSampleDownFlag )
SampleCt++;
else
{
DEBUGMSG( ZONE_TIMING,
(TEXT("%d down samples queued\r\n"),
SampleCt) );
SampleCt = 0;
}
}
#endif
(pfnCallback)( SampleFlags, CalX, CalY);
}
else
{
LeaveCriticalSection( &csMutex );
}
}
}
ExitThread(1);
return ( TRUE );
}
#define KEYNAME_TOUCH_DRIVER TEXT("\\Drivers\\BuiltIn\\Touch")
#define VALNAME_THREAD_PRIO TEXT("Priority256")
#define VALNAME_THREAD_HIGH_PRIO TEXT("HighPriority256")
/*++
Autodoc Information:
@func DWORD | TouchPanelpGetPriority |
This routine reads the TouchPanelpISR thread priority from the registry.
--*/
static VOID TouchPanelpGetPriority(DWORD *ThrdPrio, DWORD *ThrdHighPrio)
{
HKEY hKey;
DWORD dwType;
DWORD dwSize;
DWORD dwStatus;
dwStatus = RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
KEYNAME_TOUCH_DRIVER,
0,
0,
&hKey
);
if (dwStatus)
{
DEBUGMSG(ZONE_INIT | ZONE_WARN,
(TEXT("TOUCH:TouchPanelpGetPriority - RegOpenKeyEx(%s) failed %d, using default thread priorities\n"),
KEYNAME_TOUCH_DRIVER, dwStatus));
*ThrdPrio = DEFAULT_THREAD_PRIORITY;
*ThrdHighPrio = DEFAULT_THREAD_HIGH_PRIORITY;
return;
}
dwSize = sizeof(DWORD);
dwStatus = RegQueryValueEx(
hKey,
VALNAME_THREAD_PRIO,
0,
&dwType,
(PUCHAR)ThrdPrio,
&dwSize
);
if (dwStatus)
{
DEBUGMSG(ZONE_INIT | ZONE_WARN,
(TEXT("TOUCH:TouchPanelpGetPriority - Failed to get %s value, defaulting to %d\r\n"),
VALNAME_THREAD_PRIO, DEFAULT_THREAD_PRIORITY));
*ThrdPrio = DEFAULT_THREAD_PRIORITY;
}
dwSize = sizeof(DWORD);
dwStatus = RegQueryValueEx(
hKey,
VALNAME_THREAD_HIGH_PRIO,
0,
&dwType,
(PUCHAR)ThrdHighPrio,
&dwSize
);
if (dwStatus)
{
DEBUGMSG(ZONE_INIT | ZONE_WARN,
(TEXT("TOUCH:TouchPanelpGetPriority - Failed to get %s value, defaulting to %d\r\n"),
VALNAME_THREAD_HIGH_PRIO, DEFAULT_THREAD_HIGH_PRIORITY));
*ThrdHighPrio = DEFAULT_THREAD_HIGH_PRIORITY;
}
RegCloseKey(hKey);
RETAILMSG(1, (TEXT("TOUCH:ThrdPrio = %d, ThrdHighPrio = %d\n"), *ThrdPrio, *ThrdHighPrio));
return;
} // TouchPanelpGetPriority
//**********************************************************************
// The following routines provide the exported DDI interface.
// @doc EX_TOUCH_DDI EXTERNAL DRIVERS MDD TOUCH_PANEL
//**********************************************************************
#ifdef DEBUG
PFN_TOUCH_PANEL_SET_CALIBRATION v_pfnSetCalibration = TouchPanelSetCalibration;
#endif
/*++
@func BOOL | TouchPanelGetDeviceCaps |
Queries capabilities about the physical touch panel device.
@parm ULONG | iIndex |
Specifies the capability to query. They are one of the following:
@flag DDI_TPDC_SAMPLERATE |
The sample rate.
@flag DDI_TPDC_CALIBRATIONPOINTS |
The X and Y coordinates used for calibration.
@flag DDI_TPDC_CALIBRATIONDATA |
The X and Y coordinates used for calibration mapping.
@flag DDI_TPDC_SAMPLERATE |
Size of the digitizer panel (X, Y).
@parm LPVOID | lpOutput |
Points to the memory location(s) where the queried information
will be placed. The format of the memory referenced depends on
the setting of iIndex. If 0, returns the number of words
required for the output data.
@rdesc
The return value is TRUE if the information was retrieved succesfully,
and FALSE otherwise.
--*/
BOOL
TouchPanelGetDeviceCaps(
INT iIndex,
LPVOID lpOutput
)
{
struct TPDC_CALIBRATION_POINT *pTCP;
BOOL fGotCaps = FALSE;
EnterCriticalSection( &csMutex );
if( lpOutput != NULL)
{
fGotCaps = DdsiTouchPanelGetDeviceCaps(iIndex, lpOutput);
// We want to remember the screen size for later use. Some day,
// we might change this so that screen size is passed in as
// part of setup. But for now, it is part of getCalibrationPoint
if( iIndex == TPDC_CALIBRATION_POINT_ID )
{
pTCP = (struct TPDC_CALIBRATION_POINT *)lpOutput;
DisplayWidth = pTCP -> cDisplayWidth;
DisplayHeight = pTCP -> cDisplayHeight;
}
}
LeaveCriticalSection( &csMutex );
return ( fGotCaps );
}
#ifdef DEBUG
PFN_TOUCH_PANEL_GET_DEVICE_CAPS v_pfnGetDeviceCaps = TouchPanelGetDeviceCaps;
#endif
/*++
Autodoc Information:
@func BOOL | TouchPanelSetMode |
Sets information about the abstract touch panel device.
@parm ULONG | iIndex |
Specifies the mode to set. They are one of the following:
@flag DDI_TPSM_SAMPLERATE_HIGH |
Set the sample rate to the high rate.
@flag DDI_TPSM_SAMPLERATE_LOW |
Set the sample rate to the low rate.
@parm LPVOID | lpInput |
Points to the memory location(s) where the update information
resides. The format of the memory referenced depends on the
mode.
@rdesc
If the function succeeds the return value is TRUE, otherwise, it is FALSE.
Extended error information is available via the GetLastError function.
--*/
BOOL
TouchPanelSetMode(
INT iIndex,
LPVOID lpInput
)
{
BOOL ReturnValue = TRUE; // Assume it worked until someone says othewise
EnterCriticalSection( &csMutex );
switch( iIndex )
{
// The thread priority functions were provided so that OOM could
// raise our priority as needed.
case TPSM_PRIORITY_HIGH_ID:
// Set the flag so that no more points are send to transcriber while system in OOM state.
_bTchThreadHighPriority = TRUE;
CeSetThreadPriority (hThread, gThreadHighPriority);
break;
case TPSM_PRIORITY_NORMAL_ID:
CeSetThreadPriority (hThread, gThreadPriority);
// We are no longer in OOM state.
_bTchThreadHighPriority = FALSE;
break;
default:
// If we can't handle it, give the PDD a chance
ReturnValue = DdsiTouchPanelSetMode(iIndex, lpInput);
break;
}
LeaveCriticalSection( &csMutex );
return ( ReturnValue );
}
#ifdef DEBUG
PFN_TOUCH_PANEL_SET_MODE v_pfnSetMode = TouchPanelSetMode;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -