]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/services/gfx/mw/v2_0/src/drivers/mou_ps5.c
Initial revision
[karo-tx-redboot.git] / packages / services / gfx / mw / v2_0 / src / drivers / mou_ps5.c
1 /*
2  * Microwindows touch screen driver for Psion 5
3  */
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <math.h>
10 #include <sys/ioctl.h>
11 #define _LINUX_TYPES_H
12 #include <linux/fb.h>
13 #include </linux/include/asm-arm/arch/touch_psion.h>
14
15 #include "device.h"
16
17 /* file descriptor for touch panel */
18 static int pd_fd;
19
20 /* Hack extern to used when hiding the mouse cursor
21  * There needs to be a better way to do this
22 */
23 extern SCREENDEVICE scrdev;
24
25 static int PD_Open(MOUSEDEVICE *pmd)
26 {
27         /*
28          * open up the touch-panel device.
29          * Return the fd if successful, or negative if unsuccessful.
30          */
31
32         pd_fd = open("/dev/touch_psion", O_NONBLOCK);
33         if (pd_fd < 0) {
34                 fprintf(stderr, "Error %d opening touch panel\n", errno);
35                 return -1;
36         }
37
38         GdHideCursor(&scrdev);
39         return pd_fd;
40 }
41
42 static void PD_Close(void)
43 {
44         /* Close the touch panel device. */
45         fprintf(stderr,"PD_Close called\n");
46         if (pd_fd > 0)
47                 close(pd_fd);
48         pd_fd = 0;
49 }
50
51 static int PD_GetButtonInfo(void)
52 {
53         /* get "mouse" buttons supported */
54         return MWBUTTON_L;
55 }
56
57 static void PD_GetDefaultAccel(int *pscale,int *pthresh)
58 {
59         /*
60          * Get default mouse acceleration settings
61          * This doesn't make sense for a touch panel.
62          * Just return something inconspicuous for now.
63          */
64         *pscale = 3;
65         *pthresh = 5;
66 }
67
68 static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
69 {
70         /* read a data point */
71         struct touch_psion_event data;
72         int bytes_read;
73
74         bytes_read = read(pd_fd, &data, sizeof(data));
75
76         if (bytes_read != sizeof(data)) {
77                 if (errno == EINTR || errno == EAGAIN)
78                         return 0;
79                 return -1;
80         }
81
82         *px = (MWCOORD)data.x_c;
83         *py = (MWCOORD)data.y_c;
84
85         *pb = (data.down>0?MWBUTTON_L:0);
86         *pz = 0;
87
88         if((*px == -1 || *py == -1) && *pb >= 0)
89                 return 3;                       /* only have button data */
90         if((*px == -1 || *py == -1) && *pb < 0)
91                 return 0;                       /* don't have any data   */
92         return 2;                               /* have full set of data */
93 }
94
95 MOUSEDEVICE mousedev = {
96         PD_Open,
97         PD_Close,
98         PD_GetButtonInfo,
99         PD_GetDefaultAccel,
100         PD_Read,
101         NULL
102 };
103
104 #ifdef TEST
105 int main(int argc, char ** v)
106 {
107         MWCOORD         x, y, z;
108         MWBUTTON        b;
109         int result;
110         int mouse = -1;
111         printf("Opening touch panel...\n");
112
113         if((result=PD_Open(0)) < 0)
114                 printf("Error %d, result %d opening touch-panel\n", errno, result);
115
116         /* This stuff below can be used to set some of the parameters of the
117          * driver from the command line before going in to the test loop.
118          * Could this have been done better? Yup.
119          */
120
121         if(argc > 1) {
122                 ioctl(result,1,atoi(v[1]));
123                 fprintf(stderr,"Setting pressure to %d\n",atoi(v[1]));
124         } 
125         if(argc > 2) {
126                 ioctl(result,2,atoi(v[2]));
127                 fprintf(stderr,"Setting updelay to %d\n",atoi(v[2]));
128         }
129         if(argc > 3) {
130                 ioctl(result,3,atoi(v[3]));
131                 fprintf(stderr,"Setting raw x to %d\n",atoi(v[3]));
132         }
133         if(argc > 4) {
134                 ioctl(result,4,atoi(v[4]));
135                 fprintf(stderr,"Setting raw y to %d\n",atoi(v[4]));
136         } 
137         if(argc > 5) {
138                 ioctl(result,5,atoi(v[5]));
139                 fprintf(stderr,"Setting res x to %d\n",atoi(v[5]));
140         }
141         if(argc > 6) {
142                 ioctl(result,6,atoi(v[6]));
143                 fprintf(stderr,"Setting res y to %d\n",atoi(v[6]));
144         }
145         if(argc > 7) {
146                 ioctl(result,7,atoi(v[7]));
147                 fprintf(stderr,"Setting fudge x to %d\n",atoi(v[7]));
148         }
149         if(argc > 8) {
150                 ioctl(result,8,atoi(v[8]));
151                 fprintf(stderr,"Setting fudge y to %d\n",atoi(v[8]));
152         }
153         if(argc > 9) {
154                 ioctl(result,9,atoi(v[9]));
155                 fprintf(stderr,"Setting average sample to %d\n",atoi(v[9]));
156         } 
157         if(argc > 10) {
158                 ioctl(result,10,atoi(v[10]));
159                 fprintf(stderr,"Setting raw min x to %d\n",atoi(v[10]));
160         }
161         if(argc > 11) {
162                 ioctl(result,11,atoi(v[11]));
163                 fprintf(stderr,"Setting raw min y to %d\n",atoi(v[11]));
164         } 
165
166         printf("Reading touch panel...\n");
167
168         while(1) {
169                 result = PD_Read(&x, &y, &z, &b);
170                 if( result > 0) {
171                         if(mouse != b) {
172                                 mouse = b;
173                                 if(mouse) 
174                                         printf("Pen Down\n");
175                                 else
176                                         printf("Pen Up\n");
177                         }
178
179                         printf("%d,%d,%d,%d,%d\n", result, x, y, z, b);
180
181                 }
182         }
183 }
184 #endif