]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/mou_fbsd.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / mou_fbsd.c
1 /* #include <stdio.h> */
2 #include <sys/types.h>
3 #include <sys/uio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <errno.h>
7
8 #include <machine/mouse.h>
9 #include <machine/console.h>
10
11 /* #include <vgl.h> */
12
13 #include "device.h"
14
15 #define SCALE 3
16 #define THRESH 5
17
18
19 static int FBSD_Open(MOUSEDEVICE *pmd);
20 static void FBSD_Close(void);
21 static int FBSD_GetButtonInfo(void);
22 static void FBSD_GetDefaultAccel(int *pscale, int *pthresh);
23 static int FBSD_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz,int *bp);
24 MOUSEDEVICE mousedev = {
25     FBSD_Open,
26     FBSD_Close,
27     FBSD_GetButtonInfo,
28     FBSD_GetDefaultAccel,
29     FBSD_Read,
30     NULL
31 };
32
33 static int mouse_fd=0;
34
35 static int FBSD_Open(MOUSEDEVICE *pmd)
36 {
37
38     mousemode_t theMouseMode;
39
40     mouse_fd=open("/dev/sysmouse",O_RDONLY);
41     if(mouse_fd < 0)
42     {
43         return(-1);
44     }
45     ioctl(mouse_fd, MOUSE_GETMODE, &theMouseMode);
46     theMouseMode.level=1;
47     ioctl(mouse_fd, MOUSE_SETMODE, &theMouseMode);
48     return mouse_fd;
49     
50 }
51
52 static void FBSD_Close(void)
53 {
54     if (mouse_fd > 0)
55     {
56         close(mouse_fd);
57     }
58     mouse_fd=0;
59
60 }
61
62 static int FBSD_GetButtonInfo(void)
63 {
64     return MWBUTTON_L | MWBUTTON_M | MWBUTTON_R;
65 }
66
67 static void FBSD_GetDefaultAccel(int *pscale, int *pthresh)
68 {
69     *pscale = SCALE;
70     *pthresh = THRESH;
71 }
72
73 extern void FBSD_handle_event(void);
74
75 static int FBSD_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz,
76                      int *bp)
77
78 {
79     mousestatus_t theStatus;
80     int butStat=0;
81     int retVal=0;
82
83     FBSD_handle_event();
84     
85     ioctl(mouse_fd,MOUSE_GETSTATUS, &theStatus);
86
87     if(theStatus.flags | MOUSE_POSCHANGED)
88     {
89         *dx=theStatus.dx;
90         *dy=theStatus.dy;
91         *dz=theStatus.dz;
92         retVal|=1;
93     }
94
95     if(theStatus.button & 0x1)
96     {
97         butStat|=MWBUTTON_L;
98         retVal|=1;
99     }
100     if(theStatus.button & 0x2)
101     {
102         butStat|=MWBUTTON_M;
103         retVal|=1;
104     }
105     if(theStatus.button & 0x4)
106     {
107         butStat|=MWBUTTON_R;
108         retVal|=1;
109     }
110         
111     *bp=butStat;
112     return retVal;
113 }