📄 guiial.c
字号:
/***************************************************************************
* FILE: guiIal.c
* MODULE: input abstract layer
*
* PURPOSE:
*
* AUTHOR(S): YangCX
* GROUP: GUI Group
* DATE CREATED: 2001/11/18
* REFERENCE DOCUMENT ID:
* MODIFICATIONS:
* Date userName Description
* 2001/11/18 Yangcx Create this file
**************************************************************************/
#include <stdlib.h>
#include <string.h>
#include "sysGUI.h"
#include "sysROS33.h"
#define IAL_NR_KEYS 128
T_MODULE T_WORD wXPos; /* current x position of mouse */
T_MODULE T_WORD wYPos; /* current y position of mouse */
T_MODULE T_WORD wMinX; /* minimum allowed x position */
T_MODULE T_WORD wMaxX; /* maximum allowed x position */
T_MODULE T_WORD wMinY; /* minimum allowed y position */
T_MODULE T_WORD wMaxY; /* maximum allowed y position */
T_MODULE T_WORD wButtons; /* current state of buttons */
T_BOOL IsPenDown;
T_BOOL IsKeyDown;
T_MODULE T_UBYTE ubState[IAL_NR_KEYS];
/************************ Low Level Input Operations **********************/
/******************************************************************
* FUNCTION: UpdateMouse
*
* PURPOSE:
* read touchpad port,get current coordinate value
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
* IAL_NODATA(0) no data to read
* IAL_DATAREAD(1) success
*
* Reentrant : No
*****************************************************************/
T_MODULE T_WORD UpdateMouse(T_VOID)
{
T_WORD tempx,tempy;
T_WORD TempState;
if(fnIHL_ReadMouse(&TempState,&tempx,&tempy))
{
wButtons = TempState;
wXPos = tempx;
wYPos = tempy;
if( wXPos < wMinX )
wXPos = wMinX;
if( wXPos > wMaxX )
wXPos = wMaxX;
if( wYPos < wMinY )
wYPos = wMinY;
if( wYPos > wMaxY )
wYPos = wMaxY;
return IAL_DATAREAD;
}
else
{
return IAL_NODATA;
}
}
/******************************************************************
* FUNCTION: GetMouseX
*
* PURPOSE:
* get x value of current mouse cursor
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value: x value
*
* Reentrant : No
*****************************************************************/
T_MODULE T_WORD GetMouseX(T_VOID)
{
return wXPos;
}
/******************************************************************
* FUNCTION: GetMouseY
*
* PURPOSE:
* get y valude of current mouse cursor
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value: y value
*
* Reentrant : No
*****************************************************************/
T_MODULE T_WORD GetMouseY(T_VOID)
{
return wYPos;
}
/******************************************************************
* FUNCTION: SetMouseXY
*
* PURPOSE:
* reset position of current mouse cursor
*
* PARAMETERS
* Input:
* NewX new x value of mouse cursor
* NewY new y value of mouse cursor
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID SetMouseXY(T_WORD NewX, T_WORD NewY)
{
if (NewX < wMinX)
NewX = wMinX;
if (NewX > wMaxX)
NewX = wMaxX;
if (NewY < wMinY)
NewY = wMinY;
if (NewY > wMaxY)
NewY = wMaxY;
if (NewX == wXPos && NewY == wYPos)
return;
wXPos = NewX;
wYPos = NewY;
}
/******************************************************************
* FUNCTION: GetMouseButton
*
* PURPOSE:
* get mouse status
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value: the state of mouse key-press
*
* Reentrant : No
*****************************************************************/
T_MODULE T_WORD GetMouseButton(T_VOID)
{
return wButtons;
}
/******************************************************************
* FUNCTION: SetMouseRange
*
* PURPOSE:
* set up valid area of mouse move
*
* PARAMETERS
* Input:
* NewMinX x value of the left-top of the area
* NewMinY y value of the left_top of the area
* NewMaxX x value of the right-down of the area
* NewMaxY y value of the right-down of the area
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID SetMouseRange(
T_WORD NewMinX,
T_WORD NewMinY,
T_WORD NewMaxX,
T_WORD NewMaxY
)
{
wMinX = NewMinX;
wMinY = NewMinY;
wMaxX = NewMaxX;
wMaxY = NewMaxY;
SetMouseXY((NewMinX + NewMaxX) / 2, (NewMinY + NewMaxY) / 2);
}
/******************************************************************
* FUNCTION: SuspendMouse
*
* PURPOSE:
* suspend mouse
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID SuspendMouse(T_VOID)
{
/* nothing */
}
/******************************************************************
* FUNCTION: ResumeMouse
*
* PURPOSE:
* resume mouse
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID ResumeMouse(T_VOID)
{
/* nothing */
}
/******************************************************************
* FUNCTION: UpdateKeyboard
*
* PURPOSE:
* read keyboard messae, update keyboard status table
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
* IAL_NODATA(0) no key data
* IAL_DATAREAD(1) key data updated
*
* Reentrant : No
*****************************************************************/
T_MODULE T_WORD UpdateKeyboard(T_VOID)
{
T_UBYTE buf;
if(!fnIHL_ReadKeyboard(&buf))
return IAL_NODATA;
if(IsKeyDown)
{
ubState[buf] = 1;
}
else
{
ubState[buf] = 0;
}
return IAL_DATAREAD;
}
/******************************************************************
* FUNCTION: GetKeyboardState
*
* PURPOSE:
* get keyboard status table address
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value: starting address of the keyboard status table
*
* Reentrant : No
*****************************************************************/
T_MODULE T_CONST T_BYTE *GetKeyboardState(T_VOID)
{
return (T_CONST T_BYTE *)ubState;
}
/******************************************************************
* FUNCTION: SetLeds
*
* PURPOSE:
* set keyboard indicator light
*
* PARAMETERS
* Input:
* leds keyboard indicator light command
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID SetLeds(T_UWORD leds)
{
fnIHL_WriteKeyboard(leds);
}
/******************************************************************
* FUNCTION: SuspendKeyboard
*
* PURPOSE:
* suspend keyboard
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID SuspendKeyboard(T_VOID)
{
/* nothing */
}
/******************************************************************
* FUNCTION: ResumeKeyboard
*
* PURPOSE:
* resume keyboard
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_MODULE T_VOID ResumeKeyboard(T_VOID)
{
/* nothing */
}
/******************************************************************
* FUNCTION: WaitEvent
*
* PURPOSE:
* waiting for keyboard or keyboard event, if happend, call
* mouse_update or keyboard_update to get ralated data
*
* PARAMETERS
* Input:
* IsReturn: if it is True ,funciton will return immediately when there have no events;
* otherwise it will wait some time and then return.
* Output:
* InOut:
*
* Return value:
* IAL_TIMEOUTEVENT(0) no event happen
* IAL_MOUSEEVENT(1) mouse event happened
* IAL_KEYEVENT(2) keyboard event happended
*
* Reentrant : No
*****************************************************************/
T_WORD WaitEvent(T_BOOL IsReturn)
{
T_WORD retvalue = 0;
T_BOOL PenEvent,KeyEvent,IsTimeOut;
T_GUI_UINT p_flgptn;
/*initialize PenEvent and KeyEvent as FALSE*/
while(1)
{
PenEvent = FALSE;
KeyEvent = FALSE;
IsTimeOut = FALSE;
/*if pen not down and if key not down; now go to wait event*/
if( (!IsPenDown) )
{
if(IsReturn)
//pol_flg(&p_flgptn, GUI_EVENTID, 0x111, TWF_ORW);
twai_flg(&p_flgptn, GUI_EVENTID, 0x111, TWF_ORW,10);
else
wai_flg(&p_flgptn, GUI_EVENTID, 0x111, TWF_ORW);/*ros33 system calling*/
if( p_flgptn & 0x001 )
{
PenEvent = TRUE;
clr_flg(GUI_EVENTID,0x110);
}
else if( p_flgptn & 0x010 )
{
KeyEvent = TRUE;
clr_flg(GUI_EVENTID,0x101);
}
else
IsTimeOut = TRUE;
}
/*if pen event occured or if pen is down*/
if( IsPenDown || PenEvent )
{
if(UpdateMouse())/*update the Mouse or TP data;if no data read, return 0*/
{
retvalue |= IAL_MOUSEEVENT;
return retvalue;
}
}
/*if key event occured or if key is down*/
if( KeyEvent )
{
if(UpdateKeyboard())/*update the key data;if no data read,return 0;but this can not be occured*/
{
retvalue |= IAL_KEYEVENT;
return retvalue;
}
}
if( IsTimeOut )
{
return 0;
}
}
}
T_IAL_Input *tpIAL_Input;
T_IAL_Input tIAL_Input = {
UpdateMouse,
GetMouseX,
GetMouseY,
SetMouseXY,
GetMouseButton,
SetMouseRange,
SuspendMouse,
ResumeMouse,
UpdateKeyboard,
GetKeyboardState,
SuspendKeyboard,
ResumeKeyboard,
SetLeds,
WaitEvent
};
/******************************************************************
* FUNCTION: fnIAL_InitInput
*
* PURPOSE:
* The function initializes input device
*
* PARAMETERS
* Input:
* Output:
* InOut:
*
* Return value:
*
* Reentrant : No
*****************************************************************/
T_VOID fnIAL_InitInput(T_VOID)
{
IsPenDown = FALSE;
IsKeyDown = FALSE;
tpIAL_Input = &tIAL_Input;
fnIHL_InitMouse();
fnIHL_InitKeyboard();
wXPos = 0;
wXPos = 0;
wButtons = 0;
wMinX = 0;
wMaxX = (wGAL_WidthPhyGc) - 2;
wMinY = 0;
wMaxY = (wGAL_HeightPhyGc) - 2;
memset((T_VOID*)ubState,0,IAL_NR_KEYS);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -