forked from coin3d/sogui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspwinput_win32.c.in
1418 lines (1255 loc) · 41.7 KB
/
spwinput_win32.c.in
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* @configure_input@ */
/*----------------------------------------------------------------------
* (C) 1998-2009 3Dconnexion. All rights reserved.
* Permission to use, copy, modify, and distribute this software for all
* purposes and without fees is hereby grated provided that this copyright
* notice appears in all copies. Permission to modify this software is granted
* and 3Dconnexion will support such modifications only is said modifications are
* approved by 3Dconnexion.
*
*/
/*
* The module contains interface routines to the Si library routines contained
* in the associated Dynamic Link Library. The DLL is loaded explicitly when
* Si is initialized. When the DLL is loaded, the initialization routine finds
* the addresses of the routines that it exposes to the world. Once this is
* done the library routines are used as if they were part of the original
* source code.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */
#ifdef HAVE_WIN32_API /* Only compile this file when the Win32 API is available */
#define SPW_DEFINE_COPYRIGHT
#define SPW_DEFINE_GLOBALS
#include <windows.h>
#include <Inventor/@Gui@/devices/spwinput_win32.h>
/* DLL library name */
static LPCTSTR DllLibrary = "siappdll";
/* names of DLL variables used in DLL */
static LPCSTR strDLLRetVal = "SpwErrorVal";
/*typedef enum SpwRetVal SpwReturnValue;*/
/* Names of functions contained in DLL; used to find their addresses at load
time */
static LPCSTR fnSiBeep = "SiBeep";
static LPCSTR fnSiInitialize = "SiInitialize";
static LPCSTR fnSiTerminate = "SiTerminate";
static LPCSTR fnSiGetDeviceID = "SiGetDeviceID";
static LPCSTR fnSiGetNumDevices = "SiGetNumDevices";
static LPCSTR fnSiDeviceIndex = "SiDeviceIndex";
static LPCSTR fnSiDispatch = "SiDispatch";
static LPCSTR fnSiIsSpaceWareEvent = "SiIsSpaceWareEvent";
static LPCSTR fnSiOpenWinInit = "SiOpenWinInit";
static LPCSTR fnSiOpen = "SiOpen";
static LPCSTR fnSiClose = "SiClose";
static LPCSTR fnSiGetEventWinInit = "SiGetEventWinInit";
static LPCSTR fnSiGetEvent = "SiGetEvent";
static LPCSTR fnSiRezero = "SiRezero";
static LPCSTR fnSiGrabDevice = "SiGrabDevice";
static LPCSTR fnSiReleaseDevice = "SiReleaseDevice";
static LPCSTR fnSiButtonPressed = "SiButtonPressed";
static LPCSTR fnSiButtonReleased = "SiButtonReleased";
static LPCSTR fnSiSetUIMode = "SiSetUiMode";
static LPCSTR fnSiGetDevicePort = "SiGetDevicePort";
static LPCSTR fnSiGetDriverInfo = "SiGetDriverInfo";
static LPCSTR fnSiGetLibraryInfo = "SiGetLibraryInfo";
static LPCSTR fnSiGetDeviceInfo = "SiGetDeviceInfo";
static LPCSTR fnSpwErrorString = "SpwErrorString";
/* DLL initialization status */
static enum InitResult gInitStatus = NOT_LOADED;
/* DLL handle */
HINSTANCE ghDll;
enum SpwRetVal SpwErrorVal;
/* Device handle */
SiHdl Spw_DeviceHandle = SI_NO_HANDLE;
/* Check to see if we can open a device handle to the spaceball */
int SPW_SpaceBallExistsWin32(void)
{
SiOpenData oData;
SiOpenWinInit(&oData,NULL);
return (SiOpen("", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData) != SI_NO_HANDLE) ? TRUE : FALSE;
}
/* check if can open a handle to the spaceball, load the driver functions
and start receiving input from the spaceball */
int SPW_CheckForSpaceballWin32(void * win)
{
char classname[25];
SiOpenData oData;
if (Spw_DeviceHandle == SI_NO_HANDLE) {
if (SiInitialize() != SPW_DLL_LOAD_ERROR) {
GetClassName((HWND)win, classname, sizeof(classname));
SiOpenWinInit(&oData, (HWND)win);
Spw_DeviceHandle = SiOpen(classname, SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);
if (Spw_DeviceHandle != SI_NO_HANDLE) {
SiSetUiMode(Spw_DeviceHandle, SI_UI_ALL_CONTROLS);
return TRUE;
}
else {
SiTerminate();
return FALSE;
}
}
else return FALSE;
}
else return TRUE;
}
/* translates a Win32 event to a SPW_InputEvent. */
int SPW_TranslateEventWin32(MSG * msg, SPW_InputEvent * sbEvent)
{
SiSpwEvent spwEvent;
SiGetEventData eventdata;
if (Spw_DeviceHandle != SI_NO_HANDLE) {
SiGetEventWinInit (&eventdata, msg->message, msg->wParam, msg->lParam);
if (SiGetEvent (Spw_DeviceHandle, 0, &eventdata, &spwEvent) == SI_IS_EVENT) {
int i;
switch(spwEvent.type) {
case SI_MOTION_EVENT:
sbEvent->type = SPW_InputMotionEvent;
for(i=0; i<6; i++) {
sbEvent->sData[i] = (short)spwEvent.u.spwData.mData[i];
}
break;
case SI_BUTTON_EVENT:
sbEvent->type = SPW_InputButtonPressEvent;
sbEvent->buttonState.pressed = (SiButtonPressed(&spwEvent) != SI_NO_BUTTON);
sbEvent->buttonState.released = (SiButtonReleased(&spwEvent) != SI_NO_BUTTON);
break;
}
return TRUE;
}
}
return FALSE;
}
/* Stop receiving input from the spaceball */
void SPW_disableSpaceBallWin32(void)
{
SiClose(Spw_DeviceHandle);
SiTerminate();
Spw_DeviceHandle = SI_NO_HANDLE;
}
/*-----------------------------------------------------------------------------
*
* void __SiAppInitialize(void)
*
* Args:
* None
*
* Return Value:
* None
*
* Description:
* This function opens up the DLL library and, if successful, loads a
* function pointer table with exported UAPI functions contained in the DLL.
*
*---------------------------------------------------------------------------*/
int __SiAppInitialize(void)
{
enum InitResult nResult; /* initialization result code */
enum ErrorCode nErrorCode; /* function return code */
/* attempt to load the DLL */
if ((ghDll = LoadLibrary (DllLibrary)) != NULL)
{
/* preset variables and hope for success */
nResult = LOADED;
nErrorCode = NO_DLL_ERROR;
/* load up the global variable used by the DLL to return error info */
if ((pDllSpwRetVal = (enum SpwRetVal *)
GetProcAddress(ghDll, strDLLRetVal)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_VAR_LOAD_FAILURE;
}
/* load up function pointer table */
if ((pfnSiBeep = (PFNSI_BEEP)
GetProcAddress(ghDll, fnSiBeep)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiInit = (PFNSI_INIT)
GetProcAddress(ghDll, fnSiInitialize)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiTerminate = (PFNSI_TERMINATE)
GetProcAddress(ghDll, fnSiTerminate)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetNumDevices = (PFNSI_GETNUMDEVICES)
GetProcAddress(ghDll, fnSiGetNumDevices)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetDeviceID = (PFNSI_GETDEVICEID)
GetProcAddress(ghDll, fnSiGetDeviceID)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiDeviceIndex = (PFNSI_DEVICEINDEX)
GetProcAddress(ghDll, fnSiDeviceIndex)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiDispatch = (PFNSI_DISPATCH)
GetProcAddress(ghDll, fnSiDispatch)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiOpenWinInit = (PFNSI_OPENWININIT)
GetProcAddress(ghDll, fnSiOpenWinInit)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiOpen = (PFNSI_OPEN)
GetProcAddress(ghDll, fnSiOpen)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiClose = (PFNSI_CLOSE)
GetProcAddress(ghDll, fnSiClose)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetEventWinInit = (PFNSI_GETEVENTWININIT)
GetProcAddress(ghDll, fnSiGetEventWinInit)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiIsSpaceWareEvent = (PFNSI_ISSPACEWAREEVENT)
GetProcAddress(ghDll, fnSiIsSpaceWareEvent)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetEvent = (PFNSI_GETEVENT)
GetProcAddress(ghDll, fnSiGetEvent)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiRezero = (PFNSI_REZERO)
GetProcAddress(ghDll, fnSiRezero)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGrabDevice = (PFNSI_GRABDEVICE)
GetProcAddress(ghDll, fnSiGrabDevice)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiReleaseDevice = (PFNSI_RELEASEDEVICE)
GetProcAddress(ghDll, fnSiReleaseDevice)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiButtonPressed = (PFNSI_BUTTONPRESSED)
GetProcAddress(ghDll, fnSiButtonPressed)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiButtonReleased = (PFNSI_BUTTONRELEASED)
GetProcAddress(ghDll, fnSiButtonReleased)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiSetUiMode = (PFNSI_SETUIMODE)
GetProcAddress(ghDll, fnSiSetUIMode)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetDevicePort = (PFNSI_GETDEVICEPORT)
GetProcAddress(ghDll, fnSiGetDevicePort)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetDriverInfo = (PFNSI_GETDRIVERINFO)
GetProcAddress(ghDll, fnSiGetDriverInfo)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetLibraryInfo = (PFNSI_GETLIBRARYINFO)
GetProcAddress(ghDll, fnSiGetLibraryInfo)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSiGetDeviceInfo = (PFNSI_GETDEVICEINFO)
GetProcAddress(ghDll, fnSiGetDeviceInfo)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
if ((pfnSpwErrorString = (PFNSPW_ERRORSTRING)
GetProcAddress(ghDll, fnSpwErrorString)) == NULL)
{
nResult = FAILED;
nErrorCode = DLL_FUNCTION_LOAD_FAILURE;
}
}
else /* couldn't load DLL */
{
nResult = FAILED;
nErrorCode = DLL_LOAD_FAILURE;
}
/* set the global variable */
gInitStatus = nResult;
return nErrorCode;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiInitialize (void)
*
* Args:
*
* Return Value:
* SPW_NO_ERROR No error
* SPW_ERROR Initialization error
*
* Description:
* This function initializes the SpaceWare input library. Since most input
* functions require that the library be initialized, this function should
* be called before any other input functions are called.
*
*---------------------------------------------------------------------------*/
enum SpwRetVal
SiInitialize(void)
{
enum SpwRetVal tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
__SiAppInitialize();
if (gInitStatus == FAILED)
{
return SPW_DLL_LOAD_ERROR;
}
}
tmpRetVal = pfnSiInit();
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* void SiTerminate (void)
*
* Args:
* None
*
* Return Value:
* None
*
* Description:
* This function must be called to properly shut down the SpaceWare input
* library. No other input functions (except SiInit) should be called
* afterwards.
*
*---------------------------------------------------------------------------*/
void
SiTerminate(void)
{
/* It is unlikely that the function table will not have been loaded by the
time this is called, but we'll cover the bases anyhow */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */
return;
}
/* if we weren't returning void, we'd do error handling here */
}
pfnSiTerminate();
SpwErrorVal = *pDllSpwRetVal;
/* Unload the DLL to prevent memory leaks */
FreeLibrary(ghDll);
/* change status in case someone reinitializes */
gInitStatus = NOT_LOADED;
}
/*-----------------------------------------------------------------------------
*
* int SiGetNumDevices (void)
*
* Args:
*
* Return Value:
* If the SpaceWare input library is initialized, the number of devices is
* returned and SpwErrorVal is set to SPW_NO_ERROR. Otherwise, the return
* code is -1 and SpwErrorVal is set to either SI_UNINITIALIZED or one of
* the other standard error codes.
*
* Description:
* This function returns the number of input devices detected by the
* driver.
*
*---------------------------------------------------------------------------*/
int
SiGetNumDevices (void)
{
int tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */
return -1;
}
}
tmpRetVal = pfnSiGetNumDevices();
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* SiDevID SiGetDeviceID (SiHdl hdl)
*
* Args:
* hdl (r/o) SpaceWare handle
*
* Return Value:
* If there is no error, the device ID is returned and SpwErrorVal is set
* to SPW_NO_ERROR. Otherwise, the return value is SI_NO_DEVICE and
* SpwErrorVal is set to either SI_BAD_HANDLE (if the SpaceWare handle is
* invalid) or one of the other standard error codes.
*
* Description:
* Given a SpaceWare handle, this function returns the ID of the
* associated device.
*
*---------------------------------------------------------------------------*/
SiDevID
SiGetDeviceID (SiHdl hdl)
{
SiDevID tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */
return SI_NO_DEVICE;
}
}
tmpRetVal = pfnSiGetDeviceID(hdl);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* SiDevID SiDeviceIndex (int idx)
*
* Args:
* idx (r/o) Device index (zero relative)
*
* Return Value:
* If there is no error, the device ID is returned and SpwErrorVal is set
* to SPW_NO_ERROR. Otherwise, the return value is SI_NO_DEVICE and
* SpwErrorVal is set to either SPW_ERROR (if the device index is invalid),
* SI_UNINITIALIZED, or SI_NO_DRIVER.
*
* Description:
* Given a device index, SiDeviceIndex returns the associated device ID.
* This routine is particularly useful with the function SiGetDevicePort.
*
*---------------------------------------------------------------------------*/
SiDevID
SiDeviceIndex (int idx)
{
SiDevID tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
SpwErrorVal = SPW_DLL_LOAD_ERROR; /* global variable */
return SI_NO_DEVICE;
}
}
tmpRetVal = pfnSiDeviceIndex(idx);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* int SiDispatch (SiHdl hdl, SiGetEventData *pData, SiSpwEvent *pEvent,
* SiSpwHandlers *pHandlers)
*
* Args:
* hdl (r/o) SpaceWare handle
* pData (r/o) Pntr to platform specific data (as passed to SiGetEvent)
* pEvent (r/o) Pntr to SpaceWare event (as returned by SiGetEvent)
* pHandlers (r/o) Pntr to SpaceWare event handlers
*
* Return Value:
* Value returned by called event handler or zero if handler not defined.
*
* Description:
* Provided as a companion to SiGetEvent, this function calls the appro-
* priate handler to process the SpaceWare event returned by SiGetEvent.
* The SiSpwHandlers structure contains one handler for each event type.
* An event type can be ignored by setting the func member of the appro-
* priate SiEventHandler structure to NULL. Unlike the handler for
* SiGetEvent, there is no specific use for the function return value of
* these handlers -- the interpretation is entirely the caller's.
*
*---------------------------------------------------------------------------*/
int
SiDispatch (SiHdl hdl, SiGetEventData *pData,
SiSpwEvent *pEvent, SiSpwHandlers *pDHandlers)
{
int tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return 0;
}
}
tmpRetVal = pfnSiDispatch(hdl, pData, pEvent, pDHandlers);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* void SiOpenWinInit (SiOpenData *pData, HWND hWnd)
*
* Args:
* pData (w/o) Pointer to storage for returned platform specific data
* hWnd (r/o) Window handle
*
* Return Value:
* Nothing
*
* Description:
* This function initializes the Windows platform specific data for a
* subsequent call to SiOpen.
*
*---------------------------------------------------------------------------*/
void
SiOpenWinInit (SiOpenData *pData, HWND hWnd)
{
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
pData = NULL;
hWnd = NULL;
return;
}
}
pfnSiOpenWinInit(pData, hWnd);
SpwErrorVal = *pDllSpwRetVal;
}
/*-----------------------------------------------------------------------------
*
* SiHdl SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
* SiOpenData *pData)
*
* Args:
* pAppName (r/o) Pointer to application name
* devID (r/o) Device ID or SI_ANY_DEVICE
* pTMask (r/o) Pointer to device type mask or SI_NO_MASK
* mode (r/o) SpaceWare event retrieval method: SI_EVENT or SI_POLL
* pData (r/o) Pointer to platform specific data if mode is SI_EVENT
*
* Return Value:
* SpaceWare handle or SI_NO_HANDLE if error. SpwErrorVal is set to one
* of the following:
*
* SPW_NO_ERROR No error
* SPW_ERROR Device could not be opened
* SI_BAD_ID Invalid device ID
* SI_BAD_VALUE Invalid argument
* SI_UNSUPPORTED Specified retrieval method is unsupported
*
* Description:
* SiOpen is called to open a device for input and (sometimes) output
* access. The device in which to open is indicated via the device ID
* (devID) and a device type mask (pTMask). If the ID of a particular
* device is known, it is passed in devID. If the ID is not known or the
* application simply doesn't care which device is selected, devID is passed
* as SI_ANY_DEVICE.
*
* Irrespective of the device ID, the device type mask indicates which
* device types are permitted. The type may be constrained to particular
* devices, classes, or any combination thereof. The mask is created via
* the function SiSetTypeMask (see the definition of that function for more
* information). If the application doesn't wish to constrain the selection
* to any particular types or classes, pTMask may be passed as SI_NO_MASK.
* This is the equivalent of passing a mask set to SI_ALL_TYPES.
*
* The following table shows how a device is selected based on the device ID
* and type mask. In those cases where SI_ANY_DEVICE is specified, the
* order in which the devices are searched is the same order as indexed by
* the function SiDevIndex.
*
* devID pTMask Device selected
*
* SI_ANY_DEVICE SI_NO_MASK The first available device in the list.
*
* A device ID SI_NO_MASK The device matching the specified ID if
* it's available.
*
* SI_ANY_DEVICE A type mask The first available device in the list
* with a type or class that is specified
* in the mask.
*
* A device ID A type mask The device matching the specified ID if
* its type or class matches one specified
* in the mask and it's available.
*
* Note that some SpaceWare implementations will run only if all of the
* configured devices are attached and working properly. Thus, all of the
* devices are available. Other implementations may run with some devices
* not working. These constitute unavailable devices.
*
* The mode argument specifies how the application intends to retrieve
* data from the device. SI_EVENT indicates that the application should
* be informed, via a system event message, whenever device data is
* pending. The message is acknowledged by a call to SiGetEvent. When
* this mode is selected, pData points to the platform specific informa-
* tion necessary for the API to generate system event messages. The mode
* SI_POLL indicates that the application will check for data from the
* device by calling SiGetEvent regularly. For this mode, pData is passed
* as NULL.
*
*---------------------------------------------------------------------------*/
SiHdl
SiOpen (char *pAppName, SiDevID devID, SiTypeMask *pTMask, int mode,
SiOpenData *pData)
{
SiHdl tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
SpwErrorVal = SPW_DLL_LOAD_ERROR;
return NULL;
}
}
tmpRetVal = pfnSiOpen(pAppName, devID, pTMask, mode, pData);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiClose (SiHdl hdl)
*
* Args:
* hdl (r/o) SpaceWare handle
*
* Return Value:
* SPW_NO_ERROR No error
* SPW_ERROR Close error
* SI_BAD_HANDL Invalid SpaceWare handle
*
* Description:
* This function closes a device. Once closed, the SpaceWare handle is
* no longer valid.
*
*---------------------------------------------------------------------------*/
enum
SpwRetVal SiClose (SiHdl hdl)
{
enum SpwRetVal tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return SPW_DLL_LOAD_ERROR;
}
}
tmpRetVal = pfnSiClose(hdl);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* SPWbool SiIsSpaceWareEvent (SiGetEventData *pData, SiHdl *pHdl)
*
* Args:
* pData (r/o) Pointer to platform specific data
* pHdl (w/o) Pointer to storage for returned SpaceWare handle
*
* Return Value:
* SPW_TRUE if pData refers to a SpaceWare event, otherwise SPW_FALSE.
*
* Description:
* This function determines whether or not the data addressed by pData per-
* tains to a SpaceWare event. If so, the handle for which the event is
* intended is returned.
*
* Notes:
* NULL may be passed for pHdl if the return of the intended handle is not
* required.
*
*---------------------------------------------------------------------------*/
SPWbool
SiIsSpaceWareEvent(SiGetEventData *pData, SiHdl *pHdl)
{
SPWbool tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return SPW_FALSE;
}
}
tmpRetVal = pfnSiIsSpaceWareEvent(pData, pHdl);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* void SiGetEventWinInit (SiGetEventData *pData,
* UINT msg, WPARAM wParam, LPARAM lParam)
*
* Args:
* pData (w/o) Pointer to storage for returned platform specific data
* msg (r/o) Windows message
* wParam (r/o) Parameter #1
* lParam (r/o) Parameter #2
*
* Return Value:
* Nothing
*
* Description:
* This function initializes the Windows platform specific data for a
* subsequent call to SiGetEvent.
*
*---------------------------------------------------------------------------*/
void
SiGetEventWinInit (SiGetEventData *pData, UINT msg, WPARAM wParam,
LPARAM lParam)
{
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return;
}
}
pfnSiGetEventWinInit(pData, msg, wParam, lParam);
SpwErrorVal = *pDllSpwRetVal;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiGetEvent (SiHdl hdl, int flags,
* SiGetEventData *pData, SiSpwEvent *pEvent)
*
* Args:
* hdl (r/o) SpaceWare handle
* flags (r/o) Processing flags
* pData (r/o) Pointer to platform specific data
* pEvent (w/o) Pointer to storage for returned SpaceWare event
*
* Return Value:
* SI_BAD_HANDLE Invalid SpaceWare handle
* SI_NOT_EVENT The event is not a SpaceWare event or no event pending
* SI_IS_EVENT The event is a SpaceWare event
* SI_SKIP_EVENT The event is a SpaceWare event but it should be skipped
*
* Description:
* This function determines if device data is pending and if so, returns
* the data as a SpaceWare event. See the "SpaceWare Universal API"
* specification for a complete description of this function.
*
*---------------------------------------------------------------------------*/
enum SpwRetVal
SiGetEvent (SiHdl hdl, int flags, SiGetEventData *pData,
SiSpwEvent *pEvent)
{
enum SpwRetVal tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return SPW_DLL_LOAD_ERROR;
}
}
tmpRetVal = pfnSiGetEvent(hdl, flags, pData, pEvent);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiBeep (SiHdl hdl, char *pString)
*
* Args:
* hdl (r/o) SpaceWare handle
* pString (r/o) Pointer to beep description string
*
* Return Value:
* SPW_NO_ERROR No error
* SI_BAD_HANDLE Invalid SpaceWare handle
* SI_BAD_VALUE Bad string
*
* Description:
* If supported, this function causes the input device to emit a sequence
* of tones and pauses. Each character of the string represents either a
* tone or a delay. Lowercase letters [a-z] represent a tone, uppercase
* letters [A-Z] represent a pause. The closer the letter is to the
* beginning of the alphabet the shorter the pause or tone ('a' or 'A' is
* 1/32 second, 'b' or 'B' is 2/32 second, etc). Up to 14 characters in
* a string are processed, additional characters are ignored.
*
*---------------------------------------------------------------------------*/
enum SpwRetVal
SiBeep(SiHdl hdl, char *pString)
{
enum SpwRetVal tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return SPW_DLL_LOAD_ERROR;
}
}
tmpRetVal = pfnSiBeep(hdl, pString);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiRezero (SiHdl hdl)
*
* Args:
* hdl (r/o) SpaceWare handle
*
* Return Value:
* SPW_NO_ERROR No error
* SI_BAD_HANDLE Invalid SpaceWare handle
*
* Description:
* This function causes the input device's current setting to be defined
* as the rest position. Movement away from this position will cause
* motion events. This can be used to eliminate drift or to set up a
* constant motion.
*
*---------------------------------------------------------------------------*/
enum SpwRetVal
SiRezero (SiHdl hdl)
{
enum SpwRetVal tmpRetVal; /* temporary return value */
if (gInitStatus != LOADED)
{
SiInitialize();
if (gInitStatus == FAILED)
{
return SPW_DLL_LOAD_ERROR;
}
}
tmpRetVal = pfnSiRezero(hdl);
SpwErrorVal = *pDllSpwRetVal;
return tmpRetVal;
}
/*-----------------------------------------------------------------------------
*
* enum SpwRetVal SiGrabDevice (SiHdl hdl, SPWbool exclusive)
*
* Args:
* hdl (r/o) SpaceWare handle
* exclusive (r/o) Exclusive grab flag
*
* Return Value:
* SPW_NO_ERROR No error