1
/*----------------------------------------------------------------------
2
* (C) 1998-2001 3Dconnexion. All rights reserved.
3
* Permission to use, copy, modify, and distribute this software for all
4
* purposes and without fees is hereby grated provided that this copyright
5
* notice appears in all copies. Permission to modify this software is granted
6
* and 3Dconnexion will support such modifications only is said modifications are
7
* approved by 3Dconnexion.
11
#ifndef SPWINPUT_WIN32_H
12
#define SPWINPUT_WIN32_H
16
#endif /* HAVE_CONFIG_H */
18
#include <Inventor/Qt/devices/spwinput.h>
20
#ifndef HAVE_WIN32_API
21
#error "Do not include this file unless HAVE_WIN32_API is set."
22
#endif /* !HAVE_WIN32_API */
26
/* some enumerated types used in spwinput_win32.cpp */
38
DLL_FUNCTION_LOAD_FAILURE,
42
enum SpwRetVal /* Error return values. */
44
SPW_NO_ERROR, /* No error. */
45
SPW_ERROR, /* Error -- function failed. */
46
SI_BAD_HANDLE, /* Invalid SpaceWare handle. */
47
SI_BAD_ID, /* Invalid device ID. */
48
SI_BAD_VALUE, /* Invalid argument value. */
49
SI_IS_EVENT, /* Event is a SpaceWare event. */
50
SI_SKIP_EVENT, /* Skip this SpaceWare event. */
51
SI_NOT_EVENT, /* Event is not a SpaceWare event. */
52
SI_NO_DRIVER, /* SpaceWare driver is not running. */
53
SI_NO_RESPONSE, /* SpaceWare driver is not responding. */
54
SI_UNSUPPORTED, /* The function is unsupported by this version. */
55
SI_UNINITIALIZED, /* SpaceWare input library is uninitialized. */
56
SI_WRONG_DRIVER, /* Driver is incorrect for this SpaceWare version.*/
57
SI_INTERNAL_ERROR, /* Internal SpaceWare error. */
58
SI_BAD_PROTOCOL, /* The transport protocol is unknown. */
59
SI_OUT_OF_MEMORY, /* Unable to malloc space required. */
60
SPW_DLL_LOAD_ERROR, /* Could not load siapp dlls */
61
SI_NOT_OPEN, /* Spaceball device not open */
62
SI_ITEM_NOT_FOUND /* Item not found */
65
static enum SpwRetVal *pDllSpwRetVal;
69
#define SPW_TRUE (!SPW_FALSE)
71
#define SPW_MAX(a,b) (((a)>(b))?(a):(b))
72
#define SPW_MIN(a,b) (((a)<(b))?(a):(b))
74
#define SPW_ABS(a) (((a)<0)?(-(a)):(a))
76
#define SPW_SIGN(a) ((a)>=0?1:-1)
78
#define SPW_BIND(min,n,max) (SPW_MIN((max),SPW_MAX((min),(n))))
80
#define SPW_NUM_ELEMENTS_IN(a) (sizeof(a)/sizeof((a)[0]))
82
#define SPW_PI 3.14159265358979324f
84
#define SPW_DEG_TO_RAD(d) ((d)*SPW_PI/180.0f)
85
#define SPW_RAD_TO_DEG(r) ((r)*180.0f/SPW_PI)
87
#define SPW_LENGTH_OF(a) (sizeof(a)/sizeof((a)[0]))
89
#define SPW_END_OF(a) (&(a)[SPW_LENGTH_OF(a)-1])
91
#define SPW_SQ(a) ((a)*(a))
93
#define SPW_ABSDIFF(a, b) (fabs((double) (a) - (b)))
95
/* the accepted datatypes for spacetec products */
97
#define tchar_t _TCHAR
99
#define uint32_t unsigned long
100
#define sint32_t long
101
#define boolean_t unsigned char
103
#define window_handle_t HWND
106
typedef long SPWint32;
107
typedef short SPWint16;
108
typedef char SPWint8;
110
typedef unsigned long SPWuint32;
111
typedef unsigned short SPWuint16;
112
typedef unsigned char SPWuint8;
113
typedef _TCHAR SPWchar;
114
typedef _TCHAR* SPWstring;
115
typedef float SPWfloat32;
116
typedef double SPWfloat64;
121
#define SI_UI_ALL_CONTROLS 0xffffffffL
122
#define SI_UI_NO_CONTROLS 0x00000000L
125
* These UI modes are left here for legacy applications.
127
#define SI_UI_FILTERS 0x00000001L
128
#define SI_UI_FUNC_BUTTONS 0x00000002L
129
#define SI_UI_RESET_BUTTONS 0x00000004L
130
#define SI_UI_SENSITIVITY 0x00000008L
131
#define SI_UI_TUNING 0x00000010L
132
#define SI_UI_DIALOG_POPUP 0x00000020L
135
* Device types and classes
140
SI_UNKNOWN_DEVICE = 0,
141
SI_SPACEBALL_2003 = 1,
142
SI_SPACEBALL_3003 = 2,
143
SI_SPACE_CONTROLLER = 3,
147
SI_SPACEBALL_2003A = 7,
148
SI_SPACEBALL_2003B = 8,
149
SI_SPACEBALL_2003C = 9,
150
SI_SPACEBALL_3003A = 10,
151
SI_SPACEBALL_3003B = 11,
152
SI_SPACEBALL_3003C = 12,
153
SI_SPACEBALL_4000 = 13,
154
SI_SPACEMOUSE_CLASSIC = 14,
155
SI_SPACEMOUSE_PLUS = 15,
156
SI_SPACEMOUSE_XT = 16,
159
SI_NUM_DEV_TYPES /* Leave this last, add before it */
163
* These defintions of device classes are left in for legacy applications.
165
#define SI_HIGH_END 63
166
#define SI_MED_END 62
167
#define SI_LOW_END 61
170
* Data retrieval mode, only SI_EVENT is currently supported.
172
#define SI_EVENT 0x0001
173
#define SI_POLL 0x0002
178
#define SI_AVERAGE_EVENTS 0x0001
181
* This is an INTERNAL flag used by the polling mechanism, user applications
182
* should NOT send this flag.
184
#define SI_POLLED_REQUEST 0x0100
187
* SpaceWare event types
193
SI_COMBO_EVENT, /* Not implemented */
197
SI_ORIENTATION_EVENT,
205
#define SI_MODE_NORMALIZE 0x0001
206
#define SI_MODE_COMPRESS 0x0002
207
#define SI_MODE_SENSITIVITY 0x0004
208
#define SI_MODE_TUNING 0x0008
211
* Motion data offsets
213
#define SI_TX 0 /* Translation X value */
214
#define SI_TY 1 /* Translation Y value */
215
#define SI_TZ 2 /* Translation Z value */
216
#define SI_RX 3 /* Rotation X value */
217
#define SI_RY 4 /* Rotation Y value */
218
#define SI_RZ 5 /* Rotation Z value */
224
#define SI_RESET_BIT 0x00000001L
225
#define SI_PICK_BIT 0x80000000L
226
#define SI_DIALOG_BIT 0x40000000L
228
#define SI_RESET_BUTTON 0
229
#define SI_PICK_BUTTON 31
230
#define SI_DIALOG_BUTTON 30
235
#define SI_END_ARGS 0
236
#define SI_NO_HANDLE ((SiHdl) NULL)
237
#define SI_ALL_HANDLES ((SiHdl) NULL)
238
#define SI_ANY_HANDLE ((SiHdl) NULL)
239
#define SI_NO_TRANSCTL ((SiTransCtl) NULL)
240
#define SI_NO_MASK ((SiTypeMask *) NULL)
241
#define SI_ANY_DEVICE -1
242
#define SI_NO_DEVICE -1
243
#define SI_NO_TYPE -1
244
#define SI_NO_LIST -1
245
#define SI_NO_BUTTON -1
246
#define SI_STRSIZE 128
247
#define SI_MAXBUF 128
248
#define SI_KEY_MAXBUF 5120
250
typedef int SiDevID; /* Device ID */
251
typedef void *SiHdl; /* SpaceWare handle */
252
typedef void *SiTransCtl; /* SpaceWare transport control handle */
254
typedef struct /* Open data */
257
HWND hWnd; /* Window handle for SpaceWare messages. */
258
SiTransCtl transCtl; /* SpaceWare transport control handle. Reserved */
259
/* for the s80 transport mechanism. */
260
DWORD processID; /* The process ID for this application. */
261
char exeFile[MAX_PATH]; /* The executable name of the process. */
262
SPWint32 libFlag; /* Library version flag. */
265
typedef struct /* Get event Data */
273
typedef struct /* Device type mask */
275
unsigned char mask[8];
278
typedef struct /* Device port information */
280
SiDevID devID; /* Device ID */
281
int devType; /* Device type */
282
int devClass; /* Device class */
283
char devName[SI_STRSIZE]; /* Device name */
284
char portName[SI_STRSIZE]; /* Port name */
287
typedef struct /* Device information */
289
char firmware[SI_STRSIZE]; /* Firmware version */
290
int devType; /* Device type */
291
int numButtons; /* Number of buttons */
292
int numDegrees; /* Number of degrees of freedom */
293
SPWbool canBeep; /* Device beeps */
294
int majorVersion; /* Major version number */
295
int minorVersion; /* Minor version number */
298
typedef struct /* Version information */
300
int major; /* Major version number */
301
int minor; /* Minor version number */
302
int build; /* Build number */
303
char version[SI_STRSIZE]; /* Version string */
304
char date[SI_STRSIZE]; /* Date string */
307
typedef struct /* Sensitivity parameters */
312
typedef struct /* Tuning parameters */
319
SPWuint8 code; /* Out of band message code */
320
SPWuint8 message[SI_MAXBUF-1]; /* The actual message */
325
SPWuint8 string[SI_KEY_MAXBUF]; /* String for keyboard data */
330
SPWuint32 lpfk; /* LPFK number to send */
339
typedef struct /* Bitmasks of button states */
341
SPWuint32 last; /* Buttons pressed as of last event */
342
SPWuint32 current; /* Buttons pressed as of this event */
343
SPWuint32 pressed; /* Buttons pressed this event */
344
SPWuint32 released; /* Buttons released this event */
347
typedef struct /* SpaceWare data */
349
SiButtonData bData; /* Button data */
350
long mData[6]; /* Motion data (index via SI_TX, etc) */
351
long period; /* Period (milliseconds) */
354
typedef struct /* SpaceWare event */
356
int type; /* Event type */
359
SiSpwData spwData; /* Button, motion, or combo data */
360
SiSpwOOB spwOOB; /* Out of band message */
361
SiOrientation spwOrientation;/* Which hand orientation is the device */
362
char exData[SI_MAXBUF]; /* Exception data */
363
SiKeyboardData spwKeyData; /* String for keyboard data */
364
SiLpfkData spwLpfkData; /* LPFK data */
368
typedef struct /* Event handler (for SiDispatch) */
370
int (*func) (SiOpenData *, SiGetEventData *, SiSpwEvent *, void *);
374
typedef struct /* SpaceWare event handlers */
376
SiEventHandler button; /* Button event handler */
377
SiEventHandler motion; /* Motion event handler */
378
SiEventHandler combo; /* Combo event handler */
379
SiEventHandler zero; /* Zero event handler */
380
SiEventHandler exception; /* Exception event handler */
384
enum SpwRetVal SiAndTypeMask (SiTypeMask *pTMaskA, SiTypeMask *pTMaskB);
388
/* interface specifications define parameter passing to DLL functions */
393
typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void);
394
typedef void (WINAPI *PFNSI_TERMINATE) (void);
395
typedef void (WINAPI *PFNSI_OPENWININIT) (SiOpenData *pData, HWND hWnd);
396
typedef int (WINAPI *PFNSI_GETNUMDEVICES) (void);
397
typedef SiDevID (WINAPI *PFNSI_GETDEVICEID) (SiHdl hdl);
398
typedef int (WINAPI *PFNSI_DISPATCH) (SiHdl hdl, SiGetEventData *pData,
399
SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers);
400
typedef SiHdl (WINAPI *PFNSI_OPEN) (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
402
typedef enum SpwRetVal (WINAPI *PFNSI_CLOSE) (SiHdl hdl);
403
typedef SPWbool (WINAPI *PFNSI_ISSPACEWAREEVENT) (SiGetEventData *pData, SiHdl *pHdl);
404
typedef void (WINAPI *PFNSI_GETEVENTWININIT) (SiGetEventData *pData, UINT msg, WPARAM wParam, LPARAM lParam);
405
typedef enum SpwRetVal (WINAPI *PFNSI_GETEVENT) (SiHdl hdl, int flags, SiGetEventData *pData,
407
typedef enum SpwRetVal (WINAPI *PFNSI_BEEP) (SiHdl hdl, char *pString);
408
typedef enum SpwRetVal (WINAPI *PFNSI_REZERO) (SiHdl hdl);
409
typedef enum SpwRetVal (WINAPI *PFNSI_GRABDEVICE) (SiHdl hdl, SPWbool exclusive);
410
typedef enum SpwRetVal (WINAPI *PFNSI_RELEASEDEVICE) (SiHdl hdl);
411
typedef int (WINAPI *PFNSI_BUTTONPRESSED) (SiSpwEvent *pEvent);
412
typedef int (WINAPI *PFNSI_BUTTONRELEASED) (SiSpwEvent *pEvent);
413
typedef enum SpwRetVal (WINAPI *PFNSI_SETUIMODE) (SiHdl hdl, SPWuint32 mode);
414
typedef enum SpwRetVal (WINAPI *PFNSI_SETTYPEMASK) (SiTypeMask *pTMask, int type1, ...);
415
typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEPORT) (SiDevID devID, SiDevPort *pPort);
416
typedef enum SpwRetVal (WINAPI *PFNSI_GETDRIVERINFO) (SiVerInfo *pInfo);
417
typedef void (WINAPI *PFNSI_GETLIBRARYINFO) (SiVerInfo *pInfo);
418
typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEINFO) (SiHdl hdl, SiDevInfo *pInfo);
419
typedef char* (WINAPI *PFNSPW_ERRORSTRING) (enum SpwRetVal val);
420
typedef SiDevID (WINAPI *PFNSI_DEVICEINDEX) (int idx);
426
/* function pointers to functions in DLL */
427
static PFNSI_INIT pfnSiInit;
428
static PFNSI_TERMINATE pfnSiTerminate;
429
static PFNSI_OPENWININIT pfnSiOpenWinInit;
430
static PFNSI_GETNUMDEVICES pfnSiGetNumDevices;
431
static PFNSI_GETDEVICEID pfnSiGetDeviceID;
432
static PFNSI_DISPATCH pfnSiDispatch;
433
static PFNSI_OPEN pfnSiOpen;
434
static PFNSI_CLOSE pfnSiClose;
435
static PFNSI_DEVICEINDEX pfnSiDeviceIndex;
436
static PFNSI_GETEVENTWININIT pfnSiGetEventWinInit;
437
static PFNSI_GETEVENT pfnSiGetEvent;
438
static PFNSI_ISSPACEWAREEVENT pfnSiIsSpaceWareEvent;
439
static PFNSI_BEEP pfnSiBeep;
440
static PFNSI_REZERO pfnSiRezero;
441
static PFNSI_GRABDEVICE pfnSiGrabDevice;
442
static PFNSI_RELEASEDEVICE pfnSiReleaseDevice;
443
static PFNSI_BUTTONPRESSED pfnSiButtonPressed;
444
static PFNSI_BUTTONRELEASED pfnSiButtonReleased;
445
static PFNSI_SETUIMODE pfnSiSetUiMode;
446
static PFNSI_SETTYPEMASK pfnSiSetypeMask;
447
static PFNSI_GETDEVICEPORT pfnSiGetDevicePort;
448
static PFNSI_GETDRIVERINFO pfnSiGetDriverInfo;
449
static PFNSI_GETLIBRARYINFO pfnSiGetLibraryInfo;
450
static PFNSI_GETDEVICEINFO pfnSiGetDeviceInfo;
451
static PFNSPW_ERRORSTRING pfnSpwErrorString;
456
/* externally used functions */
457
int SiGetPortList (SiDevPort **ppPort);
458
void SiFreePortList (SiDevPort *pPort);
459
void SiTune2003 (SiSpwEvent *pEvent);
460
void SiTuneSC (SiSpwEvent *pEvent);
462
enum SpwRetVal SiInitialize(void);
463
void SiTerminate(void);
464
int SiGetNumDevices (void);
465
SiDevID SiDeviceIndex (int idx);
466
int SiDispatch (SiHdl hdl, SiGetEventData *pData,
467
SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers);
468
void SiOpenWinInit (SiOpenData *pData, HWND hWnd);
469
SiHdl SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
471
enum SpwRetVal SiClose (SiHdl hdl);
472
void SiGetEventWinInit (SiGetEventData *pData,
473
UINT msg, WPARAM wParam, LPARAM lParam);
474
enum SpwRetVal SiGetEvent (SiHdl hdl, int flags, SiGetEventData *pData,
476
enum SpwRetVal SiBeep (SiHdl hdl, char *string);
477
enum SpwRetVal SiRezero (SiHdl hdl);
478
enum SpwRetVal SiGrabDevice (SiHdl hdl, SPWbool exclusive);
479
enum SpwRetVal SiReleaseDevice (SiHdl hdl);
480
int SiButtonPressed (SiSpwEvent *pEvent);
481
int SiButtonReleased (SiSpwEvent *pEvent);
482
enum SpwRetVal SiSetUiMode (SiHdl hdl, SPWuint32 mode);
483
enum SpwRetVal SiSetTypeMask (SiTypeMask *pTMask, int type1, ...);
484
enum SpwRetVal SiGetDevicePort (SiDevID devID, SiDevPort *pPort);
485
enum SpwRetVal SiGetDriverInfo (SiVerInfo *pInfo);
486
void SiGetLibraryInfo (SiVerInfo *pInfo);
487
enum SpwRetVal SiGetDeviceInfo (SiHdl hdl, SiDevInfo *pInfo);
488
char * SpwErrorString (enum SpwRetVal val);
499
int SPW_CheckForSpaceballWin32(void * win);
500
int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent);
501
void SPW_disableSpaceBallWin32(void);
502
int SPW_SpaceBallExistsWin32(void);
508
#endif /* #ifndef SIAPP_H */