?? tchstub.cpp
字號:
if (ptq->iPut != iPut) OutputDebugString(L"iPut != ptq->iPut !!!\n");
}
#endif
}
/* *********************************************************************************************** */
// This posts the point on the internal touch driver queue (Q2)
void SendPtToSelf(int iFlags, int iX, int iY)
{
int iGet = 0;
int iPut = 0;
int i;
if(_bIgnoreStroke2 &&
(iFlags&TouchSamplePreviousDownFlag)!=0)
{
return;
}
EnterCriticalSection(&Q2CritSect);
iGet = tq2.iGet;
iPut = tq2.iPut;
if((iFlags&TouchSampleDownFlag)!=0)
i = iGet - 3;
else
i = iGet - 2;
// if there are at least 2 or 3 elements left for writing in the circular buffer (depn on iFlags)
// but why 2 or 3??? Does iGet not represent the real read pointer for the queue?
// perhaps we keep 2 or 3 old points available at all times in case we need them
// or maybe the code used to use them, but doesn't anymore
if(iPut<i ||
(iPut>=iGet && iPut<i+MAX_TOUCHQUEUE))
{
_bIgnoreStroke2 = FALSE;
tq2.elems[iPut][0]=iFlags;
tq2.elems[iPut][1]=((iX<<16)|iY);
// if((iFlags&TouchSampleDownFlag)==0)
// PostMessage(_hClientWnd, WM_PEGREC_TABLETEND, iPut, 0);
iPut++;
if(iPut>=MAX_TOUCHQUEUE)
iPut = 0;
tq2.iPut = iPut;
// if both this point and the last point were pen down
if((iFlags&(TouchSampleDownFlag|TouchSamplePreviousDownFlag))==
(TouchSampleDownFlag|TouchSamplePreviousDownFlag))
{
int iiX = (iX>>3);
int iiY = (iY>>3);
if(iiX != _iLastSelfX ||
iiY != _iLastSelfY ||
_iInRow >10)
{
SetEvent(g_hInnerEvent);
_iInRow = 0;
}
else
_iInRow++;
}
else
{
SetEvent(g_hInnerEvent);
_iInRow = 0;
}
}
else
{
_bIgnoreStroke2 = TRUE;
#ifdef DEBUG
OutputDebugString(TEXT("Inner Queue Overrun!\n"));
#endif
}
LeaveCriticalSection(&Q2CritSect);
}
/* *********************************************************************************************** */
LPVOID TouchGetQueuePtr()
{
return ptq; //_pTouchQueue; //&tq;
}
BOOL IsStubWndExist()
{
if(*_phStubWnd!=NULL || (*_phStubWnd=FindWindow(TOUCHSTUB_WNDCLASSNAME, NULL))!=NULL)
return TRUE;
else
return FALSE;
}
HWND TouchGetFocusWnd()
{
if(IsStubWndExist())
return (HWND)SendMessage(*_phStubWnd, WM_STUB_GETFOCUSWND, 0, 0);
return NULL;
}
HWND TouchGetLastTouchFocusWnd()
{
if(IsStubWndExist())
return (HWND)SendMessage(*_phStubWnd, WM_STUB_GETLASTTOUCHFOCUSWND, 0, 0);
return NULL;
}
void TouchReset(BOOL bSetAllValuesToDefault)
{
if(IsStubWndExist())
SendMessage(*_phStubWnd, WM_STUB_RESET, bSetAllValuesToDefault, 0);
}
void TouchCreateEvent(int iX, int iY)
{
if(IsStubWndExist())
SendMessage(*_phStubWnd, WM_STUB_EVENT, iX, iY);
}
void TouchCreateEventInternal(int begX, int begY)
{
if(v_pfnCgrPointCallback==NULL)
return;
(*v_pfnCgrPointCallback)(0x07, begX+1, begY+1);
(*v_pfnCgrPointCallback)(0x0f, begX, begY);
(*v_pfnCgrPointCallback)(0x0f, begX, begY);
(*v_pfnCgrPointCallback)(0x0f, begX, begY);
(*v_pfnCgrPointCallback)(0x0D, begX, begY);
(*v_pfnCgrPointCallback)(0x05, begX, begY);
}
HWND TouchGetRegisteredWindow()
{
return _hClientWnd;
}
BOOL TouchRegisterWindow(HWND hClientWnd)
{
// set up permissions so we can access the buffer in the touch driver
// (which might be in slot 4, for example, while Tscriber is in slot 8)
ptq->iPut = ptq->iGet =0;
tq2.iPut = tq2.iGet =0;
// zero out the shared memory queue
memset((void*) ptq, 0, sizeof(TOUCH_QUEUE));
if(IsStubWndExist() && SendMessage(*_phStubWnd, WM_STUB_REGISTWND, (WPARAM)hClientWnd, 0))
return TRUE;
else
return FALSE;
}
void TouchUnregisterWindow(HWND hClientWnd)
{
if(IsStubWndExist())
SendMessage(*_phStubWnd, WM_STUB_UNREGISTWND, (WPARAM)hClientWnd, 0);
}
void TouchSetValue(DWORD dwName, DWORD dwValue)
{
if(IsStubWndExist())
SendMessage(*_phStubWnd, WM_STUB_SETVALUE, dwName, dwValue);
}
LRESULT TouchGetValue(DWORD dwName, DWORD dwValue)
{
if(IsStubWndExist())
return SendMessage(*_phStubWnd, WM_STUB_GETVALUE, dwName, dwValue);
return 0;
}
/* ************************************************************************** */
// this is where we get points from the hardware
BOOL
CgrCallback(
TOUCH_PANEL_SAMPLE_FLAGS Flags,
INT X,
INT Y
)
{
DWORD dwTick;
TOUCH_PANEL_SAMPLE_FLAGS FlagsToDll = Flags, FlagsToWnd = Flags;
#ifdef DEBUG1
TCHAR str[100];
#endif
#if WRITE_STATISTICSLOG // define to log all points we get from hardware into a txt file
{
static int _iStatWrites = 0;
static int _iStatCurrent = 0;
static short _iStatBuf[MAX_STATS][3] = {0};
if(_iStatWrites<=MAX_WRITES)
{
static int count = 0;
_iStatBuf[_iStatCurrent][0] = (short)Flags;
_iStatBuf[_iStatCurrent][1] = (short)X;
_iStatBuf[_iStatCurrent][2] = (short)Y;
_iStatCurrent++;
if(_iStatCurrent==MAX_STATS)
{
HANDLE hFile = INVALID_HANDLE_VALUE;
int i;
_iStatCurrent = 0;
hFile = CreateFile(L"\\tchlog.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile!=INVALID_HANDLE_VALUE)
{
DWORD dw = 0;
int len;
int j;
SetFilePointer(hFile, 0, NULL, FILE_END);
for (i = 0; i < MAX_STATS; i++)
{
TCHAR str[64];
unsigned char str2[64];
wsprintf(str, L"%d %d %d %d %c%c", count++, (int)_iStatBuf[i][1], (int)(3000 - _iStatBuf[i][2]), (int)_iStatBuf[i][0], (TCHAR)13, (TCHAR)10);
len = _tcslen(str);
if(len > 62)
len = 62;
for (j = 0; j < len; j ++)
str2[j] = (unsigned char)str[j];
str2[len] = 0;
WriteFile(hFile, str2, len, &dw, NULL);
}
CloseHandle(hFile);
}
_iStatWrites++;
}
}
}
#endif
#ifdef DEBUG1
wsprintf(str, TEXT(" *** StubCallback (%d,%d) *** \n"), X, Y);
OutputDebugString( str);
#endif
#ifdef DEBUGTOUCH
static int nPointSkips; // incr if point more than 10 pixels away in x or y
static int nLongIntervalCount; // incr if time between points is greater than some threshold
static int nLongIntervalSum; // total length of all the long intervals we see
static long nStrokeStartTick; // when did this stroke start
static long nLastTimerTick; // time the last point was seen at
static int sampleCount; // number of points seen since the pen went down
static long nPointSkipSum; // how many total point skip distances
long nTicksNow;
long samplesPerSecond;
long nLongIntervalAvg; // how long was the average long interval
long nPointSkipAvg; // how many total point skip distances
long deltaX;
long deltaY;
long ptIndex;
static POINT ptBuf[2]; // point buffer for testing latentcy and throughput
// test for first point, middle point, or end point
// (ex - pen up points: wacom pens send points when above the tablet for cursor hovering)
// if first point
// Set sample count to 1
// get strokeStartTick and lastTimerTick time
// store first sample
// initialize accumulator variables
if ((0 == (Flags&TouchSamplePreviousDownFlag)) && // if previous sample is pen up
(0 != (Flags&TouchSampleDownFlag)) ) // and this sample is pen down
{
nStrokeStartTick = GetTickCount();
nLastTimerTick = nStrokeStartTick;
ptBuf[0].x = X;
ptBuf[0].y = Y;
sampleCount = 1;
nLongIntervalSum = 0;
nLongIntervalCount = 0;
nPointSkips = 0;
nPointSkipSum = 0;
}
// if middle point or end point
// get time
// store sample
// samplecount++
// check for time lag between samples
// check for point jumps
if (0 != (Flags&TouchSamplePreviousDownFlag)) // if the previous sample was pen down
// and this sample is either pen down or pen up
{
nTicksNow = GetTickCount();
ptIndex = sampleCount % 2;
ptBuf[ptIndex].x = X;
ptBuf[ptIndex].y = Y;
sampleCount++;
// check to see if too much time elapsed since the last point.
// this ignores the fact that the windows timer wraps around every 49 days
// I ignored it for the purpose of being fast and minimally intrusive.
if (nTicksNow - nLastTimerTick > LATENCY_THRESHOLD)
{
nLongIntervalCount++;
nLongIntervalSum += nTicksNow - nLastTimerTick;
}
// dist is greater than threshold if delta x squared + delta y squared > threshold squared
// we compute it this way because it is fastest - avoids the sqrt call
// we might be faster still if we used abs(deltaX) + abs(deltaY) > SKIP_THRESHOLD,
// but that is a non-euclidean distance metric.
deltaX = ptBuf[0].x - ptBuf[1].x;
deltaY = ptBuf[0].y - ptBuf[1].y;
if ( (deltaX * deltaX + deltaY * deltaY) > SKIP_THRESHOLD * SKIP_THRESHOLD)
{
nPointSkips++;
nPointSkipSum += deltaX*deltaX + deltaY*deltaY;
}
nLastTimerTick = nTicksNow;
}
// if end point, check for errors, and display error message if any happened.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -