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

📄 mou_ps2.c

📁 在ecos 下mingui 的移植开发
💻 C
字号:
/* * ps/2 Mouse Driver *  By Song Lixin 2000/11/17  * Take examples of MicroWindows and LibGGI. */#include <stdio.h>#include <errno.h>#include <unistd.h>#include <fcntl.h>#include "common.h"#include "misc.h"#include "ial.h"#include "gal.h"#include "native.h"#define	SCALE		3	/* default scaling factor for acceleration */#define	THRESH		5	/* default threshhold for acceleration */#define PS2_SCALE11	230	/* Set 1:1 scale factor */#define PS2_SCALE21	231	/* Set 2:1 scale factor */#define PS2_SETRES	232	/* Set resolution */#define PS2_GETSCALE	233	/* Get scale factor */#define PS2_SETSTREAM	234	/* Set stream mode */#define PS2_SETSAMPLE	243	/* Set sample rate */#define PS2_ENABLE	244	/* Enable PS/2 device */#define PS2_DISABLE	245	/* Disable PS/2 device */#define PS2_DEFAULT	246	/* Set default settings */#define PS2_RESET	255	/* Reset PS/2 device */#define PS2_DEV_FILE	"/dev/psaux"static gal_uint8 initdata_ps2[] = /* Make sure the mouse is enabled and in a sane state */{ PS2_DEFAULT, PS2_SCALE11, PS2_ENABLE };static int  	PS2_Open(void);static void 	PS2_Close(void);static int  	PS2_GetButtonInfo(void);static void		PS2_GetDefaultAccel(int *pscale,int *pthresh);static int  	PS2_Read(int *dx, int *dy, int *dz, int *bp);MOUSEDEVICE mousedev_PS2 = {	PS2_Open,	PS2_Close,	PS2_GetButtonInfo,	PS2_GetDefaultAccel,	PS2_Read};static int mouse_fd;/* * Open up the mouse device. * Returns the fd if successful, or negative if unsuccessful. */static int PS2_Open(void){	mouse_fd = open (PS2_DEV_FILE, O_RDONLY | O_NOCTTY | O_NONBLOCK);	if (mouse_fd < 0) 			return -1;	write(mouse_fd, initdata_ps2, sizeof(initdata_ps2));	return mouse_fd;}/* * Close the mouse device. */static void PS2_Close(void){	if (mouse_fd > 0)		close(mouse_fd);	mouse_fd = 0;}/* * Get mouse buttons supported */static int PS2_GetButtonInfo(void){	return BUTTON_L | BUTTON_M | BUTTON_R;}/* * Get default mouse acceleration settings */static void PS2_GetDefaultAccel(int *pscale,int *pthresh){	*pscale = SCALE;	*pthresh = THRESH;}/* * Attempt to read bytes from the mouse and interpret them. * Returns -1 on error, 0 if either no bytes were read or not enough * was read for a complete state, or 1 if the new state was read. * When a new state is read, the current buttons and x and y deltas * are returned.  This routine does not block. */static int PS2_Read(int *dx, int *dy, int *dz, int *bp){	static unsigned char buf[3];	static int nbytes;	int n;	int buttons[4] = { 0, 4, 1, 5};	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];			*dz = 0;			nbytes = 0;			return 1;		}	}	return 0;}

⌨️ 快捷键说明

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