This repository was archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathPSMoveClient_CAPI.h
More file actions
1597 lines (1398 loc) · 80.7 KB
/
PSMoveClient_CAPI.h
File metadata and controls
1597 lines (1398 loc) · 80.7 KB
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
/**
\file
*/
#ifndef __PSMOVECLIENT_CAPI_H
#define __PSMOVECLIENT_CAPI_H
#include "PSMoveClient_export.h"
#include "ClientConstants.h"
#include "ClientGeometry_CAPI.h"
#include <stdbool.h>
//cut_before
/**
\brief Client Interface for PSMoveService
\defgroup PSMoveClient_CAPI Client Interface
\addtogroup PSMoveClient_CAPI
@{
*/
// Wrapper Types
//--------------
/// The ID of a pending request send to PSMoveService
typedef int PSMRequestID;
/// Opaque handle to the internal protocol buffer response
typedef const void * PSMResponseHandle;
/// Opaque handle to the internal protocol buffer request
typedef void *PSMRequestHandle;
/// opaque handle to the internal protocol buffer event
typedef const void *PSMEventDataHandle;
/// The ID of a controller in the controller pool
typedef int PSMControllerID;
/// The ID of a tracker in the tracker pool
typedef int PSMTrackerID;
/// The ID of an HMD in the HMD pool
typedef int PSMHmdID;
// Shared Constants
//-----------------
/// Invalid Request ID constant
const PSMRequestID PSM_INVALID_REQUEST_ID = -1;
/// Result enum in response to a client API request
typedef enum
{
PSMResult_Error = -1, ///< General Error Result
PSMResult_Success = 0, ///< General Success Result
PSMResult_Timeout = 1, ///< Requested Timed Out
PSMResult_RequestSent = 2, ///< Request Successfully Sent
PSMResult_Canceled = 3, ///< Request Canceled
PSMResult_NoData = 4, ///< Request Returned No Data
} PSMResult;
/// Connection type for a device
typedef enum
{
PSMConnectionType_BLUETOOTH, ///< Device connected over bluetooth
PSMConnectionType_USB ///< Device connected over USB
} PSMConnectionType;
/// De-bounced state of a button
typedef enum
{
PSMButtonState_UP = 0x00, ///< (00b) Not pressed
PSMButtonState_PRESSED = 0x01, ///< (01b) Down for one frame only
PSMButtonState_DOWN = 0x03, ///< (11b) Down for >1 frame
PSMButtonState_RELEASED = 0x02, ///< (10b) Up for one frame only
} PSMButtonState;
/// The available tracking color types
typedef enum
{
PSMTrackingColorType_Magenta, ///< R:0xFF, G:0x00, B:0xFF
PSMTrackingColorType_Cyan, ///< R:0x00, G:0xFF, B:0xFF
PSMTrackingColorType_Yellow, ///< R:0xFF, G:0xFF, B:0x00
PSMTrackingColorType_Red, //</ R:0xFF, G:0x00, B:0x00
PSMTrackingColorType_Green, ///< R:0x00, G:0xFF, B:0x00
PSMTrackingColorType_Blue, ///< R:0x00, G:0x00, B:0xFF
PSMTrackingColorType_MaxColorTypes
} PSMTrackingColorType;
/// Battery charge state levels
typedef enum
{
PSMBattery_0 = 0,
PSMBattery_20 = 1,
PSMBattery_40 = 2,
PSMBattery_60 = 3,
PSMBattery_80 = 4,
PSMBattery_100 = 5,
PSMBattery_Charging = 0xEE,
PSMBattery_Charged = 0xEF
} PSMBatteryState;
/// Tracked device data stream options
typedef enum
{
PSMStreamFlags_defaultStreamOptions = 0x00, ///< Default minimal data stream
PSMStreamFlags_includePositionData = 0x01, ///< Add position data (turns on tracking)
PSMStreamFlags_includePhysicsData = 0x02, ///< Add IMU physics state
PSMStreamFlags_includeRawSensorData = 0x04, ///< Add raw IMU sensor data
PSMStreamFlags_includeCalibratedSensorData = 0x08, ///< Add calibrated IMU sensor state
PSMStreamFlags_includeRawTrackerData = 0x10, ///< Add raw optical tracking projection info
PSMStreamFlags_disableROI = 0x20, ///< Disable Region-of-Interest tracking optimization
} PSMControllerDataStreamFlags;
/// The possible rumble channels available to the comtrollers
typedef enum
{
PSMControllerRumbleChannel_All, ///< Rumble across all channels
PSMControllerRumbleChannel_Left, ///< Rumble on the left channel
PSMControllerRumbleChannel_Right ///< Runble on the right channel
} PSMControllerRumbleChannel;
/// The list of possible controller types tracked by PSMoveService
typedef enum
{
PSMController_None= -1,
PSMController_Move,
PSMController_Navi,
PSMController_DualShock4,
PSMController_Virtual
} PSMControllerType;
/// Describes which hand the given device is intended for
typedef enum
{
PSMControllerHand_Any = 0,
PSMControllerHand_Left = 1,
PSMControllerHand_Right = 2,
} PSMControllerHand;
/// The list of possible camera types tracked by PSMoveService
typedef enum
{
PSMTracker_None= -1,
PSMTracker_PS3Eye
} PSMTrackerType;
/// The list of possible HMD types tracked by PSMoveService
typedef enum
{
PSMHmd_None= -1,
PSMHmd_Morpheus= 0,
PSMHmd_Virtual= 1,
} PSMHmdType;
/// The list of possible camera drivers used by PSMoveService
typedef enum
{
PSMDriver_LIBUSB,
PSMDriver_CL_EYE,
PSMDriver_CL_EYE_MULTICAM,
PSMDriver_GENERIC_WEBCAM
} PSMTrackerDriver;
// Controller State
//------------------
/// Tracked object physics data state
typedef struct
{
PSMVector3f LinearVelocityCmPerSec;
PSMVector3f LinearAccelerationCmPerSecSqr;
PSMVector3f AngularVelocityRadPerSec;
PSMVector3f AngularAccelerationRadPerSecSqr;
double TimeInSeconds;
} PSMPhysicsData;
/// Raw Sensor data from the PSMove IMU
typedef struct
{
PSMVector3i Magnetometer;
PSMVector3i Accelerometer;
PSMVector3i Gyroscope;
double TimeInSeconds;
} PSMPSMoveRawSensorData;
/// Calibrated Sensor
typedef struct
{
PSMVector3f Magnetometer;
PSMVector3f Accelerometer;
PSMVector3f Gyroscope;
double TimeInSeconds;
} PSMPSMoveCalibratedSensorData;
/// Device projection geometry as seen by each tracker
typedef struct
{
/// ID of the selected tracker
PSMTrackerID TrackerID;
/// Pixel position of device projection centroid on each tracker
PSMVector2f ScreenLocation;
/// Tracker relative device 3d position on each tracker
PSMVector3f RelativePositionCm;
/// Tracker relative device 3d orientation on each tracker
PSMQuatf RelativeOrientation;
/// Tracker relative device projection geometry on each tracker
PSMTrackingProjection TrackingProjection;
/// A bitmask of the trackers with valid projections
unsigned int ValidTrackerBitmask;
// Multicam triangulated position and orientation, pre-filtered
/// Optically derived world space position of device in cm
PSMVector3f MulticamPositionCm;
/// Optically derived world space orientation of device in cm
PSMQuatf MulticamOrientation;
/// Flag if the world space optical position is valid
bool bMulticamPositionValid;
/// Flag if the world space optical orientation is valid
bool bMulticamOrientationValid;
} PSMRawTrackerData;
/// PSMove Controller State in Controller Pool Entry
typedef struct
{
bool bHasValidHardwareCalibration;
bool bIsTrackingEnabled;
bool bIsCurrentlyTracking;
bool bIsOrientationValid;
bool bIsPositionValid;
bool bHasUnpublishedState;
char DevicePath[256];
char DeviceSerial[128];
char AssignedHostSerial[128];
bool PairedToHost;
PSMConnectionType ConnectionType;
PSMTrackingColorType TrackingColorType;
PSMPosef Pose;
PSMPhysicsData PhysicsData;
PSMPSMoveRawSensorData RawSensorData;
PSMPSMoveCalibratedSensorData CalibratedSensorData;
PSMRawTrackerData RawTrackerData;
PSMButtonState TriangleButton;
PSMButtonState CircleButton;
PSMButtonState CrossButton;
PSMButtonState SquareButton;
PSMButtonState SelectButton;
PSMButtonState StartButton;
PSMButtonState PSButton;
PSMButtonState MoveButton;
PSMButtonState TriggerButton;
PSMBatteryState BatteryValue;
unsigned char TriggerValue;
unsigned char Rumble;
unsigned char LED_r, LED_g, LED_b;
long long ResetPoseButtonPressTime;
bool bResetPoseRequestSent;
bool bPoseResetButtonEnabled;
} PSMPSMove;
/// PSNavi Controller State in Controller Pool Entry
typedef struct
{
PSMButtonState L1Button;
PSMButtonState L2Button;
PSMButtonState L3Button;
PSMButtonState CircleButton;
PSMButtonState CrossButton;
PSMButtonState PSButton;
PSMButtonState TriggerButton;
PSMButtonState DPadUpButton;
PSMButtonState DPadRightButton;
PSMButtonState DPadDownButton;
PSMButtonState DPadLeftButton;
unsigned char TriggerValue;
unsigned char Stick_XAxis;
unsigned char Stick_YAxis;
} PSMPSNavi;
/// DualShock4 raw IMU sensor data
typedef struct
{
PSMVector3i Accelerometer;
PSMVector3i Gyroscope;
double TimeInSeconds;
} PSMDS4RawSensorData;
/// DualShock4 calibrated IMU sensor data
typedef struct
{
PSMVector3f Accelerometer;
PSMVector3f Gyroscope;
double TimeInSeconds;
} PSMDS4CalibratedSensorData;
/// DualShock4 Controller State in Controller Pool Entry
typedef struct
{
bool bHasValidHardwareCalibration;
bool bIsTrackingEnabled;
bool bIsCurrentlyTracking;
bool bIsOrientationValid;
bool bIsPositionValid;
bool bHasUnpublishedState;
char DevicePath[256];
char DeviceSerial[128];
char AssignedHostSerial[128];
bool PairedToHost;
PSMConnectionType ConnectionType;
PSMTrackingColorType TrackingColorType;
PSMPosef Pose;
PSMPhysicsData PhysicsData;
PSMDS4RawSensorData RawSensorData;
PSMDS4CalibratedSensorData CalibratedSensorData;
PSMRawTrackerData RawTrackerData;
PSMButtonState DPadUpButton;
PSMButtonState DPadDownButton;
PSMButtonState DPadLeftButton;
PSMButtonState DPadRightButton;
PSMButtonState SquareButton;
PSMButtonState CrossButton;
PSMButtonState CircleButton;
PSMButtonState TriangleButton;
PSMButtonState L1Button;
PSMButtonState R1Button;
PSMButtonState L2Button;
PSMButtonState R2Button;
PSMButtonState L3Button;
PSMButtonState R3Button;
PSMButtonState ShareButton;
PSMButtonState OptionsButton;
PSMButtonState PSButton;
PSMButtonState TrackPadButton;
float LeftAnalogX;
float LeftAnalogY;
float RightAnalogX;
float RightAnalogY;
float LeftTriggerValue;
float RightTriggerValue;
unsigned char BigRumble, SmallRumble;
unsigned char LED_r, LED_g, LED_b;
long long ResetPoseButtonPressTime;
bool bResetPoseRequestSent;
bool bPoseResetButtonEnabled;
} PSMDualShock4;
/// Virtual Controller State in Controller Pool Entry
typedef struct
{
bool bIsTrackingEnabled;
bool bIsCurrentlyTracking;
bool bIsPositionValid;
char DevicePath[256];
int vendorID;
int productID;
int numAxes;
int numButtons;
unsigned char axisStates[PSM_MAX_VIRTUAL_CONTROLLER_AXES];
PSMButtonState buttonStates[PSM_MAX_VIRTUAL_CONTROLLER_BUTTONS];
PSMTrackingColorType TrackingColorType;
PSMPosef Pose;
PSMPhysicsData PhysicsData;
PSMRawTrackerData RawTrackerData;
} PSMVirtualController;
/// Controller Pool Entry
typedef struct
{
PSMControllerID ControllerID;
PSMControllerType ControllerType;
PSMControllerHand ControllerHand;
union
{
PSMPSMove PSMoveState;
PSMPSNavi PSNaviState;
PSMDualShock4 PSDS4State;
PSMVirtualController VirtualController;
} ControllerState;
bool bValid;
int OutputSequenceNum;
int InputSequenceNum;
bool IsConnected;
long long DataFrameLastReceivedTime;
float DataFrameAverageFPS;
int ListenerCount;
} PSMController;
// Tracker State
//--------------
/// Static properties about a tracker
typedef struct
{
// ID of the tracker in the service
PSMTrackerID tracker_id;
// Tracker USB properties
PSMTrackerType tracker_type;
PSMTrackerDriver tracker_driver;
char device_path[128];
// Video stream properties
char shared_memory_name[64];
// Camera Intrinsic properties
PSMVector2f tracker_focal_lengths; ///< lens focal length in pixels
PSMVector2f tracker_principal_point; ///< lens center point in pixels
PSMVector2f tracker_screen_dimensions; ///< tracker image size in pixels
float tracker_hfov; ///< tracker horizontal FOV in degrees
float tracker_vfov; ///< tracker vertical FOV in degrees
float tracker_znear; ///< tracker z-near plane distance in cm
float tracker_zfar; ///< tracker z-far plane distance in cm
float tracker_k1; ///< lens distortion coefficient k1
float tracker_k2; ///< lens distortion coefficient k2
float tracker_k3; ///< lens distortion coefficient k3
float tracker_p1; ///< lens distortion coefficient p1
float tracker_p2; ///< lens distortion coefficient p2
// Camera Extrinsic properties
PSMPosef tracker_pose; ///< World space location of tracker (relative to calibration mat)
} PSMClientTrackerInfo;
/// Tracker Pool Entry
typedef struct
{
// Tracker Static Properties
PSMClientTrackerInfo tracker_info;
// Tracker Streaming State
int listener_count;
bool is_connected;
int sequence_num;
long long data_frame_last_received_time;
float data_frame_average_fps;
// SharedVideoFrameReadOnlyAccessor used by config tool
void *opaque_shared_memory_accesor;
} PSMTracker;
// HMD State
//----------
/// Morpheus Raw IMU sensor data
typedef struct
{
PSMVector3i Accelerometer;
PSMVector3i Gyroscope;
double TimeInSeconds;
} PSMMorpheusRawSensorData;
/// Morpheus Calibrated IMU sensor data
typedef struct
{
PSMVector3f Accelerometer;
PSMVector3f Gyroscope;
double TimeInSeconds;
} PSMMorpheusCalibratedSensorData;
/// Morpheus HMD State in HMD Pool Entry
typedef struct
{
bool bIsTrackingEnabled;
bool bIsCurrentlyTracking;
bool bIsOrientationValid;
bool bIsPositionValid;
PSMPosef Pose;
PSMPhysicsData PhysicsData;
PSMMorpheusRawSensorData RawSensorData;
PSMMorpheusCalibratedSensorData CalibratedSensorData;
PSMRawTrackerData RawTrackerData;
} PSMMorpheus;
/// Virtual HMD State in HMD Pool Entry
typedef struct
{
bool bIsTrackingEnabled;
bool bIsCurrentlyTracking;
bool bIsPositionValid;
PSMPosef Pose;
PSMPhysicsData PhysicsData;
PSMRawTrackerData RawTrackerData;
} PSMVirtualHMD;
/// HMD Pool Entry
typedef struct
{
PSMHmdID HmdID;
PSMHmdType HmdType;
union
{
PSMMorpheus MorpheusState;
PSMVirtualHMD VirtualHMDState;
} HmdState;
bool bValid;
int OutputSequenceNum;
bool IsConnected;
long long DataFrameLastReceivedTime;
float DataFrameAverageFPS;
int ListenerCount;
} PSMHeadMountedDisplay;
// Service Events
//------------------
/// A container for all PSMoveService events
typedef struct
{
enum eEventType
{
// Client Events
PSMEvent_connectedToService,
PSMEvent_failedToConnectToService,
PSMEvent_disconnectedFromService,
// Service Events
PSMEvent_opaqueServiceEvent, // Need to have protocol access to see what kind of event this is
PSMEvent_controllerListUpdated,
PSMEvent_trackerListUpdated,
PSMEvent_hmdListUpdated,
PSMEvent_systemButtonPressed
} event_type;
/// Opaque handle that can be converted to a <const PSMoveProtocol::Response *> pointer
/// using GET_PSMOVEPROTOCOL_EVENT(handle) if you linked against the PSMoveProtocol lib.
PSMEventDataHandle event_data_handle;
} PSMEventMessage;
// Service Responses
//------------------
/// Current version of PSMoveService
typedef struct
{
char version_string[PSMOVESERVICE_MAX_VERSION_STRING_LEN];
} PSMServiceVersion;
/// List of controllers attached to PSMoveService
typedef struct
{
PSMControllerID controller_id[PSMOVESERVICE_MAX_CONTROLLER_COUNT];
PSMControllerType controller_type[PSMOVESERVICE_MAX_CONTROLLER_COUNT];
PSMControllerHand controller_hand[PSMOVESERVICE_MAX_CONTROLLER_COUNT];
char controller_serial[PSMOVESERVICE_MAX_CONTROLLER_COUNT][PSMOVESERVICE_CONTROLLER_SERIAL_LEN];
char parent_controller_serial[PSMOVESERVICE_MAX_CONTROLLER_COUNT][PSMOVESERVICE_CONTROLLER_SERIAL_LEN];
int count;
} PSMControllerList;
/// List of trackers connected to PSMoveService
typedef struct
{
PSMClientTrackerInfo trackers[PSMOVESERVICE_MAX_TRACKER_COUNT];
int count;
float global_forward_degrees;
} PSMTrackerList;
/// List of HMDs connected to PSMoveSerivce
typedef struct
{
PSMHmdID hmd_id[PSMOVESERVICE_MAX_HMD_COUNT];
PSMHmdType hmd_type[PSMOVESERVICE_MAX_HMD_COUNT];
int count;
} PSMHmdList;
/// Tracking Space Parameters
typedef struct
{
float global_forward_degrees;
} PSMTrackingSpace;
/// A contrainer for all possible responses to requests sent from PSMoveService
typedef struct
{
/// The id of the request this response is from
PSMRequestID request_id;
/// Whether this request succeeded, failed, or was canceled
PSMResult result_code;
/// Opaque handle that can be converted to a <const PSMoveProtocol::Request *> pointer
/// using GET_PSMOVEPROTOCOL_REQUEST(handle) if you linked against the PSMoveProtocol lib.
PSMResponseHandle opaque_request_handle;
/// Opaque handle that can be converted to a <const PSMoveProtocol::Response *> pointer
/// using GET_PSMOVEPROTOCOL_RESPONSE(handle) if you linked against the PSMoveProtocol lib.
PSMResponseHandle opaque_response_handle;
/// Payload data specific to a subset of the responses
union
{
PSMServiceVersion service_version; ///< Response to service version request
PSMControllerList controller_list; ///< Response to controller list request
PSMTrackerList tracker_list; ///< Response to tracker list request
PSMHmdList hmd_list; ///< Response to hmd list request
PSMTrackingSpace tracking_space; ///< Response to tracking space request
} payload;
/// Type of response sent from PSMoveService
enum eResponsePayloadType
{
_responsePayloadType_Empty,
_responsePayloadType_ServiceVersion,
_responsePayloadType_ControllerList,
_responsePayloadType_TrackerList,
_responsePayloadType_TrackingSpace,
_responsePayloadType_HmdList,
_responsePayloadType_Count
} payload_type;
} PSMResponseMessage;
/// Registered response callback function for a PSMoveService request
typedef void(*PSMResponseCallback)(const PSMResponseMessage *response, void *userdata);
// Message Container
//------------------
/// Message container for responses and events sent from PSMoveService
typedef struct
{
union{
PSMEventMessage event_data; ///< Event sent about something changing in PSMoveService
PSMResponseMessage response_data; ///< Response sent from PSMoveService` in reply to a request
};
enum eMessagePayloadType
{
_messagePayloadType_Event,
_messagePayloadType_Response,
_messagePayloadType_Count
} payload_type;
} PSMMessage;
// Interface
//----------
// Blocking Connection Methods
/** \brief Initializes a connection to PSMoveService.
Attempts to connect to PSMService at the given address and port.
This function must be called before calling any other client functions.
Calling this function again after a connection is already started will return PSMResult_Success.
\remark Blocking - Returns after either a connection is successfully established OR the timeout period is reached.
\param host The address that PSMoveService is running at, usually PSMOVESERVICE_DEFAULT_ADDRESS
\param port The port that PSMoveSerive is running at, usually PSMOVESERVICE_DEFAULT_PORT
\param timeout The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\returns PSMResult_Success on success, PSMResult_Timeout, or PSMResult_Error on a general connection error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_Initialize(const char* host, const char* port, int timeout_ms);
/** \brief Shuts down connection to PSMoveService
Closes an active connection to PSMoveService and cleans out any pending requests.
This function should be called when closing down the client OR to reset a client connection.
Calling this function again after a connection is alread closed will return PSMResult_Error.
\returns PSMResult_Success on success or PSMResult_Error if there was no valid connection.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_Shutdown();
// Async Connection Methods
/** \brief Initializes a connection to PSMoveService.
Starts connection process to PSMService at the given address and port.
This function must be called before calling any other client functions.
Calling this function again after a connection has already been requested will return PSMResult_RequestSent.
\remark Async - Starts a request for login. Connection status can be tested one of two ways:
- Call \ref PSM_Update() and then test \ref PSM_HasConnectionStatusChanged() is true
- Call \ref PSM_UpdateNoPollMessages() and then call \ref PSM_PollNextMessage() to see if an event is received:
- \ref PSMEvent_connectedToService
- \ref PSMEvent_failedToConnectToService
.
\param host The address that PSMoveService is running at, usually PSMOVESERVICE_DEFAULT_ADDRESS
\param port The port that PSMoveSerive is running at, usually PSMOVESERVICE_DEFAULT_PORT
\param timeout The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\returns PSMResult_RequestSent on success, PSMResult_Timeout, or PSMResult_Error on a general connection error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_InitializeAsync(const char* host, const char* port);
// Update
/** \brief Poll the connection and process messages.
This function will poll the connection for new messages from PSMoveService.
If new events are received they are processed right away and the the appropriate status flag will be set.
Any received responses that had a callback assigned to them will be called.
The following state polling functions can be called after an update:
- \ref PSM_GetIsConnected()
- \ref PSM_HasConnectionStatusChanged()
- \ref PSM_HasControllerListChanged()
- \ref PSM_HasTrackerListChanged()
- \ref PSM_HasHMDListChanged()
- \ref PSM_WasSystemButtonPressed()
\return PSMResult_Success if there is an active connection or PSMResult_Error if there is no valid connection
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_Update();
/** \brief Poll the connection and DO NOT process messages.
This function will poll the connection for new messages from PSMoveService.
If new events are received they are put in a queue. The messages are extracted using \ref PSM_PollNextMessage().
Messages not read from the queue will get cleared on the next update call.
\return PSMResult_Success if there is an active connection or PSMResult_Error if there is no valid connection
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_UpdateNoPollMessages();
// System State Queries
/** \brief Get the client API version string
\return A zero-terminated version string of the format "Product.Major-Phase Minor.Release.Hotfix", ex: "0.9-alpha 8.1.0"
*/
PSM_PUBLIC_FUNCTION(const char*) PSM_GetClientVersionString();
/** \brief Get the API initialization status
\return true if the client API is initialized
*/
PSM_PUBLIC_FUNCTION(bool) PSM_GetIsInitialized();
/** \brief Get the client connection status
\return true if the client is connected to PSMoveService
*/
PSM_PUBLIC_FUNCTION(bool) PSM_GetIsConnected();
/** \brief Get the connection status change flag
This flag is only filled in when \ref PSM_Update() is called.
If you instead call PSM_UpdateNoPollMessages() you'll need to process the event queue yourself to get connection
status change events.
\return true if the client is connection status changed
*/
PSM_PUBLIC_FUNCTION(bool) PSM_HasConnectionStatusChanged();
/** \brief Get the controller list change flag
This flag is only filled in when \ref PSM_Update() is called.
If you instead call PSM_UpdateNoPollMessages() you'll need to process the event queue yourself to get controller
list change events.
\return true if the controller list changed
*/
PSM_PUBLIC_FUNCTION(bool) PSM_HasControllerListChanged();
/** \brief Get the tracker list change flag
This flag is only filled in when \ref PSM_Update() is called.
If you instead call PSM_UpdateNoPollMessages() you'll need to process the event queue yourself to get tracker
list change events.
\return true if the tracker list changed
*/
PSM_PUBLIC_FUNCTION(bool) PSM_HasTrackerListChanged();
/** \brief Get the HMD list change flag
This flag is only filled in when \ref PSM_Update() is called.
If you instead call PSM_UpdateNoPollMessages() you'll need to process the event queue yourself to get HMD
list change events.
\return true if the HMD list changed
*/
PSM_PUBLIC_FUNCTION(bool) PSM_HasHMDListChanged();
/** \brief Get the "any system button pressed" flag
This flag is only filled in when \ref PSM_Update() is called.
If you instead call PSM_UpdateNoPollMessages() you'll need to process the event queue yourself to get HMD
list change events.
This is useful if the client need to send a "wake up" notification on system button press.
\return true if the system button (i.e. the "PS" button) was pressed on any controller this update.
*/
PSM_PUBLIC_FUNCTION(bool) PSM_WasSystemButtonPressed();
// System Blocking Queries
/** \brief Get the client API version string from PSMoveService
Sends a request to PSMoveService to get the protocol version.
This should be compared against the version returned from \ref PSM_GetClientVersionString() as a way to verify
that the an outdated client isn't being used with PSMoveService.
\remark Blocking - Returns after either the version string is returned OR the timeout period is reached.
\param[out] out_version_string The string buffer to write the version into
\param max_version_string The size of the output buffer
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_GetServiceVersionString(char *out_version_string, size_t max_version_string, int timeout_ms);
// System Async Queries
/** \brief Get the client API version string from PSMoveService
Sends a request to PSMoveService to get the protocol version.
This should be compared against the version returned from \ref PSM_GetClientVersionString() as a way to verify
that the an outdated client isn't being used with PSMoveService.
\remark Async - Starts a request for version string. Result obtained in one of two ways:
- Register callback for request id with \ref PSM_RegisterCallback and the poll with \ref PSM_Update()
- Poll with \ref PSM_UpdateNoPollMessages() and then call \ref PSM_PollNextMessage() to see if
\ref PSMServiceVersion result has been received.
\param[out] out_request_id The id of the request sent to PSMoveService. Can be used to register callback with \ref PSM_RegisterCallback.
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_GetServiceVersionStringAsync(PSMRequestID *out_request_id);
// Async Message Handling API
/** \brief Retrieve the next message from the message queue.
A call to \ref PSM_UpdateNoPollMessages will queue messages received from PSMoveService.
Use this function to processes the queued event and response messages one by one.
If a response message does not have a callback registered with \ref PSM_RegisterCallback it will get returned here.
\param[out] out_messaage The next \ref PSMMessage read from the incoming message queue.
\param message_size The size of the message structure. Pass in sizeof(PSMMessage).
\return PSMResult_Success or PSMResult_NoData if no more messages are available.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_PollNextMessage(PSMMessage *out_message, size_t message_size);
/** \brief Sends a private protocol request to PSMoveService.
If the client has linked against the PSMoveProtocol.lib and defined the HAS_PROTOCOL_ACCESS symbol then you can
construct a private message declared in PSMoveProtocol.pb.h. These messages are defined in the Google protobuf
definition file, PSMoveProtocol.proto. Typically clients won't need or want to send private messages since many of
the lower level protocol messages are intended for calibration and other service setting options used by the
PSMoveConfigTool.
\param request_handle The pointer to the protocol message
\param[out] out_request_id The id of the request sent to PSMoveService. Can be used to register callback with \ref PSM_RegisterCallback.
\return PSMResult_RequestSent upon successfully sending request or PSMResult_Error if connection is invalid.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_SendOpaqueRequest(PSMRequestHandle request_handle, PSMRequestID *out_request_id);
/** \brief Registers an async request callback
A \ref PSMRequestID is issued for every request sent.
This request_id can be assigned a \ref PSMResponseCallback.
The callback will get called when a responsed is fetched by a call to \ref PSMUpdate or \ref PSMUpdateNoPollMessages.
PSMoveConfigToolback can be cancelled with a call to \ref PSM_CancelCallback.
\param request_id The id of a pending async request
\param callback A callback function pointer
\param callback_userdata Userdata for a callback function (often a "this" pointer to a class that issued the request).
\return PSMResult_Success if the request_id is valid and the connection is active
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_RegisterCallback(PSMRequestID request_id, PSMResponseCallback callback, void *callback_userdata);
/** \brief Cancels a pending async request callback.
This can be used to unregister a callback for a pending async request.
If the response for the request is received later, it will simply get dropped on the floor.
\param request_id The id of a pending request to cancel
\return PSMResult_Success if the request_id is valid and the connection is active
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_CancelCallback(PSMRequestID request_id);
/** \brief Marks a request's response to be ignored.
If \ref PSM_UpdateNoPollMessages is called, responses that don't have a callback registered will get added to the
message queue which can then be fetched by \ref PSM_PollNextMessage.
If instead \ref PSM_Update is called then it expects all requests to have a registered callback.
If no callback is found then a warning is issued and the message is dropped on the floor.
Calling PSM_EatResponse explicly signals that we don't care about the response and will prevent the response from
getting added to the message queue in the first place.
\param request_id The id of a pending request whose response we want to ignore
\return PSMResult_Success if the request_id is valid and the connection is active
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_EatResponse(PSMRequestID request_id);
// Controller Pool
/** \brief Fetches the \ref PSMController data for the given controller
The client API maintains a pool of controller structs.
We can fetch a given controller by \ref PSMControllerID.
DO NOT DELETE the controller pointer returned by this function.
It is safe to copy this pointer on to other structures so long as the pointer is cleared once the client API is shutdown.
\param controller_id The id of the controler structure to fetch
\return A pointer to a \ref PSMController
*/
PSM_PUBLIC_FUNCTION(PSMController *) PSM_GetController(PSMControllerID controller_id);
/** \brief Allocate a reference to a controller.
This function tells the client API to increment a reference count for a given controller.
This function should be called before fetching the controller data using \ref PSM_GetController.
When done with the controller, make sure to call \ref PSM_FreeControllerListener.
\param controller_id The id of the controller we want to allocate a listener for
\return PSMResult_Success if a valid controller id is given
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_AllocateControllerListener(PSMControllerID controller_id);
/** \brief Free a reference to a controller
This function tells the client API to decrement a reference count for a given controller.
\param controller_id The of of the controller we want to free the listener for.
\return PSMResult_Success if a valid controller id is given that has a non-zero ref count
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_FreeControllerListener(PSMControllerID controller_id);
// Blocking Controller Methods
/** \brief Requests a list of the streamable controllers currently connected to PSMoveService.
Sends a request to PSMoveService to get the list of currently streamable controllers.
\remark Blocking - Returns after either the controller list is returned OR the timeout period is reached.
\param[out] out_controller_list The controller list to write the result into.
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_GetControllerList(PSMControllerList *out_controller_list, int timeout_ms);
/** \brief Requests start of an unreliable(udp) data stream for a given controller
Asks PSMoveService to start stream data for the given controller with the given set of stream properties.
The data in the associated \ref PSMController state will get updated automatically in calls to \ref PSM_Update or
\ref PSM_UpdateNoPollMessages.
Requests to restart an already started stream will return an error.
\remark Blocking - Returns after either stream start response comes back OR the timeout period is reached.
\param controller_id The id of the controller to start the stream for.
\param data_stream_flags One or more of the following steam:
- PSMStreamFlags_defaultStreamOptions = minimal controller stream info
- PSMStreamFlags_includePositionData = add position to pose data (which turns on tracking lights)
- PSMStreamFlags_includePhysicsData = add linear and angular velocity and acceleration
- PSMStreamFlags_includeRawSensorData = add raw IMU sensor data values
- PSMStreamFlags_includeCalibratedSensorData = add calibrated sensor data values
- PSMStreamFlags_includeRawTrackerData = add tracker projection info for each tacker
- PSMStreamFlags_disableROI = turns off RegionOfInterest optimization used to reduce CPU load when finding tracking bulb
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_StartControllerDataStream(PSMControllerID controller_id, unsigned int data_stream_flags, int timeout_ms);
/** \brief Requests stop of an unreliable(udp) data stream for a given controller
Asks PSMoveService to start stream data for the given controller with the given set of stream properties.
The data in the associated \ref PSMController state will get updated automatically in calls to \ref PSM_Update or
\ref PSM_UpdateNoPollMessages.
Requests to restart an already started stream will return an error.
\remark Blocking - Returns after either stream start response comes back OR the timeout period is reached.
\param controller_id The id of the controller to start the stream for.
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error. */
PSM_PUBLIC_FUNCTION(PSMResult) PSM_StopControllerDataStream(PSMControllerID controller_id, int timeout_ms);
/** \brief Requests changing the tracking color type of a given controller.
Sends a request to PSMoveService to change the tracking color of a controller.
If another controller already is using the color being assigned to this controller, it will be assigned an available color.
\remark Blocking - Returns after either the new color is set OR the timeout period is reached.
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_SetControllerLEDTrackingColor(PSMControllerID controller_id, PSMTrackingColorType tracking_color, int timeout_ms);
/** \brief Requests resetting the controllers current orientation.
This request is used to reset any drift that has occured in the pose filter's orientation from the controllers true
orientation. Resetting the controller orientation assumes that controller is currently being held in the "identity" orientation,
which is typically pointing down the -Z axis.
This request is typically sent in reponse to a certain combonation of buttons being held (usually SELECT).
\remark Blocking - Returns after either the version string is returned OR the timeout period is reached.
\param controller_id The ID of the whose orientation we want to reset
\param q_pose The pose the controller is currently being held in relative to the identity pose (like straight up).
\param timeout_ms The conection timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_Success upon receiving result, PSMResult_Timeoout, or PSMResult_Error on request error.
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_ResetControllerOrientation(PSMControllerID controller_id, PSMQuatf *q_pose, int timeout_ms);
/** \brief Requests setting the selected tracker index for a controller
This request is used to set the selected tracker index on a controller data stream
when the data stream has tracking projection data active. The projection data is
only provided for the selected tracker.
\remark Blocking - Returns after either the result is returned OR the timeout period is reached.
\param controller_id The ID of the controller whose data stream we want to modify
\param tracker_id The ID of the tracker we want to assign as the active tracker
\param timeout_ms The request timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_RequestSent on success or PSMResult_Error if there was no valid connection
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_SetControllerDataStreamTrackerIndex(PSMControllerID controller_id, PSMTrackerID tracker_id, int timeout_ms);
/** \brief Requests setting the hand assigned to a controller
This request is used to set the suggested hand for a controller.
Hand information is used by external APIs and not by PSMoveService.
No restrictions are made about which hands are assigned to a given controller.
\remark Blocking - Returns after either the result is returned OR the timeout period is reached.
\param controller_id The ID of the controller whose data stream we want to modify
\param hand The hand to assign to a controller (Any, Left or Right)
\param timeout_ms The request timeout period in milliseconds, usually PSM_DEFAULT_TIMEOUT
\return PSMResult_RequestSent on success or PSMResult_Error if there was no valid connection
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_SetControllerHand(PSMControllerID controller_id, PSMControllerHand hand, int timeout_ms);
// Controller State Methods
/** \brief Get the current orientation of a controller
\param controller_id The id of the controller
\param[out] out_orientation The orientation of the controller
\return PSMResult_Success if controller has a valid orientation
*/
PSM_PUBLIC_FUNCTION(PSMResult) PSM_GetControllerOrientation(PSMControllerID controller_id, PSMQuatf *out_orientation);
/** \brief Get the current position of a controller
\param controller_id The id of the controller
\param[out] out_position The position of the controller
\return PSMResult_Success if controller has a valid position
*/