linux wireless mouse

1、下面是写的一个无线或是有线鼠标测试程序

注:有线鼠标插入linux系统中是会在/dev目录下创建一个event0文件,但是无线鼠标插上后会有两个设备文件,一个是event0,另一个是event1;

/********************************************************************************* *      Copyright:  (C) 2014 fulinux<fulinux@sina.com>  *                  All rights reserved. * *       Filename:  mice_test.c *    Description:  This file  *                  *        Version:  1.0.0(01/23/2014~) *         Author:  fulinux <fulinux@sina.com> *      ChangeLog:  1, Release initial version on "01/23/2014 09:43:04 PM" *                  ********************************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/time.h>#include <sys/mman.h>#include <sys/ioctl.h>#include <linux/input.h>#define WIRELESS_MOUSE#ifdef WIRELESS_MOUSE    #define DEV_MOUSE "/dev/event1"#else    #define DEV_MOUSE "/dev/event0"#endifstruct mousedev_motion{    int dx, dy, dz;    unsigned long buttons;    unsigned short abs_x;    unsigned short abs_y;}event;typedef struct mouse_data{    unsigned char key;    signed short x;    signed short y;                                                                                                                        signed short z;    unsigned short ax;    unsigned short ay;}MOUSE_DATA;/******************************************************************************** *  Description: *   Input Args: *  Output Args: * Return Value: ********************************************************************************/int main (int argc, char **argv){    int fd;    MOUSE_DATA pdata;    if((fd = open(DEV_MOUSE, O_RDONLY)) < 0)    {        printf ("open mice device failed!\n");        exit(1);    }    while(1)    {        int ret;        ret = read(fd, &event, sizeof(struct mousedev_motion));        if(ret < 0)        {            printf ("read mouse failed\n");            exit(1);        }        else        {            pdata.key = (event.buttons & 0x7);            pdata.x = (short)event.dx;            pdata.y = (short)-event.dy;            pdata.z = (short)event.dz;            /* absolute coordinates */            pdata.ax = event.abs_x;            pdata.ay = event.abs_y;            printf ("key = 0x%02x x = 0x%02x, y = 0x%02x, z = 0x%02x\n",                    (char)pdata.key, (char)pdata.x, (char)pdata.y, (char)pdata.z);        }    }    return 0;} /* ----- End of main() ----- */

2、下面是一个makefile文件:

注:如果你的ARCH不是arn,还有CROSS_COMPILE不是下面的那个,请修改。

#*********************************************************************************#      Copyright:  (C) 2011 China Undergraduate Embedded League(CUEL)#                  All rights reserved.##       Filename:  Makefile#    Description:  This Makefile used to compile all the C source code file in current #                  folder to respective excutable binary files.#                      #        Version:  1.0.0(1/24/2014)#                  Author:   fulinux<fulinux@gmail.com>#      ChangeLog:  1, Release initial version on "1/24/2014 12:29:33 PM"#                       #********************************************************************************/PWD=$(shell pwd)INSTPATH=/mnt/nfs#ARCH?=i386ARCH?=armLINK_MODE=STATICMODE=PRODUCTIONDEBUG=1#LDFLAGS+=-lpthreadCFLAGS+=-Wall -Werrorifeq ("${MODE}", "PRODUCTION")    CFLAGS+=-DPRODUCTION_MODEendififdef DEBUG    CFLAGS+=-g -DDEBUGendifCOMPILE_DATE=$(shell date -u +"%Y-%m-%d %H:%M")VPATH= .SRCS = $(wildcard ${VPATH}/*.c)OBJS = $(patsubst %.c,%.o,$(SRCS))TMP=$(shell echo $(ARCH) | tr "[A-Z]" "[a-z]")ifneq (,$(filter i386,$(TMP)))    CROSS_COMPILE=else    CROSS_COMPILE=arm-hisiv100nptl-linux-endifCFLAGS+=-I`dirname ${PWD}`export CC=${CROSS_COMPILE}gccexport CXX=${CROSS_COMPILE}gccexport AR=${CROSS_COMPILE}arexport AS=${CROSS_COMPILE}asexport RANLIB=${CROSS_COMPILE}ranlibexport STRIP=${CROSS_COMPILE}stripexport CFLAGSexport LDFLAGSexport ARCH                                                                                                                         export LINK_MODEifeq ("${LINK_MODE}", "STATIC")    CFLAGS+=--static    LDFLAGS+=-staticelse    LDFLAGS+=-ldlendifSRCFILES = $(wildcard *.c)BINARIES=$(SRCFILES:%.c=%)all: entry version binaries installentry:     @echo " ";    @echo " =========================================================";    @echo " **        Compile \&;${BINARIES}\&; for ${ARCH}         ";    @echo " =========================================================";version:    @echo "/* Generated by makefile, don't Edit it by hand */" > version.h     @echo "#define DATE \&;$(COMPILE_DATE)\&;" >> version.h     @echo "#define MAJOR 1" >>version.h     @echo "#define MINOR 0" >>version.h     @echo "#define REVER 0" >>version.h     @if [ -f .svn/entries ] ; then \        echo "#define SVNVER `sed -n -e 11p .svn/entries`" >>version.h; \    else \        echo "#define SVNVER 0" >>version.h; \    fi;binaries:  ${BINARIES}    @echo " Compile over"%:  %.c    $(CC) -o $@ $< $(CFLAGS)tag:     @ctags --c-kinds=+defglmnstuvx --langmap=c:.c.h.ho.hem.het.hec.hev.him.hit.hic.hiv -R .      @cscope -Rbqinstall:    cp $(BINARIES) ${INSTPATH}clean:     @rm -f version.h     @rm -f *.o $(BINARIES)     @rm -rf *.gdb *.a *.so *.elf*distclean: clean    @rm -f  tags cscope*.PHONY: clean entry

3、下面是一个测试效果:

# cat /proc/bus/input/devicesI: Bus=0003 Vendor=062a Product=4101 Version=0110N: Name="MOSART Semi. 2.4G Keyboard Mouse"P: Phys=usb-hiusb-ohci-1/input0S: Sysfs=/devices/platform/hiusb-ohci.0/usb2/2-1/2-1:1.0/input/input3U: Uniq=H: Handlers=kbd event0B: PROP=0B: EV=120013B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffeB: MSC=10B: LED=7I: Bus=0003 Vendor=062a Product=4101 Version=0110N: Name="MOSART Semi. 2.4G Keyboard Mouse"P: Phys=usb-hiusb-ohci-1/input1S: Sysfs=/devices/platform/hiusb-ohci.0/usb2/2-1/2-1:1.1/input/input4U: Uniq=H: Handlers=kbd mouse0 event1B: PROP=0B: EV=1fB: KEY=4837fff 72ff32d bf544446 0 0 1f0001 20f90 8b17c000 677bfa d941dfed 9ed680 4400 0 10000002B: REL=1c3B: ABS=1f01 0B: MSC=10

# ./mice_testkey = 0x01 x = 0x3d, y = 0xff, z = 0x02key = 0x00 x = 0x3d, y = 0xf8, z = 0x00key = 0x05 x = 0x3e, y = 0x61, z = 0x02key = 0x00 x = 0x3e, y = 0x59, z = 0x00key = 0x07 x = 0x3e, y = 0x2f, z = 0x02key = 0x00 x = 0x3e, y = 0x28, z = 0x00key = 0x04 x = 0x3e, y = 0xf1, z = 0x02key = 0x07 x = 0x3e, y = 0xed, z = 0x02key = 0x00 x = 0x3e, y = 0xe7, z = 0x00key = 0x05 x = 0x3e, y = 0xb2, z = 0x02key = 0x02 x = 0x3e, y = 0xaf, z = 0x02key = 0x00 x = 0x3e, y = 0xa9, z = 0x00key = 0x06 x = 0x3e, y = 0x70, z = 0x02key = 0x02 x = 0x3e, y = 0x6c, z = 0x02

4、答疑解惑

event0,event1和mice设备是什么关系?听我们老板说以前是用mice,后来使用event0这是什么原因?还有内核中鼠标驱动是在哪里入手?

MISC是一类设备,U盘属于USB类,SD卡属于SD卡类,他们都有一类总线那么对于LED, 按键这些东西没有一类,所以都可以把它们放到MISC里去。

event是事件设备,他可以包括鼠标,键盘,按键,操作杆等输入设备。这两个都是event事件的设备。无线鼠标是USB设备,USB设备有很多类。要搞清楚无线鼠标,就要知道USB设备驱动,设备是怎么发现,注册的;然后学习input设备驱动模型

有木有相关文档博文推荐呢?

http://mcuos.com/thread-8384-1-2.html

记忆的屏障,曾经心动的声音已渐渐远去。

linux wireless mouse

相关文章:

你感兴趣的文章:

标签云: