ps2mouse.cpp
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 224 行
CPP
224 行
/*
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved.
*/
#include <windows.h>
#include <ceddk.h>
#include <nkintr.h>
#include "ps2port.hpp"
#include "ps2mouse.hpp"
#include "ps2keybd.hpp"
#ifdef WINCECODETEST
#ifndef __CT__
#include "ct.h"
#endif
#ifndef __CT_CE__
#include "ct_ce.h"
#endif
#ifndef __TAGIMPORTS__
#include "tagimports.h"
#endif
#endif // WINCECODETEST
DWORD dwSysIntr_Mouse;
extern void Read_SysIntr( LPCWSTR szKeyName, LPDWORD pdwSysIntr );
BOOL
Ps2Mouse::
Initialize(
Ps2Port *pp2p
)
{
UINT8 ui8Data;
m_pp2p = pp2p;
m_hevInterrupt = NULL;
m_ui8ButtonState = 0;
m_pp2p -> MouseDataRead(&ui8Data); // make sure mouse input buffer is empty
m_pp2p -> MouseDataRead(&ui8Data);
m_pp2p -> MouseDataRead(&ui8Data);
return TRUE;
}
BOOL
Ps2Mouse::
IsrThreadProc(
void
)
{
int cBytes = 0;
UINT8 ui8Data;
INT8 buf[3];
long x,y;
UINT8 ui8Buttons;
UINT8 ui8XorButtons;
unsigned int evfMouse;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST);
m_hevInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL);
if ( m_hevInterrupt == NULL)
{
goto leave;
}
Read_SysIntr( TEXT("HARDWARE\\DEVICEMAP\\MOUSE"), &dwSysIntr_Mouse );
if( !dwSysIntr_Mouse ) {
goto leave;
}
if ( !InterruptInitialize(dwSysIntr_Mouse, m_hevInterrupt, NULL, 0) )
{
goto leave;
}
m_pp2p -> MouseInterruptEnable();
for ( ; ; )
{
wait_for_interrupt:
if (WaitForSingleObject(m_hevInterrupt, (cBytes == 0 ? INFINITE : IN_PACKET_TIMEOUT)) == WAIT_TIMEOUT)
{
cBytes = 0;
m_pp2p -> MouseDataRead(&ui8Data); // make sure mouse input buffer is empty
m_pp2p -> MouseDataRead(&ui8Data);
m_pp2p -> MouseDataRead(&ui8Data);
goto wait_for_interrupt;
}
#ifdef WINCECODETEST
// AMC code: IST mouse entry
*amc_ctrl_port = FUNCTION_NORMAL_ENTRY | IST_PS2MOUSE;
#endif
if ( m_pp2p -> MouseDataRead(&ui8Data) )
{
if ( cBytes < 3 )
{
buf[cBytes++] = ui8Data;
}
if ( cBytes == 3 )
{
evfMouse = 0;
ui8XorButtons = buf[0] ^ m_ui8ButtonState;
if ( ui8XorButtons )
{
ui8Buttons = buf[0];
if ( ui8XorButtons & 0x01 )
{
if ( ui8Buttons & 0x01 )
{
evfMouse |= MOUSEEVENTF_LEFTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_LEFTUP;
}
}
if ( ui8XorButtons & 0x02 )
{
if ( ui8Buttons & 0x02 )
{
evfMouse |= MOUSEEVENTF_RIGHTDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_RIGHTUP;
}
}
if ( ui8XorButtons & 0x04 )
{
if ( ui8Buttons & 0x04 )
{
evfMouse |= MOUSEEVENTF_MIDDLEDOWN;
}
else
{
evfMouse |= MOUSEEVENTF_MIDDLEUP;
}
}
m_ui8ButtonState = buf[0];
}
if ( buf[1] || buf[2] )
{
evfMouse |= MOUSEEVENTF_MOVE;
}
x = buf[1];
y = -buf[2];
mouse_event(evfMouse, x, y, 0, NULL);
cBytes = 0;
}
}
else
{
ERRORMSG(1,(TEXT("Error reading mouse data\r\n")));
}
InterruptDone(dwSysIntr_Mouse);
#ifdef WINCECODETEST
// AMC code: mouse IST exit
*amc_ctrl_port = FUNCTION_NORMAL_EXIT | IST_PS2MOUSE;
#endif
}
leave:
return TRUE;
}
DWORD
Ps2MouseIsrThread(
Ps2Mouse *pp2m
)
{
pp2m -> IsrThreadProc();
return 0;
}
BOOL
Ps2Mouse::
IsrThreadStart(
void
)
{
HANDLE hthrd;
hthrd = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Ps2MouseIsrThread, this, 0, NULL);
// Since we don't need the handle, close it now.
CloseHandle(hthrd);
return TRUE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?