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#if 0 // unused type definitions 100#define tchar_t _TCHAR 101#define char_t char 102#define uint32_t unsigned long 103#define sint32_t long 104#define boolean_t unsigned char 105#define void_t void 106#define window_handle_t HWND 107#endif 108 109 110typedef long SPWint32; 111typedef short SPWint16; 112typedef char SPWint8; 113typedef int SPWbool; 114typedef unsigned long SPWuint32; 115typedef unsigned short SPWuint16; 116typedef unsigned char SPWuint8; 117typedef _TCHAR SPWchar; 118typedef _TCHAR* SPWstring; 119typedef float SPWfloat32; 120typedef double SPWfloat64; 121 122/* 123 * UI modes 124 */ 125#define SI_UI_ALL_CONTROLS 0xffffffffL 126#define SI_UI_NO_CONTROLS 0x00000000L 127 128/* 129 * These UI modes are left here for legacy applications. 130 */ 131#define SI_UI_FILTERS 0x00000001L 132#define SI_UI_FUNC_BUTTONS 0x00000002L 133#define SI_UI_RESET_BUTTONS 0x00000004L 134#define SI_UI_SENSITIVITY 0x00000008L 135#define SI_UI_TUNING 0x00000010L 136#define SI_UI_DIALOG_POPUP 0x00000020L 137 138/* 139 * Device types and classes 140 */ 141typedef enum 142 { 143 SI_ALL_TYPES = -1, 144 SI_UNKNOWN_DEVICE = 0, 145 SI_SPACEBALL_2003 = 1, 146 SI_SPACEBALL_3003 = 2, 147 SI_SPACE_CONTROLLER = 3, 148 SI_AVENGER = 4, 149 SI_SPACEORB_360 = 5, 150 SI_NAVIGATOR = 6, 151 SI_SPACEBALL_2003A = 7, 152 SI_SPACEBALL_2003B = 8, 153 SI_SPACEBALL_2003C = 9, 154 SI_SPACEBALL_3003A = 10, 155 SI_SPACEBALL_3003B = 11, 156 SI_SPACEBALL_3003C = 12, 157 SI_SPACEBALL_4000 = 13, 158 SI_SPACEMOUSE_CLASSIC = 14, 159 SI_SPACEMOUSE_PLUS = 15, 160 SI_SPACEMOUSE_XT = 16, 161 SI_PUCKMAN = 17, 162 SI_CADMAN = 18, 163 SI_NUM_DEV_TYPES /* Leave this last, add before it */ 164 } SiDevType; 165 166/* 167 * These defintions of device classes are left in for legacy applications. 168 */ 169#define SI_HIGH_END 63 170#define SI_MED_END 62 171#define SI_LOW_END 61 172 173/* 174 * Data retrieval mode, only SI_EVENT is currently supported. 175 */ 176#define SI_EVENT 0x0001 177#define SI_POLL 0x0002 178 179/* 180 * Get event flags 181 */ 182#define SI_AVERAGE_EVENTS 0x0001 183 184/* 185 * This is an INTERNAL flag used by the polling mechanism, user applications 186 * should NOT send this flag. 187 */ 188#define SI_POLLED_REQUEST 0x0100 189 190/* 191 * SpaceWare event types 192 */ 193typedef enum 194 { 195 SI_BUTTON_EVENT = 1, 196 SI_MOTION_EVENT, 197 SI_COMBO_EVENT, /* Not implemented */ 198 SI_ZERO_EVENT, 199 SI_EXCEPTION_EVENT, 200 SI_OUT_OF_BAND, 201 SI_ORIENTATION_EVENT, 202 SI_KEYBOARD_EVENT, 203 SI_LPFK_EVENT 204 } SiEventType; 205 206/* 207 * Data modes 208 */ 209#define SI_MODE_NORMALIZE 0x0001 210#define SI_MODE_COMPRESS 0x0002 211#define SI_MODE_SENSITIVITY 0x0004 212#define SI_MODE_TUNING 0x0008 213 214/* 215 * Motion data offsets 216 */ 217#define SI_TX 0 /* Translation X value */ 218#define SI_TY 1 /* Translation Y value */ 219#define SI_TZ 2 /* Translation Z value */ 220#define SI_RX 3 /* Rotation X value */ 221#define SI_RY 4 /* Rotation Y value */ 222#define SI_RZ 5 /* Rotation Z value */ 223 224/* 225 * Reserved buttons 226 */ 227 228#define SI_RESET_BIT 0x00000001L 229#define SI_PICK_BIT 0x80000000L 230#define SI_DIALOG_BIT 0x40000000L 231 232#define SI_RESET_BUTTON 0 233#define SI_PICK_BUTTON 31 234#define SI_DIALOG_BUTTON 30 235 236/* 237 * Miscellaneous 238 */ 239#define SI_END_ARGS 0 240#define SI_NO_HANDLE ((SiHdl) NULL) 241#define SI_ALL_HANDLES ((SiHdl) NULL) 242#define SI_ANY_HANDLE ((SiHdl) NULL) 243#define SI_NO_TRANSCTL ((SiTransCtl) NULL) 244#define SI_NO_MASK ((SiTypeMask *) NULL) 245#define SI_ANY_DEVICE -1 246#define SI_NO_DEVICE -1 247#define SI_NO_TYPE -1 248#define SI_NO_LIST -1 249#define SI_NO_BUTTON -1 250#define SI_STRSIZE 128 251#define SI_MAXBUF 128 252#define SI_KEY_MAXBUF 5120 253 254typedef int SiDevID; /* Device ID */ 255typedef void *SiHdl; /* SpaceWare handle */ 256typedef void *SiTransCtl; /* SpaceWare transport control handle */ 257 258typedef struct /* Open data */ 259 { 260 261 HWND hWnd; /* Window handle for SpaceWare messages. */ 262 SiTransCtl transCtl; /* SpaceWare transport control handle. Reserved */ 263 /* for the s80 transport mechanism. */ 264 DWORD processID; /* The process ID for this application. */ 265 char exeFile[MAX_PATH]; /* The executable name of the process. */ 266 SPWint32 libFlag; /* Library version flag. */ 267 } SiOpenData; 268 269typedef struct /* Get event Data */ 270 { 271 272 UINT msg; 273 WPARAM wParam; 274 LPARAM lParam; 275 } SiGetEventData; 276 277typedef struct /* Device type mask */ 278 { 279 unsigned char mask[8]; 280 } SiTypeMask; 281 282typedef struct /* Device port information */ 283 { 284 SiDevID devID; /* Device ID */ 285 int devType; /* Device type */ 286 int devClass; /* Device class */ 287 char devName[SI_STRSIZE]; /* Device name */ 288 char portName[SI_STRSIZE]; /* Port name */ 289 } SiDevPort; 290 291typedef struct /* Device information */ 292 { 293 char firmware[SI_STRSIZE]; /* Firmware version */ 294 int devType; /* Device type */ 295 int numButtons; /* Number of buttons */ 296 int numDegrees; /* Number of degrees of freedom */ 297 SPWbool canBeep; /* Device beeps */ 298 int majorVersion; /* Major version number */ 299 int minorVersion; /* Minor version number */ 300 } SiDevInfo; 301 302typedef struct /* Version information */ 303 { 304 int major; /* Major version number */ 305 int minor; /* Minor version number */ 306 int build; /* Build number */ 307 char version[SI_STRSIZE]; /* Version string */ 308 char date[SI_STRSIZE]; /* Date string */ 309 } SiVerInfo; 310 311typedef struct /* Sensitivity parameters */ 312 { 313 char dummy; 314 } SiSensitivity; 315 316typedef struct /* Tuning parameters */ 317 { 318 char dummy; 319 } SiTuning; 320 321typedef struct 322 { 323 SPWuint8 code; /* Out of band message code */ 324 SPWuint8 message[SI_MAXBUF-1]; /* The actual message */ 325 } SiSpwOOB; 326 327typedef struct 328 { 329 SPWuint8 string[SI_KEY_MAXBUF]; /* String for keyboard data */ 330 } SiKeyboardData; 331 332typedef struct 333 { 334 SPWuint32 lpfk; /* LPFK number to send */ 335 } SiLpfkData; 336 337typedef enum 338 { 339 SI_LEFT = 0, 340 SI_RIGHT 341 } SiOrientation; 342 343typedef struct /* Bitmasks of button states */ 344 { 345 SPWuint32 last; /* Buttons pressed as of last event */ 346 SPWuint32 current; /* Buttons pressed as of this event */ 347 SPWuint32 pressed; /* Buttons pressed this event */ 348 SPWuint32 released; /* Buttons released this event */ 349 } SiButtonData; 350 351typedef struct /* SpaceWare data */ 352 { 353 SiButtonData bData; /* Button data */ 354 long mData[6]; /* Motion data (index via SI_TX, etc) */ 355 long period; /* Period (milliseconds) */ 356 } SiSpwData; 357 358typedef struct /* SpaceWare event */ 359 { 360 int type; /* Event type */ 361 union 362 { 363 SiSpwData spwData; /* Button, motion, or combo data */ 364 SiSpwOOB spwOOB; /* Out of band message */ 365 SiOrientation spwOrientation;/* Which hand orientation is the device */ 366 char exData[SI_MAXBUF]; /* Exception data */ 367 SiKeyboardData spwKeyData; /* String for keyboard data */ 368 SiLpfkData spwLpfkData; /* LPFK data */ 369 } u; 370 } SiSpwEvent; 371 372typedef struct /* Event handler (for SiDispatch) */ 373 { 374 int (*func) (SiOpenData *, SiGetEventData *, SiSpwEvent *, void *); 375 void *data; 376 } SiEventHandler; 377 378typedef struct /* SpaceWare event handlers */ 379 { 380 SiEventHandler button; /* Button event handler */ 381 SiEventHandler motion; /* Motion event handler */ 382 SiEventHandler combo; /* Combo event handler */ 383 SiEventHandler zero; /* Zero event handler */ 384 SiEventHandler exception; /* Exception event handler */ 385 } SiSpwHandlers; 386 387 388enum SpwRetVal SiAndTypeMask (SiTypeMask *pTMaskA, SiTypeMask *pTMaskB); 389 390 391 392/* interface specifications define parameter passing to DLL functions */ 393#ifdef __cplusplus 394extern "C" { 395#endif 396 397typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void); 398typedef void (WINAPI *PFNSI_TERMINATE) (void); 399typedef void (WINAPI *PFNSI_OPENWININIT) (SiOpenData *pData, HWND hWnd); 400typedef int (WINAPI *PFNSI_GETNUMDEVICES) (void); 401typedef SiDevID (WINAPI *PFNSI_GETDEVICEID) (SiHdl hdl); 402typedef int (WINAPI *PFNSI_DISPATCH) (SiHdl hdl, SiGetEventData *pData, 403 SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers); 404typedef SiHdl (WINAPI *PFNSI_OPEN) (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode, 405 SiOpenData *pData); 406typedef enum SpwRetVal (WINAPI *PFNSI_CLOSE) (SiHdl hdl); 407typedef SPWbool (WINAPI *PFNSI_ISSPACEWAREEVENT) (SiGetEventData *pData, SiHdl *pHdl); 408typedef void (WINAPI *PFNSI_GETEVENTWININIT) (SiGetEventData *pData, UINT msg, WPARAM wParam, LPARAM lParam); 409typedef enum SpwRetVal (WINAPI *PFNSI_GETEVENT) (SiHdl hdl, int flags, SiGetEventData *pData, 410 SiSpwEvent *pEvent); 411typedef enum SpwRetVal (WINAPI *PFNSI_BEEP) (SiHdl hdl, char *pString); 412typedef enum SpwRetVal (WINAPI *PFNSI_REZERO) (SiHdl hdl); 413typedef enum SpwRetVal (WINAPI *PFNSI_GRABDEVICE) (SiHdl hdl, SPWbool exclusive); 414typedef enum SpwRetVal (WINAPI *PFNSI_RELEASEDEVICE) (SiHdl hdl); 415typedef int (WINAPI *PFNSI_BUTTONPRESSED) (SiSpwEvent *pEvent); 416typedef int (WINAPI *PFNSI_BUTTONRELEASED) (SiSpwEvent *pEvent); 417typedef enum SpwRetVal (WINAPI *PFNSI_SETUIMODE) (SiHdl hdl, SPWuint32 mode); 418typedef enum SpwRetVal (WINAPI *PFNSI_SETTYPEMASK) (SiTypeMask *pTMask, int type1, ...); 419typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEPORT) (SiDevID devID, SiDevPort *pPort); 420typedef enum SpwRetVal (WINAPI *PFNSI_GETDRIVERINFO) (SiVerInfo *pInfo); 421typedef void (WINAPI *PFNSI_GETLIBRARYINFO) (SiVerInfo *pInfo); 422typedef enum SpwRetVal (WINAPI *PFNSI_GETDEVICEINFO) (SiHdl hdl, SiDevInfo *pInfo); 423typedef char* (WINAPI *PFNSPW_ERRORSTRING) (enum SpwRetVal val); 424typedef SiDevID (WINAPI *PFNSI_DEVICEINDEX) (int idx); 425 426#ifdef __cplusplus 427} 428#endif 429 430/* function pointers to functions in DLL */ 431static PFNSI_INIT pfnSiInit; 432static PFNSI_TERMINATE pfnSiTerminate; 433static PFNSI_OPENWININIT pfnSiOpenWinInit; 434static PFNSI_GETNUMDEVICES pfnSiGetNumDevices; 435static PFNSI_GETDEVICEID pfnSiGetDeviceID; 436static PFNSI_DISPATCH pfnSiDispatch; 437static PFNSI_OPEN pfnSiOpen; 438static PFNSI_CLOSE pfnSiClose; 439static PFNSI_DEVICEINDEX pfnSiDeviceIndex; 440static PFNSI_GETEVENTWININIT pfnSiGetEventWinInit; 441static PFNSI_GETEVENT pfnSiGetEvent; 442static PFNSI_ISSPACEWAREEVENT pfnSiIsSpaceWareEvent; 443static PFNSI_BEEP pfnSiBeep; 444static PFNSI_REZERO pfnSiRezero; 445static PFNSI_GRABDEVICE pfnSiGrabDevice; 446static PFNSI_RELEASEDEVICE pfnSiReleaseDevice; 447static PFNSI_BUTTONPRESSED pfnSiButtonPressed; 448static PFNSI_BUTTONRELEASED pfnSiButtonReleased; 449static PFNSI_SETUIMODE pfnSiSetUiMode; 450static PFNSI_SETTYPEMASK pfnSiSetypeMask; 451static PFNSI_GETDEVICEPORT pfnSiGetDevicePort; 452static PFNSI_GETDRIVERINFO pfnSiGetDriverInfo; 453static PFNSI_GETLIBRARYINFO pfnSiGetLibraryInfo; 454static PFNSI_GETDEVICEINFO pfnSiGetDeviceInfo; 455static PFNSPW_ERRORSTRING pfnSpwErrorString; 456 457#ifdef __cplusplus 458extern "C" { 459#endif 460/* externally used functions */ 461int SiGetPortList (SiDevPort **ppPort); 462void SiFreePortList (SiDevPort *pPort); 463void SiTune2003 (SiSpwEvent *pEvent); 464void SiTuneSC (SiSpwEvent *pEvent); 465 466enum SpwRetVal SiInitialize(void); 467void SiTerminate(void); 468int SiGetNumDevices (void); 469SiDevID SiDeviceIndex (int idx); 470int SiDispatch (SiHdl hdl, SiGetEventData *pData, 471 SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers); 472void SiOpenWinInit (SiOpenData *pData, HWND hWnd); 473SiHdl SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode, 474 SiOpenData *pData); 475enum SpwRetVal SiClose (SiHdl hdl); 476void SiGetEventWinInit (SiGetEventData *pData, 477 UINT msg, WPARAM wParam, LPARAM lParam); 478enum SpwRetVal SiGetEvent (SiHdl hdl, int flags, SiGetEventData *pData, 479 SiSpwEvent *pEvent); 480enum SpwRetVal SiBeep (SiHdl hdl, char *string); 481enum SpwRetVal SiRezero (SiHdl hdl); 482enum SpwRetVal SiGrabDevice (SiHdl hdl, SPWbool exclusive); 483enum SpwRetVal SiReleaseDevice (SiHdl hdl); 484int SiButtonPressed (SiSpwEvent *pEvent); 485int SiButtonReleased (SiSpwEvent *pEvent); 486enum SpwRetVal SiSetUiMode (SiHdl hdl, SPWuint32 mode); 487enum SpwRetVal SiSetTypeMask (SiTypeMask *pTMask, int type1, ...); 488enum SpwRetVal SiGetDevicePort (SiDevID devID, SiDevPort *pPort); 489enum SpwRetVal SiGetDriverInfo (SiVerInfo *pInfo); 490void SiGetLibraryInfo (SiVerInfo *pInfo); 491enum SpwRetVal SiGetDeviceInfo (SiHdl hdl, SiDevInfo *pInfo); 492char * SpwErrorString (enum SpwRetVal val); 493 494#ifdef __cplusplus 495} 496#endif 497 498 499#ifdef __cplusplus 500extern "C" { 501#endif 502 503int SPW_CheckForSpaceballWin32(void * win); 504int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent); 505void SPW_disableSpaceBallWin32(void); 506int SPW_SpaceBallExistsWin32(void); 507 508#ifdef __cplusplus 509} 510#endif 511 512#endif /* #ifndef SIAPP_H */ 513 514