⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comminput.c

📁 在ADS环境下MiniGUI的源码
💻 C
字号:
/*
** $Id: comminput.c,v 1.5 2005/02/03 01:06:53 xwyan Exp $
**
** comminput.c: Common Input Engine for eCos, uC/OS-II, VxWorks, ...
** 
** Copyright (C) 2004 Feynman Software
**
** Created by Zhong Shuyi, 2004/02/29
*/

/*
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>
#include <stdlib.h>

#include "common.h"

#ifdef _COMM_IAL

#include "minigui.h"
#include "misc.h"
#include "ial.h"

#include "comminput.h"

//////////////////////////////////////////////////////////////////////////////
// COMM_IAL相关函数声明 (在mgdrv-ucosii.c中实现)

extern int comm_ts_getdata (short *x, short *y, short *button);
extern int comm_kb_getdata (short *key, short *status);
extern int comm_wait_for_input(void);


/////////////////////////////////////////////////////////////////////////////

// 引擎所所需要的变量
static int MOUSEX = 0, MOUSEY = 0, MOUSEBUTTON = 0;		// 鼠标
static short KEYCODE = 0, KEYSTATUS = 0;				// 按键


// 通知底层引擎更新鼠标信息 (返回1)
static int mouse_update (void)
{
    return 1;	
}


// 获得最新的鼠标(x,y)坐标值
static void mouse_getxy (int *x, int* y)
{
    *x = MOUSEX;
    *y = MOUSEY;
}

// 获取鼠标按钮状态
// 该函数的返回值可以是IAL_MOUSE_LEFTBUTTON(表示左键按下)、
// IAL_MOUSE_MIDDLEBUTTON(表示中键按下)、IAL_MOUSE_RIGHTBUTTON
// (表示右键按下)等值"或"的结果。
static int mouse_getbutton (void)
{
    return MOUSEBUTTON;
}

/////////////////////////////////////////////////////////////////////////////

static unsigned char kbd_state[NR_KEYS];	// 键盘状态缓冲区

// 通知底层引擎更新键盘信息 (更改kbd_state数组,表明有按键)
static int keyboard_update (void)
{
    kbd_state[KEYCODE] = KEYSTATUS;
    return KEYCODE + 1;
}

// 获取键盘状态,返回一个字符数组(包括多个按键的状态),其中包含以扫描码索引的键盘按键状态。
static const char* keyboard_getstate (void)
{
    return kbd_state;
}


/////////////////////////////////////////////////////////////////////////////

static int wait_event( int which, fd_set *in, fd_set *out, fd_set *except,
                       struct timeval *timeout)
{
    int retvalue;
     
    
    retvalue = comm_wait_for_input ();	// 查询键盘或鼠标事件(需要挂起任务)
    
    if (retvalue & IAL_MOUSEEVENT) 	// 鼠标事件 
    {
        // 如果是触摸屏,则有button按键时才会更新MOUSEX、MOUSEY
        comm_ts_getdata (&MOUSEX, &MOUSEY, &MOUSEBUTTON);

        retvalue = IAL_MOUSEEVENT;
    }
    else 
    {  
    	if (retvalue & IAL_KEYEVENT) 	// 键盘事件
       	{
           	comm_kb_getdata (&KEYCODE, &KEYSTATUS);

        	if (kbd_state[KEYCODE] == KEYSTATUS) return -1;
		
           	retvalue = IAL_KEYEVENT;
       	}
       	else 
       	{
     		retvalue = -1;
       	}
    }
        
    return(retvalue);
}


/////////////////////////////////////////////////////////////////////////////
// 输入引擎的初始化函数。该函数负责对INPUT结构的其它成员赋值。
BOOL InitCOMMInput (INPUT* input, const char* mdev, const char* mtype)
{
    // 在此函数调用之前必须初始化输入设备硬件。
    // (可以在此调用初始化函数)
    
    input->update_mouse = mouse_update;
    input->get_mouse_xy = mouse_getxy;
    input->set_mouse_xy = NULL;				// 上层调用该函数可以设置鼠标位置到新的坐标值。
    input->get_mouse_button = mouse_getbutton;
    input->set_mouse_range = NULL;			// 设置鼠标的活动范围。
    input->suspend_mouse= NULL;
    input->resume_mouse = NULL;

    input->update_keyboard = keyboard_update;
    input->get_keyboard_state = keyboard_getstate;
    input->suspend_keyboard = NULL;			// 暂停键盘设备的读取,用于虚拟控制台切换。
    input->resume_keyboard = NULL;			// 继续键盘设备读取,用于虚拟控制台切换。
    input->set_leds = NULL;					// 设置键盘的锁定LED。

    input->wait_event = wait_event;			// 上层调用该函数等待底层引擎上发生输入事件

    return(TRUE);
}

// 输入引擎的终止清除函数
void TermCOMMInput (void)
{
}

#endif /* _COMM_IAL */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -