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

📄 event.c

📁 uboot在arm处理器s3c2410的移植代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************                   SciTech Multi-platform Graphics Library**  ========================================================================**    The contents of this file are subject to the SciTech MGL Public*    License Version 1.0 (the "License"); you may not use this file*    except in compliance with the License. You may obtain a copy of*    the License at http://www.scitechsoft.com/mgl-license.txt**    Software distributed under the License is distributed on an*    "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or*    implied. See the License for the specific language governing*    rights and limitations under the License.**    The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.**    The Initial Developer of the Original Code is SciTech Software, Inc.*    All Rights Reserved.**  ========================================================================** Language:     ANSI C* Environment:  Linux** Description:  Linux fullscreen console implementation for the SciTech*               cross platform event library.*               Portions ripped straigth from the gpm source code for mouse*               handling.*****************************************************************************//*---------------------------- Global Variables ---------------------------*/extern int              _PM_console_fd;static ushort           keyUpMsg[256] = {0};static int              _EVT_mouse_fd = 0;static int              range_x, range_y;static int              opt_baud = 1200, opt_sample = 100;#ifdef USE_OS_JOYSTICKstatic short            *axis0 = NULL, *axis1 = NULL;static uchar            *buts0 = NULL, *buts1 = NULL;static int              joystick0_fd = 0, joystick1_fd = 0;static int              js_version = 0;#endif/* This defines the supported mouse drivers */typedef enum {    EVT_noMouse = -1,    EVT_microsoft = 0,    EVT_ps2,    EVT_mousesystems,    EVT_gpm,    EVT_MMseries,    EVT_logitech,    EVT_busmouse,    EVT_mouseman,    EVT_intellimouse,    EVT_intellimouse_ps2,    } mouse_drivers_t;static mouse_drivers_t mouse_driver = EVT_noMouse;static char mouse_dev[20] = "/dev/mouse";typedef struct {    char    *name;    int     flags;    void    (*init)(void);    uchar   proto[4];    int     packet_len;    int     read;    } mouse_info;#define STD_FLG (CREAD | CLOCAL | HUPCL)static void _EVT_mouse_init(void);static void _EVT_logitech_init(void);static void _EVT_pnpmouse_init(void);mouse_info mouse_infos[] = {    {"Microsoft",       CS7 | B1200 | STD_FLG,              _EVT_mouse_init,    {0x40, 0x40, 0x40, 0x00}, 3, 1},    {"PS2",             STD_FLG,                            NULL,               {0xc0, 0x00, 0x00, 0x00}, 3, 1},    {"MouseSystems",    CS8 | CSTOPB | STD_FLG,             _EVT_mouse_init,    {0xf8, 0x80, 0x00, 0x00}, 5, 5},    {"GPM",             CS8 | CSTOPB | STD_FLG,             NULL,               {0xf8, 0x80, 0x00, 0x00}, 5, 5},    {"MMSeries",        CS8 | PARENB | PARODD | STD_FLG,    _EVT_mouse_init,    {0xe0, 0x80, 0x80, 0x00}, 3, 1},    {"Logitech",        CS8 | CSTOPB | STD_FLG,             _EVT_logitech_init, {0xe0, 0x80, 0x80, 0x00}, 3, 3},    {"BusMouse",        STD_FLG,                            NULL,               {0xf8, 0x80, 0x00, 0x00}, 3, 3},    {"MouseMan",        CS7 | STD_FLG,                      _EVT_mouse_init,    {0x40, 0x40, 0x40, 0x00}, 3, 1},    {"IntelliMouse",    CS7 | STD_FLG,                      _EVT_pnpmouse_init, {0xc0, 0x40, 0xc0, 0x00}, 4, 1},    {"IMPS2",           CS7 | STD_FLG,                      NULL,               {0xc0, 0x40, 0xc0, 0x00}, 4, 1}, /* ? */    };#define NB_MICE (sizeof(mouse_infos)/sizeof(mouse_info))/* The name of the environment variables that are used to change the defaults above */#define ENV_MOUSEDRV "MGL_MOUSEDRV"#define ENV_MOUSEDEV "MGL_MOUSEDEV"#define ENV_MOUSESPD "MGL_MOUSESPD"#define ENV_JOYDEV0  "MGL_JOYDEV1"#define ENV_JOYDEV1  "MGL_JOYDEV2"/* Scancode mappings on Linux for special keys */typedef struct {    int scan;    int map;    } keymap;/* TODO: Fix this and set it up so we can do a binary search! */keymap keymaps[] = {    {96, KB_padEnter},    {74, KB_padMinus},    {78, KB_padPlus},    {55, KB_padTimes},    {98, KB_padDivide},    {71, KB_padHome},    {72, KB_padUp},    {73, KB_padPageUp},    {75, KB_padLeft},    {76, KB_padCenter},    {77, KB_padRight},    {79, KB_padEnd},    {80, KB_padDown},    {81, KB_padPageDown},    {82, KB_padInsert},    {83, KB_padDelete},    {105,KB_left},    {108,KB_down},    {106,KB_right},    {103,KB_up},    {110,KB_insert},    {102,KB_home},    {104,KB_pageUp},    {111,KB_delete},    {107,KB_end},    {109,KB_pageDown},    {125,KB_leftWindows},    {126,KB_rightWindows},    {127,KB_menu},    {100,KB_rightAlt},    {97,KB_rightCtrl},    };/* And the keypad with num lock turned on (changes the ASCII code only) */keymap keypad[] = {    {71, ASCII_7},    {72, ASCII_8},    {73, ASCII_9},    {75, ASCII_4},    {76, ASCII_5},    {77, ASCII_6},    {79, ASCII_1},    {80, ASCII_2},    {81, ASCII_3},    {82, ASCII_0},    {83, ASCII_period},    };#define NB_KEYMAPS (sizeof(keymaps)/sizeof(keymaps[0]))#define NB_KEYPAD (sizeof(keypad)/sizeof(keypad[0]))typedef struct {    int     sample;    char    code[2];    } sample_rate;sample_rate sampletab[]={    {  0,"O"},    { 15,"J"},    { 27,"K"},    { 42,"L"},    { 60,"R"},    { 85,"M"},    {125,"Q"},    {1E9,"N"},    };/* Number of keycodes to read at a time from the console */#define KBDREADBUFFERSIZE 32/*---------------------------- Implementation -----------------------------*//* These are not used under Linux */#define _EVT_disableInt()       1#define _EVT_restoreInt(flaps)/****************************************************************************PARAMETERS:scanCode    - Scan code to testREMARKS:This macro determines if a specified key is currently down at thetime that the call is made.****************************************************************************/#define _EVT_isKeyDown(scanCode)    (keyUpMsg[scanCode] != 0)/****************************************************************************REMARKS:This function is used to return the number of ticks since systemstartup in milliseconds. This should be the same value that is placed intothe time stamp fields of events, and is used to implement auto mouse downevents.****************************************************************************/ulong _EVT_getTicks(void){    static uint     starttime = 0;    struct timeval  t;    gettimeofday(&t, NULL);    if (starttime == 0)      starttime = t.tv_sec * 1000 + (t.tv_usec/1000);    return ((t.tv_sec * 1000 + (t.tv_usec/1000)) - starttime);}/****************************************************************************REMARKS:Small Unix function that checks for availability on a file using select()****************************************************************************/static ibool dataReady(    int fd){    static struct timeval   t = { 0L, 0L };    fd_set                  fds;    FD_ZERO(&fds);    FD_SET(fd, &fds);    return select(fd+1, &fds, NULL, NULL, &t) > 0;}/****************************************************************************REMARKS:Reads mouse data according to the selected mouse driver.****************************************************************************/static ibool readMouseData(    int *buttons,    int *dx,    int *dy){    static uchar    data[32],prev = 0;    int             cnt = 0,ret;    mouse_info      *drv;    /* Read the first byte to check for the protocol */    drv = &mouse_infos[mouse_driver];    if (read(_EVT_mouse_fd, data, drv->read) != drv->read) {	perror("read");	return false;	}    if ((data[0] & drv->proto[0]) != drv->proto[1])	return false;    /* Load a whole protocol packet */    cnt += drv->read;    while (cnt < drv->packet_len) {	ret = read(_EVT_mouse_fd, data+cnt, drv->read);	if (ret == drv->read)	    cnt += ret;	else {	    perror("read");	    return false;	    }	}    if ((data[1] & drv->proto[2]) != drv->proto[3])	return false;    /* Now decode the protocol packet */    switch (mouse_driver) {	case EVT_microsoft:	    if (data[0] == 0x40 && !(prev|data[1]|data[2]))		*buttons = 2;   /* Third button on MS compatible mouse */	    else		*buttons= ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4);	    prev = *buttons;	    *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F));	    *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F));	    break;	case EVT_ps2:	    *buttons = !!(data[0]&1) * 4 + !!(data[0]&2) * 1 + !!(data[0]&4) * 2;	    if (data[1] != 0)		*dx = (data[0] & 0x10) ? data[1]-256 : data[1];	    else		*dx = 0;	    if (data[2] != 0)		*dy = -((data[0] & 0x20) ? data[2]-256 : data[2]);	    else		*dy = 0;	    break;	case EVT_mousesystems: case EVT_gpm:	    *buttons = (~data[0]) & 0x07;	    *dx = (char)(data[1]) + (char)(data[3]);	    *dy = -((char)(data[2]) + (char)(data[4]));	    break;	case EVT_logitech:	    *buttons= data[0] & 0x07;	    *dx = (data[0] & 0x10) ?   data[1] : - data[1];	    *dy = (data[0] & 0x08) ? - data[2] :   data[2];	    break;	case EVT_busmouse:	    *buttons= (~data[0]) & 0x07;	    *dx = (char)data[1];	    *dy = -(char)data[2];	    break;	case EVT_MMseries:	    *buttons = data[0] & 0x07;	    *dx = (data[0] & 0x10) ?   data[1] : - data[1];	    *dy = (data[0] & 0x08) ? - data[2] :   data[2];	    break;	case EVT_intellimouse:	    *buttons = ((data[0] & 0x20) >> 3)  /* left */		     | ((data[3] & 0x10) >> 3)  /* middle */		     | ((data[0] & 0x10) >> 4); /* right */	    *dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F));	    *dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F));	    break;	case EVT_intellimouse_ps2:	    *buttons = (data[0] & 0x04) >> 1 /* Middle */		| (data[0] & 0x02) >> 1 /* Right */		| (data[0] & 0x01) << 2; /* Left */	    *dx = (data[0] & 0x10) ?    data[1]-256  :  data[1];	    *dy = (data[0] & 0x20) ?  -(data[2]-256) : -data[2];	    break;	case EVT_mouseman: {	    static int      getextra;	    static uchar    prev=0;	    uchar           b;	    /* The damned MouseMan has 3/4 bytes packets. The extra byte	     * is only there if the middle button is active.	     * I get the extra byte as a packet with magic numbers in it.	     * and then switch to 4-byte mode.	     */	    if (data[1] == 0xAA && data[2] == 0x55) {		/* Got unexpected fourth byte */		if ((b = (*data>>4)) > 0x3)		    return false;  /* just a sanity check */		*dx = *dy = 0;		drv->packet_len=4;		getextra=0;		}	    else {		/* Got 3/4, as expected */		/* Motion is independent of packetlen... */		*dx = (char)(((data[0] & 0x03) << 6) | (data[1] & 0x3F));		*dy = (char)(((data[0] & 0x0C) << 4) | (data[2] & 0x3F));		prev = ((data[0] & 0x20) >> 3) | ((data[0] & 0x10) >> 4);		if (drv->packet_len==4)		    b = data[3]>>4;		}	    if (drv->packet_len == 4) {		if (b == 0) {		    drv->packet_len = 3;		    getextra = 1;		    }		else {		    if (b & 0x2)			prev |= 2;		    }		}	    *buttons = prev;	    /* This "chord-middle" behaviour was reported by David A. van Leeuwen */	    if (((prev ^ *buttons) & 5) == 5)		*buttons = *buttons ? 2 : 0;	    prev = *buttons;	    break;	    }	case EVT_noMouse:	    return false;	    break;	}    return true;}/****************************************************************************REMARKS:Map a keypress via the key mapping table****************************************************************************/static int getKeyMapping(    keymap *tab,    int nb,    int key){    int i;    for(i = 0; i < nb; i++) {	if (tab[i].scan == key)	    return tab[i].map;	}    return key;}#ifdef USE_OS_JOYSTICKstatic char js0_axes = 0, js0_buttons = 0;static char js1_axes = 0, js1_buttons = 0;static char joystick0_dev[20] = "/dev/js0";static char joystick1_dev[20] = "/dev/js1";/****************************************************************************REMARKS:Create a joystick event from the joystick data****************************************************************************/static void makeJoyEvent(    event_t *evt){    evt->message = 0;    if (buts0 && axis0) {	if (buts0[0]) evt->message |= EVT_JOY1_BUTTONA;	if (buts0[1]) evt->message |= EVT_JOY1_BUTTONB;	evt->where_x = axis0[0];	evt->where_y = axis0[1];	}    else	evt->where_x = evt->where_y = 0;    if (buts1 && axis1) {	if (buts1[0]) evt->message |= EVT_JOY2_BUTTONA;	if (buts1[1]) evt->message |= EVT_JOY2_BUTTONB;	evt->where_x = axis1[0];	evt->where_y = axis1[1];	}    else	evt->where_x = evt->where_y = 0;}/****************************************************************************REMARKS:Read the joystick axis data****************************************************************************/int EVTAPI _EVT_readJoyAxis(    int jmask,    int *axis){    int mask = 0;    if ((js_version & ~0xffff) == 0) {	/* Old 0.x driver */	struct JS_DATA_TYPE js;	if (joystick0_fd && read(joystick0_fd, &js, JS_RETURN) == JS_RETURN) {	    if (jmask & EVT_JOY_AXIS_X1)		axis[0] = js.x;	    if (jmask & EVT_JOY_AXIS_Y1)		axis[1] = js.y;	    mask |= EVT_JOY_AXIS_X1|EVT_JOY_AXIS_Y1;	    }	if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN) {	    if (jmask & EVT_JOY_AXIS_X2)		axis[2] = js.x;	    if (jmask & EVT_JOY_AXIS_Y2)

⌨️ 快捷键说明

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