1#ifndef SPWINPUT_WIN32_H
2#define SPWINPUT_WIN32_H
3
4/* @configure_input@ */
5
6/*----------------------------------------------------------------------
7 * (C) 1998-2009 3Dconnexion. All rights reserved.
8 * Permission to use, copy, modify, and distribute this software for all
9 * purposes and without fees is hereby grated provided that this copyright
10 * notice appears in all copies.  Permission to modify this software is granted
11 * and 3Dconnexion will support such modifications only is said modifications are
12 * approved by 3Dconnexion.
13 *
14 */
15
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif /* HAVE_CONFIG_H */
19
20#include <Inventor/@Gui@/devices/spwinput.h>
21
22#ifndef HAVE_WIN32_API
23#error "Do not include this file unless HAVE_WIN32_API is set."
24#endif /* !HAVE_WIN32_API */
25
26#include <tchar.h>
27
28/* some enumerated types used in spwinput_win32.cpp */
29enum InitResult
30   {
31   NOT_LOADED,
32   FAILED,
33   LOADED
34   };
35
36enum ErrorCode
37   {
38   NO_DLL_ERROR=0,
39   DLL_LOAD_FAILURE,
40   DLL_FUNCTION_LOAD_FAILURE,
41   DLL_VAR_LOAD_FAILURE
42   };
43
44enum SpwRetVal             /* Error return values.                           */
45   {
46   SPW_NO_ERROR,           /* No error.                                      */
47   SPW_ERROR,              /* Error -- function failed.                      */
48   SI_BAD_HANDLE,          /* Invalid SpaceWare handle.                      */
49   SI_BAD_ID,              /* Invalid device ID.                             */
50   SI_BAD_VALUE,           /* Invalid argument value.                        */
51   SI_IS_EVENT,            /* Event is a SpaceWare event.                    */
52   SI_SKIP_EVENT,          /* Skip this SpaceWare event.                     */
53   SI_NOT_EVENT,           /* Event is not a SpaceWare event.                */
54   SI_NO_DRIVER,           /* SpaceWare driver is not running.               */
55   SI_NO_RESPONSE,         /* SpaceWare driver is not responding.            */
56   SI_UNSUPPORTED,         /* The function is unsupported by this version.   */
57   SI_UNINITIALIZED,       /* SpaceWare input library is uninitialized.      */
58   SI_WRONG_DRIVER,        /* Driver is incorrect for this SpaceWare version.*/
59   SI_INTERNAL_ERROR,      /* Internal SpaceWare error.                      */
60   SI_BAD_PROTOCOL,        /* The transport protocol is unknown.             */
61   SI_OUT_OF_MEMORY,       /* Unable to malloc space required.               */
62   SPW_DLL_LOAD_ERROR,     /* Could not load siapp dlls                      */
63   SI_NOT_OPEN,            /* Spaceball device not open                      */
64   SI_ITEM_NOT_FOUND	   /* Item not found                                 */
65   };
66
67static enum SpwRetVal *pDllSpwRetVal;
68
69/* some macros */
70#define SPW_FALSE   (0)
71#define SPW_TRUE    (!SPW_FALSE)
72
73#define SPW_MAX(a,b)   (((a)>(b))?(a):(b))
74#define SPW_MIN(a,b)   (((a)<(b))?(a):(b))
75
76#define SPW_ABS(a)   (((a)<0)?(-(a)):(a))
77
78#define SPW_SIGN(a)  ((a)>=0?1:-1)
79
80#define SPW_BIND(min,n,max)   (SPW_MIN((max),SPW_MAX((min),(n))))
81
82#define SPW_NUM_ELEMENTS_IN(a)   (sizeof(a)/sizeof((a)[0]))
83
84#define SPW_PI   3.14159265358979324f
85
86#define SPW_DEG_TO_RAD(d)   ((d)*SPW_PI/180.0f)
87#define SPW_RAD_TO_DEG(r)   ((r)*180.0f/SPW_PI)
88
89#define SPW_LENGTH_OF(a)   (sizeof(a)/sizeof((a)[0]))
90
91#define SPW_END_OF(a)   (&(a)[SPW_LENGTH_OF(a)-1])
92
93#define SPW_SQ(a)   ((a)*(a))
94
95#define SPW_ABSDIFF(a, b) (fabs((double) (a) - (b)))
96
97/* the accepted datatypes for spacetec products */
98
99#define tchar_t				_TCHAR
100#define char_t				char
101#define uint32_t			unsigned long
102#define sint32_t			long
103#define boolean_t			unsigned char
104#define void_t				void
105#define window_handle_t		HWND
106
107
108typedef long               SPWint32;
109typedef short              SPWint16;
110typedef char               SPWint8;
111typedef int                SPWbool;
112typedef unsigned long      SPWuint32;
113typedef unsigned short     SPWuint16;
114typedef unsigned char      SPWuint8;
115typedef _TCHAR             SPWchar;
116typedef _TCHAR*            SPWstring;
117typedef float              SPWfloat32;
118typedef double             SPWfloat64;
119
120/*
121 * UI modes
122 */
123#define SI_UI_ALL_CONTROLS    0xffffffffL
124#define SI_UI_NO_CONTROLS     0x00000000L
125
126/*
127 *  These UI modes are left here for legacy applications.
128 */
129#define SI_UI_FILTERS         0x00000001L
130#define SI_UI_FUNC_BUTTONS    0x00000002L
131#define SI_UI_RESET_BUTTONS   0x00000004L
132#define SI_UI_SENSITIVITY     0x00000008L
133#define SI_UI_TUNING          0x00000010L
134#define SI_UI_DIALOG_POPUP    0x00000020L
135
136/*
137 * Device types and classes
138 */
139typedef enum
140   {
141   SI_ALL_TYPES           = -1,
142   SI_UNKNOWN_DEVICE      =  0,
143   SI_SPACEBALL_2003      =  1,
144   SI_SPACEBALL_3003      =  2,
145   SI_SPACE_CONTROLLER    =  3,
146   SI_AVENGER             =  4,
147   SI_SPACEORB_360        =  5,
148   SI_NAVIGATOR           =  6,
149   SI_SPACEBALL_2003A     =  7,
150   SI_SPACEBALL_2003B     =  8,
151   SI_SPACEBALL_2003C     =  9,
152   SI_SPACEBALL_3003A     =  10,
153   SI_SPACEBALL_3003B     =  11,
154   SI_SPACEBALL_3003C     =  12,
155   SI_SPACEBALL_4000      =  13,
156   SI_SPACEMOUSE_CLASSIC  =  14,
157   SI_SPACEMOUSE_PLUS     =  15,
158   SI_SPACEMOUSE_XT       =  16,
159   SI_PUCKMAN             =  17,
160   SI_CADMAN              =  18,
161   SI_NUM_DEV_TYPES  /* Leave this last, add before it */
162   } SiDevType;
163
164/*
165 *  These defintions of device classes are left in for legacy applications.
166 */
167#define SI_HIGH_END           63
168#define SI_MED_END            62
169#define SI_LOW_END            61
170
171/*
172 * Data retrieval mode, only SI_EVENT is currently supported.
173 */
174#define SI_EVENT              0x0001
175#define SI_POLL               0x0002
176
177/*
178 * Get event flags
179 */
180#define SI_AVERAGE_EVENTS     0x0001
181
182/*
183 * This is an INTERNAL flag used by the polling mechanism, user applications
184 * should NOT send this flag.
185 */
186#define SI_POLLED_REQUEST     0x0100
187
188/*
189 * SpaceWare event types
190 */
191typedef enum
192   {
193   SI_BUTTON_EVENT = 1,
194   SI_MOTION_EVENT,
195   SI_COMBO_EVENT, /* Not implemented */
196   SI_ZERO_EVENT,
197   SI_EXCEPTION_EVENT,
198   SI_OUT_OF_BAND,
199   SI_ORIENTATION_EVENT,
200   SI_KEYBOARD_EVENT,
201   SI_LPFK_EVENT
202   } SiEventType;
203
204/*
205 * Data modes
206 */
207#define SI_MODE_NORMALIZE     0x0001
208#define SI_MODE_COMPRESS      0x0002
209#define SI_MODE_SENSITIVITY   0x0004
210#define SI_MODE_TUNING        0x0008
211
212/*
213 * Motion data offsets
214 */
215#define SI_TX                 0              /* Translation X value */
216#define SI_TY                 1              /* Translation Y value */
217#define SI_TZ                 2              /* Translation Z value */
218#define SI_RX                 3              /* Rotation X value */
219#define SI_RY                 4              /* Rotation Y value */
220#define SI_RZ                 5              /* Rotation Z value */
221
222/*
223 * Reserved buttons
224 */
225
226#define SI_RESET_BIT          0x00000001L
227#define SI_PICK_BIT           0x80000000L
228#define SI_DIALOG_BIT         0x40000000L
229
230#define SI_RESET_BUTTON       0
231#define SI_PICK_BUTTON        31
232#define SI_DIALOG_BUTTON      30
233
234/*
235 * Miscellaneous
236 */
237#define SI_END_ARGS           0
238#define SI_NO_HANDLE          ((SiHdl) NULL)
239#define SI_ALL_HANDLES        ((SiHdl) NULL)
240#define SI_ANY_HANDLE         ((SiHdl) NULL)
241#define SI_NO_TRANSCTL        ((SiTransCtl) NULL)
242#define SI_NO_MASK            ((SiTypeMask *) NULL)
243#define SI_ANY_DEVICE         -1
244#define SI_NO_DEVICE          -1
245#define SI_NO_TYPE            -1
246#define SI_NO_LIST            -1
247#define SI_NO_BUTTON          -1
248#define SI_STRSIZE            128
249#define SI_MAXBUF             128
250#define SI_KEY_MAXBUF         5120
251
252typedef int SiDevID;          /* Device ID */
253typedef void *SiHdl;          /* SpaceWare handle */
254typedef void *SiTransCtl;     /* SpaceWare transport control handle */
255
256typedef struct                /* Open data */
257   {
258
259   HWND hWnd;               /* Window handle for SpaceWare messages.        */
260   SiTransCtl transCtl;     /* SpaceWare transport control handle. Reserved */
261                            /* for the s80 transport mechanism.             */
262   DWORD processID;         /* The process ID for this application.         */
263   char exeFile[MAX_PATH];  /* The executable name of the process.          */
264   SPWint32 libFlag;        /* Library version flag.                        */
265   } SiOpenData;
266
267typedef struct                /* Get event Data */
268   {
269
270   UINT msg;
271   WPARAM wParam;
272   LPARAM lParam;
273   } SiGetEventData;
274
275typedef struct                /* Device type mask */
276   {
277   unsigned char mask[8];
278   } SiTypeMask;
279
280typedef struct                /* Device port information */
281   {
282   SiDevID devID;             /* Device ID */
283   int devType;               /* Device type */
284   int devClass;              /* Device class */
285   char devName[SI_STRSIZE];  /* Device name */
286   char portName[SI_STRSIZE]; /* Port name */
287   } SiDevPort;
288
289typedef struct                /* Device information */
290   {
291   char firmware[SI_STRSIZE]; /* Firmware version */
292   int devType;               /* Device type */
293   int numButtons;            /* Number of buttons */
294   int numDegrees;            /* Number of degrees of freedom */
295   SPWbool canBeep;           /* Device beeps */
296   int majorVersion;          /* Major version number */
297   int minorVersion;          /* Minor version number */
298   } SiDevInfo;
299
300typedef struct                /* Version information */
301   {
302   int major;                 /* Major version number */
303   int minor;                 /* Minor version number */
304   int build;                 /* Build number */
305   char version[SI_STRSIZE];  /* Version string */
306   char date[SI_STRSIZE];     /* Date string */
307   } SiVerInfo;
308
309typedef struct                /* Sensitivity parameters */
310   {
311   char dummy;
312   } SiSensitivity;
313
314typedef struct                /* Tuning parameters */
315   {
316   char dummy;
317   } SiTuning;
318
319typedef struct
320   {
321   SPWuint8 code;                 /* Out of band message code */
322   SPWuint8 message[SI_MAXBUF-1]; /* The actual message       */
323   } SiSpwOOB;
324
325typedef struct
326   {
327   SPWuint8 string[SI_KEY_MAXBUF];  /* String for keyboard data */
328   } SiKeyboardData;
329
330typedef struct
331   {
332   SPWuint32 lpfk;            /* LPFK number to send */
333   } SiLpfkData;
334
335typedef enum
336   {
337   SI_LEFT = 0,
338   SI_RIGHT
339   } SiOrientation;
340
341typedef struct                /* Bitmasks of button states */
342   {
343   SPWuint32 last;            /* Buttons pressed as of last event */
344   SPWuint32 current;         /* Buttons pressed as of this event */
345   SPWuint32 pressed;         /* Buttons pressed this event */
346   SPWuint32 released;        /* Buttons released this event */
347   } SiButtonData;
348
349typedef struct                /* SpaceWare data */
350   {
351   SiButtonData bData;        /* Button data */
352   long mData[6];             /* Motion data (index via SI_TX, etc) */
353   long period;               /* Period (milliseconds) */
354   } SiSpwData;
355
356typedef struct                /* SpaceWare event */
357   {
358   int type;                  /* Event type */
359   union
360      {
361      SiSpwData spwData;           /* Button, motion, or combo data        */
362      SiSpwOOB spwOOB;             /* Out of band message                  */
363      SiOrientation spwOrientation;/* Which hand orientation is the device */
364      char exData[SI_MAXBUF];      /* Exception data                       */
365      SiKeyboardData spwKeyData;   /* String for keyboard data             */
366      SiLpfkData spwLpfkData;      /* LPFK data                            */
367      } u;
368   } SiSpwEvent;
369
370typedef struct                /* Event handler (for SiDispatch) */
371   {
372   int (*func) (SiOpenData *, SiGetEventData *, SiSpwEvent *, void *);
373   void *data;
374   } SiEventHandler;
375
376typedef struct                /* SpaceWare event handlers */
377   {
378   SiEventHandler button;     /* Button event handler */
379   SiEventHandler motion;     /* Motion event handler */
380   SiEventHandler combo;      /* Combo event handler */
381   SiEventHandler zero;       /* Zero event handler */
382   SiEventHandler exception;  /* Exception event handler */
383   } SiSpwHandlers;
384
385
386enum SpwRetVal SiAndTypeMask (SiTypeMask *pTMaskA, SiTypeMask *pTMaskB);
387
388
389
390/* interface specifications define parameter passing to DLL functions */
391#ifdef __cplusplus
392extern "C" {
393#endif
394
395typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void);
396typedef void (WINAPI *PFNSI_TERMINATE) (void);
397typedef void (WINAPI *PFNSI_OPENWININIT) (SiOpenData *pData, HWND hWnd);
398typedef int (WINAPI *PFNSI_GETNUMDEVICES) (void);
399typedef SiDevID (WINAPI *PFNSI_GETDEVICEID) (SiHdl hdl);
400typedef int (WINAPI *PFNSI_DISPATCH) (SiHdl hdl, SiGetEventData *pData,
401                SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers);
402typedef SiHdl (WINAPI *PFNSI_OPEN) (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
403              SiOpenData *pData);
404typedef enum SpwRetVal (WINAPI *PFNSI_CLOSE) (SiHdl hdl);
405typedef SPWbool (WINAPI *PFNSI_ISSPACEWAREEVENT) (SiGetEventData *pData, SiHdl *pHdl);
406typedef void (WINAPI *PFNSI_GETEVENTWININIT) (SiGetEventData *pData, UINT msg, WPARAM wParam, LPARAM lParam);
407typedef enum SpwRetVal (WINAPI *PFNSI_GETEVENT) (SiHdl hdl, int flags, SiGetEventData *pData,
408                           SiSpwEvent *pEvent);
409typedef enum SpwRetVal (WINAPI *PFNSI_BEEP) (SiHdl hdl, char *pString);
410typedef enum SpwRetVal (WINAPI *PFNSI_REZERO) (SiHdl hdl);
411typedef enum SpwRetVal (WINAPI *PFNSI_GRABDEVICE) (SiHdl hdl, SPWbool exclusive);
412typedef enum SpwRetVal (WINAPI *PFNSI_RELEASEDEVICE) (SiHdl hdl);
413typedef int (WINAPI *PFNSI_BUTTONPRESSED) (SiSpwEvent *pEvent);
414typedef int (WINAPI *PFNSI_BUTTONRELEASED) (SiSpwEvent *pEvent);
415typedef enum SpwRetVal (WINAPI *PFNSI_SETUIMODE) (SiHdl hdl, SPWuint32 mode);
416typedef enum SpwRetVal (WINAPI *PFNSI_SETTYPEMASK) (SiTypeMask *pTMask, int type1, ...);
417typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEPORT) (SiDevID devID, SiDevPort *pPort);
418typedef enum SpwRetVal (WINAPI *PFNSI_GETDRIVERINFO) (SiVerInfo *pInfo);
419typedef void (WINAPI *PFNSI_GETLIBRARYINFO) (SiVerInfo *pInfo);
420typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEINFO) (SiHdl hdl, SiDevInfo *pInfo);
421typedef char* (WINAPI *PFNSPW_ERRORSTRING) (enum SpwRetVal val);
422typedef SiDevID (WINAPI *PFNSI_DEVICEINDEX) (int idx);
423
424#ifdef __cplusplus
425}
426#endif
427
428/* function pointers to functions in DLL */
429static PFNSI_INIT              pfnSiInit;
430static PFNSI_TERMINATE         pfnSiTerminate;
431static PFNSI_OPENWININIT       pfnSiOpenWinInit;
432static PFNSI_GETNUMDEVICES     pfnSiGetNumDevices;
433static PFNSI_GETDEVICEID       pfnSiGetDeviceID;
434static PFNSI_DISPATCH          pfnSiDispatch;
435static PFNSI_OPEN              pfnSiOpen;
436static PFNSI_CLOSE             pfnSiClose;
437static PFNSI_DEVICEINDEX       pfnSiDeviceIndex;
438static PFNSI_GETEVENTWININIT   pfnSiGetEventWinInit;
439static PFNSI_GETEVENT          pfnSiGetEvent;
440static PFNSI_ISSPACEWAREEVENT  pfnSiIsSpaceWareEvent;
441static PFNSI_BEEP              pfnSiBeep;
442static PFNSI_REZERO            pfnSiRezero;
443static PFNSI_GRABDEVICE        pfnSiGrabDevice;
444static PFNSI_RELEASEDEVICE     pfnSiReleaseDevice;
445static PFNSI_BUTTONPRESSED     pfnSiButtonPressed;
446static PFNSI_BUTTONRELEASED    pfnSiButtonReleased;
447static PFNSI_SETUIMODE         pfnSiSetUiMode;
448static PFNSI_SETTYPEMASK       pfnSiSetypeMask;
449static PFNSI_GETDEVICEPORT     pfnSiGetDevicePort;
450static PFNSI_GETDRIVERINFO     pfnSiGetDriverInfo;
451static PFNSI_GETLIBRARYINFO    pfnSiGetLibraryInfo;
452static PFNSI_GETDEVICEINFO     pfnSiGetDeviceInfo;
453static PFNSPW_ERRORSTRING      pfnSpwErrorString;
454
455#ifdef __cplusplus
456extern "C" {
457#endif
458/* externally used functions */
459int SiGetPortList (SiDevPort **ppPort);
460void SiFreePortList (SiDevPort *pPort);
461void SiTune2003 (SiSpwEvent *pEvent);
462void SiTuneSC (SiSpwEvent *pEvent);
463
464enum SpwRetVal SiInitialize(void);
465void           SiTerminate(void);
466int            SiGetNumDevices (void);
467SiDevID        SiDeviceIndex (int idx);
468int            SiDispatch (SiHdl hdl, SiGetEventData *pData,
469                           SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers);
470void           SiOpenWinInit (SiOpenData *pData, HWND hWnd);
471SiHdl          SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
472                       SiOpenData *pData);
473enum SpwRetVal SiClose (SiHdl hdl);
474void           SiGetEventWinInit (SiGetEventData *pData,
475                                  UINT msg, WPARAM wParam, LPARAM lParam);
476enum SpwRetVal SiGetEvent (SiHdl hdl, int flags, SiGetEventData *pData,
477                           SiSpwEvent *pEvent);
478enum SpwRetVal SiBeep (SiHdl hdl, char *string);
479enum SpwRetVal SiRezero (SiHdl hdl);
480enum SpwRetVal SiGrabDevice (SiHdl hdl, SPWbool exclusive);
481enum SpwRetVal SiReleaseDevice (SiHdl hdl);
482int            SiButtonPressed (SiSpwEvent *pEvent);
483int            SiButtonReleased (SiSpwEvent *pEvent);
484enum SpwRetVal SiSetUiMode (SiHdl hdl, SPWuint32 mode);
485enum SpwRetVal SiSetTypeMask (SiTypeMask *pTMask, int type1, ...);
486enum           SpwRetVal SiGetDevicePort (SiDevID devID, SiDevPort *pPort);
487enum           SpwRetVal SiGetDriverInfo (SiVerInfo *pInfo);
488void           SiGetLibraryInfo (SiVerInfo *pInfo);
489enum           SpwRetVal SiGetDeviceInfo (SiHdl hdl, SiDevInfo *pInfo);
490char * SpwErrorString (enum SpwRetVal val);
491
492#ifdef __cplusplus
493}
494#endif
495
496
497#ifdef __cplusplus
498extern "C" {
499#endif
500
501int SPW_CheckForSpaceballWin32(void * win);
502int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent);
503void SPW_disableSpaceBallWin32(void);
504int SPW_SpaceBallExistsWin32(void);
505
506#ifdef __cplusplus
507}
508#endif
509
510#endif /* #ifndef SIAPP_H */
511
512