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

📄 event.c

📁 uboot在arm处理器s3c2410的移植代码
💻 C
📖 第 1 页 / 共 3 页
字号:
		axis[3] = js.y;	    mask |= EVT_JOY_AXIS_X2|EVT_JOY_AXIS_Y2;	    }	}    else {	if (axis0) {	    if (jmask & EVT_JOY_AXIS_X1)		axis[0] = axis0[0];	    if (jmask & EVT_JOY_AXIS_Y1)		axis[1] = axis0[1];	    mask |= EVT_JOY_AXIS_X1 | EVT_JOY_AXIS_Y1;	    }	if (axis1) {	    if (jmask & EVT_JOY_AXIS_X2)		axis[2] = axis1[0];	    if (jmask & EVT_JOY_AXIS_Y2)		axis[3] = axis1[1];	    mask |= EVT_JOY_AXIS_X2 | EVT_JOY_AXIS_Y2;	    }	}    return mask;}/****************************************************************************REMARKS:Read the joystick button data****************************************************************************/int EVTAPI _EVT_readJoyButtons(void){    int buts = 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)	    buts = js.buttons;	if (joystick1_fd && read(joystick1_fd, &js, JS_RETURN) == JS_RETURN)	    buts |= js.buttons << 2;	}    else {	if (buts0)	    buts |= EVT_JOY1_BUTTONA*buts0[0] + EVT_JOY1_BUTTONB*buts0[1];	if (buts1)	    buts |= EVT_JOY2_BUTTONA*buts1[0] + EVT_JOY2_BUTTONB*buts1[1];	}    return buts;}/****************************************************************************DESCRIPTION:Returns the mask indicating what joystick axes are attached.HEADER:event.hREMARKS:This function is used to detect the attached joysticks, and determinewhat axes are present and functioning. This function will re-detect anyattached joysticks when it is called, so if the user forgot to attachthe joystick when the application started, you can call this function tore-detect any newly attached joysticks.SEE ALSO:EVT_joySetLowerRight, EVT_joySetCenter, EVT_joyIsPresent****************************************************************************/int EVTAPI EVT_joyIsPresent(void){    static int      mask = 0;    int             i;    char            *tmp, name0[128], name1[128];    static ibool    inited = false;    if (inited)	return mask;    memset(EVT.joyMin,0,sizeof(EVT.joyMin));    memset(EVT.joyCenter,0,sizeof(EVT.joyCenter));    memset(EVT.joyMax,0,sizeof(EVT.joyMax));    memset(EVT.joyPrev,0,sizeof(EVT.joyPrev));    EVT.joyButState = 0;    if ((tmp = getenv(ENV_JOYDEV0)) != NULL)	strcpy(joystick0_dev,tmp);    if ((tmp = getenv(ENV_JOYDEV1)) != NULL)	strcpy(joystick1_dev,tmp);    if ((joystick0_fd = open(joystick0_dev, O_RDONLY)) < 0)	joystick0_fd = 0;    if ((joystick1_fd = open(joystick1_dev, O_RDONLY)) < 0)	joystick1_fd = 0;    if (!joystick0_fd && !joystick1_fd) /* No joysticks detected */	return 0;    inited = true;    if (ioctl(joystick0_fd ? joystick0_fd : joystick1_fd, JSIOCGVERSION, &js_version) < 0)	return 0;    /* Initialise joystick 0 */    if (joystick0_fd) {	ioctl(joystick0_fd, JSIOCGNAME(sizeof(name0)), name0);	if (js_version & ~0xffff) {	    struct js_event js;	    ioctl(joystick0_fd, JSIOCGAXES, &js0_axes);	    ioctl(joystick0_fd, JSIOCGBUTTONS, &js0_buttons);	    axis0 = PM_calloc((int)js0_axes, sizeof(short));	    buts0 = PM_malloc((int)js0_buttons);	    /* Read the initial events */	    while(dataReady(joystick0_fd)		  && read(joystick0_fd, &js, sizeof(struct js_event)) == sizeof(struct js_event)		  && (js.type & JS_EVENT_INIT)		  ) {		if (js.type & JS_EVENT_BUTTON)		    buts0[js.number] = js.value;		else if (js.type & JS_EVENT_AXIS)		    axis0[js.number] = scaleJoyAxis(js.value,js.number);		}	    }	else {	    js0_axes = 2;	    js0_buttons = 2;	    axis0 = PM_calloc((int)js0_axes, sizeof(short));	    buts0 = PM_malloc((int)js0_buttons);	    }	}    /* Initialise joystick 1 */    if (joystick1_fd) {	ioctl(joystick1_fd, JSIOCGNAME(sizeof(name1)), name1);	if (js_version & ~0xffff) {	    struct js_event js;	    ioctl(joystick1_fd, JSIOCGAXES, &js1_axes);	    ioctl(joystick1_fd, JSIOCGBUTTONS, &js1_buttons);	    axis1 = PM_calloc((int)js1_axes, sizeof(short));	    buts1 = PM_malloc((int)js1_buttons);	    /* Read the initial events */	    while(dataReady(joystick1_fd)		  && read(joystick1_fd, &js, sizeof(struct js_event))==sizeof(struct js_event)		  && (js.type & JS_EVENT_INIT)		  ) {		if (js.type & JS_EVENT_BUTTON)		    buts1[js.number] = js.value;		else if (js.type & JS_EVENT_AXIS)		    axis1[js.number] = scaleJoyAxis(js.value,js.number<<2);		}	    }	else {	    js1_axes = 2;	    js1_buttons = 2;	    axis1 = PM_calloc((int)js1_axes, sizeof(short));	    buts1 = PM_malloc((int)js1_buttons);	    }	}#ifdef  CHECKED    fprintf(stderr,"Using joystick driver version %d.%d.%d\n",	    js_version >> 16, (js_version >> 8) & 0xff, js_version & 0xff);    if (joystick0_fd)	fprintf(stderr,"Joystick 1 (%s): %s\n", joystick0_dev, name0);    if (joystick1_fd)	fprintf(stderr,"Joystick 2 (%s): %s\n", joystick1_dev, name1);#endif    mask = _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyCenter);    if (mask) {	for (i = 0; i < JOY_NUM_AXES; i++)	    EVT.joyMax[i] = EVT.joyCenter[i]*2;	}    return mask;}/****************************************************************************DESCRIPTION:Polls the joystick for position and button information.HEADER:event.hREMARKS:This routine is used to poll analogue joysticks for button and positioninformation. It should be called once for each main loop of the userapplication, just before processing all pending events via EVT_getNext.All information polled from the joystick will be posted to the eventqueue for later retrieval.Note:   Most analogue joysticks will provide readings that change even	though the joystick has not moved. Hence if you call this routine	you will likely get an EVT_JOYMOVE event every time through your	event loop.SEE ALSO:EVT_getNext, EVT_peekNext, EVT_joySetUpperLeft, EVT_joySetLowerRight,EVT_joySetCenter, EVT_joyIsPresent****************************************************************************/void EVTAPI EVT_pollJoystick(void){    event_t evt;    int     i,axis[JOY_NUM_AXES],newButState,mask,moved,ps;    if ((js_version & ~0xFFFF) == 0 && EVT.joyMask) {	/* Read joystick axes and post movement events if they have	 * changed since the last time we polled. Until the events are	 * actually flushed, we keep modifying the same joystick movement	 * event, so you won't get multiple movement event	 */	mask = _EVT_readJoyAxis(EVT.joyMask,axis);	newButState = _EVT_readJoyButtons();	moved = false;	for (i = 0; i < JOY_NUM_AXES; i++) {	    if (mask & (EVT_JOY_AXIS_X1 << i))		axis[i] = scaleJoyAxis(axis[i],i);	    else		axis[i] = EVT.joyPrev[i];	    if (axis[i] != EVT.joyPrev[i])		moved = true;	    }	if (moved) {	    memcpy(EVT.joyPrev,axis,sizeof(EVT.joyPrev));	    ps = _EVT_disableInt();	    if (EVT.oldJoyMove != -1) {		/* Modify the existing joystick movement event */		EVT.evtq[EVT.oldJoyMove].message = newButState;		EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0];		EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1];		EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2];		EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3];		}	    else if (EVT.count < EVENTQSIZE) {		/* Add a new joystick movement event */		EVT.oldJoyMove = EVT.freeHead;		memset(&evt,0,sizeof(evt));		evt.what = EVT_JOYMOVE;		evt.message = EVT.joyButState;		evt.where_x = EVT.joyPrev[0];		evt.where_y = EVT.joyPrev[1];		evt.relative_x = EVT.joyPrev[2];		evt.relative_y = EVT.joyPrev[3];		addEvent(&evt);		}	    _EVT_restoreInt(ps);	    }	/* Read the joystick buttons, and post events to reflect the change	 * in state for the joystick buttons.	 */	if (newButState != EVT.joyButState) {	    if (EVT.count < EVENTQSIZE) {		/* Add a new joystick movement event */		ps = _EVT_disableInt();		memset(&evt,0,sizeof(evt));		evt.what = EVT_JOYCLICK;		evt.message = newButState;		EVT.evtq[EVT.oldJoyMove].where_x = EVT.joyPrev[0];		EVT.evtq[EVT.oldJoyMove].where_y = EVT.joyPrev[1];		EVT.evtq[EVT.oldJoyMove].relative_x = EVT.joyPrev[2];		EVT.evtq[EVT.oldJoyMove].relative_y = EVT.joyPrev[3];		addEvent(&evt);		_EVT_restoreInt(ps);		}	    EVT.joyButState = newButState;	    }	}}/****************************************************************************DESCRIPTION:Calibrates the joystick upper left positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the upper leftposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joyIsPresent****************************************************************************/void EVTAPI EVT_joySetUpperLeft(void){    _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMin);}/****************************************************************************DESCRIPTION:Calibrates the joystick lower right positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the lower rightposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetCenter, EVT_joyIsPresent****************************************************************************/void EVTAPI EVT_joySetLowerRight(void){    _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyMax);}/****************************************************************************DESCRIPTION:Calibrates the joystick center positionHEADER:event.hREMARKS:This function can be used to zero in on better joystick calibration factors,which may work better than the default simplistic calibration (which assumesthe joystick is centered when the event library is initialised).To use this function, ask the user to hold the stick in the centerposition and then have them press a key or button. and then call thisfunction. This function will then read the joystick and update thecalibration factors.Usually, assuming that the stick was centered when the event library wasinitialized, you really only need to call EVT_joySetLowerRight since theupper left position is usually always 0,0 on most joysticks. However, thesafest procedure is to call all three calibration functions.SEE ALSO:EVT_joySetUpperLeft, EVT_joySetLowerRight, EVT_joySetCenter****************************************************************************/void EVTAPI EVT_joySetCenter(void){    _EVT_readJoyAxis(EVT_JOY_AXIS_ALL,EVT.joyCenter);}#endif/****************************************************************************REMARKS:Pumps all messages in the message queue from Linux into our event queue.****************************************************************************/static void _EVT_pumpMessages(void){    event_t                 evt;    int                     i,numkeys, c;    ibool                   release;    static struct kbentry   ke;    static char             buf[KBDREADBUFFERSIZE];    static ushort           repeatKey[128] = {0};    /* Poll keyboard events */    while (dataReady(_PM_console_fd) && (numkeys = read(_PM_console_fd, buf, KBDREADBUFFERSIZE)) > 0) {	for (i = 0; i < numkeys; i++) {	    c = buf[i];	    release = c & 0x80;	    c &= 0x7F;	    /* TODO:    This is wrong! We need this to be the time stamp at */	    /*          ** interrupt ** time!! One solution would be to */	    /*          put the keyboard and mouse polling loops into */	    /*          a separate thread that can block on I/O to the */	    /*          necessay file descriptor. */	    evt.when = _EVT_getTicks();	    if (release) {		/* Key released */		evt.what = EVT_KEYUP;		switch (c) {		    case KB_leftShift:			_PM_modifiers &= ~EVT_LEFTSHIFT;			break;		    case KB_rightShift:			_PM_modifiers &= ~EVT_RIGHTSHIFT;			break;		    case 29:			_PM_modifiers &= ~(EVT_LEFTCTRL|EVT_CTRLSTATE);			break;		    case 97:            /* Control */			_PM_modifiers &= ~EVT_CTRLSTATE;			break;		    case 56:			_PM_modifiers &= ~(EVT_LEFTALT|EVT_ALTSTATE);			break;		    case 100:			_PM_modifiers &= ~EVT_ALTSTATE;			break;		    default:		    }		evt.modifiers = _PM_modifiers;		evt.message = keyUpMsg[c];		if (EVT.count < EVENTQSIZE)		    addEvent(&evt);		keyUpMsg[c] = 0;		repeatKey[c] = 0;		}	    else {		/* Key pressed */		evt.what = EVT_KEYDOWN;		switch (c) {		    case KB_leftShift:			_PM_modifiers |= EVT_LEFTSHIFT;			break;		    case KB_rightShift:			_PM_modifiers |= EVT_RIGHTSHIFT;			break;		    case 29:			_PM_modifiers |= EVT_LEFTCTRL|EVT_CTRLSTATE;			break;		    case 97:            /* Control */			_PM_modifiers |= EVT_CTRLSTATE;			break;		    case 56:			_PM_modifiers |= EVT_LEFTALT|EVT_ALTSTATE;			break;		    case 100:			_PM_modifiers |= EVT_ALTSTATE;			break;		    case KB_capsLock:   /* Caps Lock */			_PM_leds ^= LED_CAP;			ioctl(_PM_console_fd, KDSETLED, _PM_leds);			break;		    case KB_numLock:    /* Num Lock */			_PM_leds ^= LED_NUM;			ioctl(_PM_console_fd, KDSETLED, _PM_leds);			break;		    case KB_scrollLock: /* Scroll Lock */			_PM_leds ^= LED_SCR;			ioctl(_PM_console_fd, KDSETLED, _PM_leds);			break;		    default:		    }		evt.modifiers = _PM_modifiers;		if (keyUpMsg[c]) {		    evt.what = EVT_KEYREPEAT;		    evt.message = keyUpMsg[c] | (repeatKey[c]++ << 16);		    }		else {		    int asc;		    evt.message = getKeyMapping(keymaps, NB_KEYMAPS, c) << 8;		    ke.kb_index = c;		    ke.kb_table = 0;		    if ((_PM_modifiers & EVT_SHIFTKEY) || (_PM_leds & LED_CAP))

⌨️ 快捷键说明

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