Re-probe for device if DeviceOn fails and auto-dev is active.
[xorg/acecad] / src / acecad.h
1 /* 
2  * Copyright (c) 2001 Edouard TISSERANT <tissered@esstin.u-nancy.fr>
3  * Parts inspired from Shane Watts <shane@bofh.asn.au> Xfree 3 Acecad Driver
4  * Thanks to Emily, from AceCad, For giving me documents.
5  * 
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
21  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  *
25  */
26 /* $XFree86: xc/programs/Xserver/hw/xfree86/input/acecad/acecad.h,v 1.2tsi Exp $ */
27
28 #ifndef _ACECAD_H_
29 #define _ACECAD_H_
30
31 /******************************************************************************
32  *              Definitions
33  *              structs, typedefs, #defines, enums
34  *****************************************************************************/
35 #define ACECAD_PACKET_SIZE              7
36
37 #define ACECAD_CONFIG           "a"             /* Send configuration (max coords) */
38
39 #define ACECAD_ABSOLUTE         'F'             /* Absolute mode */
40 #define ACECAD_RELATIVE         'E'             /* Relative mode */
41
42 #define ACECAD_UPPER_ORIGIN     "b"             /* Origin upper left */
43
44 #define ACECAD_PROMPT_MODE      "B"             /* Prompt mode */
45 #define ACECAD_STREAM_MODE      "@"             /* Stream mode */
46 #define ACECAD_INCREMENT        'I'             /* Set increment */
47 #define ACECAD_BINARY_FMT       "zb"    /* Binary reporting */
48
49 #define ACECAD_PROMPT           "P"             /* Prompt for current position */
50
51 #define PHASING_BIT             0x80
52 #define PROXIMITY_BIT   0x40
53 #define TABID_BIT               0x20
54 #define XSIGN_BIT               0x10
55 #define YSIGN_BIT               0x08
56 #define BUTTON_BITS             0x07
57 #define COORD_BITS              0x7f
58
59 #define ABSOLUTE_FLAG           1
60
61 #define milisleep(ms) xf86usleep (ms * 1000)
62
63 #define SYSCALL(call) while(((call) == -1) && (errno == EINTR))
64
65 static const char * acecad_initstr = ACECAD_BINARY_FMT ACECAD_STREAM_MODE;
66
67 typedef struct 
68 {
69         XISBuffer *buffer;
70     int         acecadInc;              /* increment between transmits */
71     int         acecadOldX;             /* previous X position */
72     int         acecadOldY;             /* previous Y position */
73     int         acecadOldZ;             /* previous Z position */
74     int         acecadOldProximity;     /* previous proximity */
75     int         acecadOldButtons;       /* previous buttons state */
76     int         acecadMaxX;             /* max X value */
77     int         acecadMaxY;             /* max Y value */
78     int         acecadMaxZ;             /* max Y value */
79     char        acecadReportSpeed;              /* report speed */
80     int         acecadUSB;              /*USB flag*/
81     BOOL        acecadAutoDev;          /* are using auto-dev */
82     int         flags;                  /* various flags */
83     int         packeti;                /* number of bytes read */
84     int         PacketSize;             /* number of bytes read */
85     unsigned char packet[ACECAD_PACKET_SIZE];   /* data read on the device */
86 } AceCadPrivateRec, *AceCadPrivatePtr;
87
88
89 /******************************************************************************
90  *              Declarations
91  *****************************************************************************/
92 #ifdef XFree86LOADER
93 static MODULESETUPPROTO( SetupProc );
94 static void TearDownProc (void *);
95 #endif
96 static Bool DeviceControl (DeviceIntPtr, int);
97 static Bool DeviceOn (DeviceIntPtr);
98 static Bool DeviceOff (DeviceIntPtr);
99 static Bool DeviceClose (DeviceIntPtr);
100 static Bool DeviceInit (DeviceIntPtr);
101 static void ReadInput (LocalDevicePtr);
102 static void CloseProc (LocalDevicePtr);
103 static Bool ConvertProc (LocalDevicePtr, int, int, int, int, int, int, int, int, int *, int *);
104 static Bool ReverseConvertProc(LocalDevicePtr , int , int , int*);
105 static Bool QueryHardware (AceCadPrivatePtr);
106 static void NewPacket (AceCadPrivatePtr priv);
107 static Bool AceCadGetPacket (AceCadPrivatePtr);
108 static InputInfoPtr AceCadPreInit(InputDriverPtr, IDevPtr , int);
109 #ifdef LINUX_INPUT
110 static void USBReadInput (LocalDevicePtr);
111 static Bool USBQueryHardware (LocalDevicePtr);
112 static int IsUSBLine(int);
113 static Bool fd_query_acecad(int, char*);
114 static Bool AceCadAutoDevProbe(LocalDevicePtr);
115 #endif
116
117
118 #endif