File: pointer.c

package info (click to toggle)
dmx4linux 2.5%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,660 kB
  • ctags: 2,835
  • sloc: ansic: 23,341; yacc: 918; asm: 846; makefile: 614; sh: 439
file content (196 lines) | stat: -rw-r--r-- 3,316 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright (C) Dirk Jagdmann <doj@cubic.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#include "debug.h"
#include "js.h"
#include "ps2.h"
#include "serial.h"
#include "pointer.h"

#include <dmx/dmx.h>

static int X=0, Y=0, Z=0, B=0;
static double SCALE=0.1;

void flushdevice(FILE *f)
{
  unsigned char buf[1024];
  fd_set rfds;
  struct timeval tv;
  int retval;
  int fh=fileno(f);

  PRINTF("flush\n");

  FD_ZERO(&rfds);
  FD_SET(fh, &rfds);
  tv.tv_sec=1;
  tv.tv_usec=0;

  retval=select(fh+1, &rfds, NULL, NULL, &tv);
  if(retval)
    {
      if(FD_ISSET(fh, &rfds))
	  read(fh, buf, sizeof(buf));
    }
}

static struct driver drv = { NULL, NULL, NULL };

int pointerinit(int *argc, const char **argv)
{
  const char *f;
  char *device=0;

  if(DMXgetarg(argc, argv, "--js", 1, &f)==1)
    {
      jsregister(&drv);
      device=strdup(f);
      SCALE=1.0/32768.0;
    }
  if(DMXgetarg(argc, argv, "--mm", 1, &f)==1)
    {
      mousesystemsregister(&drv);
      device=strdup(f);
    }
  if(DMXgetarg(argc, argv, "--ms", 1, &f)==1)
    {
      microsoftregister(&drv);
      device=strdup(f);
    }
  if(DMXgetarg(argc, argv, "--ps2", 1, &f)==1)
    {
      ps2register(&drv);
      device=strdup(f);
    }
  if(DMXgetarg(argc, argv, "--mousescale", 1, &f)==1)
    {
      double d=atof(f);
      if(d>0.0)
	SCALE*=1.0/d;
    }

  if(device==0)
    {
      printf("pointerinit(): no mouse device selected\n");
      return 0;
    }

  if(drv.init(device) < 0)
    {
      printf("pointerinit(): could not init device\n");
      return -1;
    }

  free(device);

  return 1;
}

int pointergetfd()
{
  return drv.getfd();
}

int pointerprocess()
{
#ifdef DEBUG
  static int z=0;
  PRINTF("\r");
#endif

  if(drv.poll() < 0)
    {
      printf("\npointerinit(): could not read device\n");
      return -1;
    }

#ifdef DEBUG
  PRINTF("%i %i %i %c %c %c %c %c %i    ", X, Y, Z, (B&BUT1)?'1':'.', (B&BUT2)?'2':'.', (B&BUT3)?'3':'.', (B&BUT4)?'4':'.', (B&BUT5)?'5':'.', ++z);
  fflush(stdout);
#endif
  return 0;
}

int pointerX()
{
  return SCALE*X;
}

int pointerY()
{
  return SCALE*Y;
}

int pointerZ()
{
  return Z;
}

int pointerrawX()
{
  return X;
}

int pointerrawY()
{
  return Y;
}

void pointersetX(int x)
{
  X=(double)x/SCALE;
}

void pointersetY(int y)
{
  Y=(double)y/SCALE;
}

void pointersetrawX(int x)
{
  X=x;
}

void pointersetrawY(int y)
{
  Y=y;
}

void pointersetZ(int z)
{
  Z=z;
}

void pointersetB(int b)
{
  B=b;
}

int pointerB()
{
  return B;
}