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

📄 mou_ps2.c

📁 一个linux下的根文件系统的源码
💻 C
字号:
#include <stdio.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#include "device.h"#define	SCALE		3	/* default scaling factor for acceleration */#define	THRESH		5	/* default threshhold for acceleration */#define PS2_SCALE	230	/* Set 1:1 scale factor */#define PS2_ENABLE	244	/* Enable PS/2 device */#define PS2_DEFAULT	246	/* Set default settings *//* Make sure the mouse is enabled and in a sane state */static unsigned char InitPs2[] = { PS2_DEFAULT, PS2_SCALE, PS2_ENABLE };#define	SCALE		3	/* default scaling factor for acceleration */#define	THRESH		5	/* default threshhold for acceleration */#define PS2_DEV_FILE	"/dev/input/mouse0"//#define PS2_DEV_FILE	"/dev/psaux"static int  	PS2_Open(MOUSEDEVICE *pmd);static void 	PS2_Close(void);static int  	PS2_GetButtonInfo(void);static void	MOU_GetDefaultAccel(int *pscale,int *pthresh);static int  	PS2_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);MOUSEDEVICE mousedev = {	PS2_Open,	PS2_Close,	PS2_GetButtonInfo,	MOU_GetDefaultAccel,	PS2_Read,	NULL};static int mouse_fd;/* * Open up the mouse device. * Returns the fd if successful, or negative if unsuccessful. */static intPS2_Open(MOUSEDEVICE *pmd){	//mouse_fd = open (PS2_DEV_FILE, O_RDONLY | O_NOCTTY | O_NONBLOCK);	mouse_fd = open (PS2_DEV_FILE, O_RDONLY | O_NOCTTY | O_NONBLOCK);	if (mouse_fd < 0) 			return -1;	//write(mouse_fd, InitPs2, sizeof(InitPs2));	return mouse_fd;}/* * Close the mouse device. */static voidPS2_Close(void){	if (mouse_fd > 0)		close(mouse_fd);	mouse_fd = -1;}/* * Get mouse buttons supported */static intPS2_GetButtonInfo(void){	return MWBUTTON_L | MWBUTTON_M | MWBUTTON_R;}/* * Get default mouse acceleration settings */static voidMOU_GetDefaultAccel(int *pscale,int *pthresh){	*pscale = SCALE;	*pthresh = THRESH;}static intPS2_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp){	static unsigned char buf[5];	static int nbytes;	int n;	int buttons[5] = { 0, 4, 1, 5, 0};	while((n = read(mouse_fd, &buf[nbytes], 3 - nbytes))) {		if(n < 0) {			if ((errno == EINTR) || (errno == EAGAIN))				return 0;			else return -1;		}		nbytes += n;		if(nbytes == 3) {			/* Check header byte. */			if ((buf[0] & 0xc0) != 0) {				buf[0] = buf[1];				buf[1] = buf[2];				nbytes = 2;				return -1;			}			*bp = buttons[(buf[0] & 0x07)];			*dx = (buf[0] & 0x10) ? buf[1] - 256 : buf[1];			*dy = (buf[0] & 0x20) ? -(buf[2] - 256) : -buf[2];			//printf("bp = %d\n",*bp);			*dz = 0;			nbytes = 0;			return 1;		}	}	return 0;}

⌨️ 快捷键说明

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