summaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/OVR_DeviceMessages.h
blob: 43f9496533d441d8bf9175ffc2222acd26e76dbc (plain)
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
/************************************************************************************

PublicHeader:   OVR.h
Filename    :   OVR_DeviceMessages.h
Content     :   Definition of messages generated by devices
Created     :   February 5, 2013
Authors     :   Lee Cooper

Copyright   :   Copyright 2013 Oculus VR, Inc. All Rights reserved.

Use of this software is subject to the terms of the Oculus license
agreement provided at the time of installation or download, or which
otherwise accompanies this software in either electronic or hard copy form.

*************************************************************************************/

#ifndef OVR_DeviceMessages_h
#define OVR_DeviceMessages_h

#include "OVR_DeviceConstants.h"
#include "OVR_DeviceHandle.h"

#include "Kernel/OVR_Math.h"
#include "Kernel/OVR_Array.h"
#include "Kernel/OVR_Color.h"

namespace OVR {

class DeviceBase;
class DeviceHandle;


#define OVR_MESSAGETYPE(devName, msgIndex)   ((Device_##devName << 8) | msgIndex)

// MessageType identifies the structure of the Message class; based on the message,
// casting can be used to obtain the exact value.
enum MessageType
{
    // Used for unassigned message types.
    Message_None            = 0,

    // Device Manager Messages
    Message_DeviceAdded             = OVR_MESSAGETYPE(Manager, 0),  // A new device is detected by manager.
    Message_DeviceRemoved           = OVR_MESSAGETYPE(Manager, 1),  // Existing device has been plugged/unplugged.
    // Sensor Messages
    Message_BodyFrame               = OVR_MESSAGETYPE(Sensor, 0),   // Emitted by sensor at regular intervals.
    // Latency Tester Messages
    Message_LatencyTestSamples          = OVR_MESSAGETYPE(LatencyTester, 0),
    Message_LatencyTestColorDetected    = OVR_MESSAGETYPE(LatencyTester, 1),
    Message_LatencyTestStarted          = OVR_MESSAGETYPE(LatencyTester, 2),
    Message_LatencyTestButton           = OVR_MESSAGETYPE(LatencyTester, 3),

};

//-------------------------------------------------------------------------------------
// Base class for all messages.
class Message
{
public:
    Message(MessageType type = Message_None,
            DeviceBase* pdev = 0) : Type(type), pDevice(pdev)
    { }

    MessageType Type;    // What kind of message this is.
    DeviceBase* pDevice; // Device that emitted the message.
};


// Sensor BodyFrame notification.
// Sensor uses Right-Handed coordinate system to return results, with the following
// axis definitions:
//  - Y Up positive
//  - X Right Positive
//  - Z Back Positive
// Rotations a counter-clockwise (CCW) while looking in the negative direction
// of the axis. This means they are interpreted as follows:
//  - Roll is rotation around Z, counter-clockwise (tilting left) in XY plane.
//  - Yaw is rotation around Y, positive for turning left.
//  - Pitch is rotation around X, positive for pitching up.

class MessageBodyFrame : public Message
{
public:
    MessageBodyFrame(DeviceBase* dev)
        : Message(Message_BodyFrame, dev), Temperature(0.0f), TimeDelta(0.0f)
    {
    }

    Vector3f Acceleration;   // Acceleration in m/s^2.
    Vector3f RotationRate;   // Angular velocity in rad/s^2.
    Vector3f MagneticField;  // Magnetic field strength in Gauss.
    float    Temperature;    // Temperature reading on sensor surface, in degrees Celsius.
    float    TimeDelta;      // Time passed since last Body Frame, in seconds.
};

// Sent when we receive a device status changes (e.g.:
// Message_DeviceAdded, Message_DeviceRemoved).
class MessageDeviceStatus : public Message
{
public:
	MessageDeviceStatus(MessageType type, DeviceBase* dev, const DeviceHandle &hdev)
		: Message(type, dev), Handle(hdev) { }

	DeviceHandle Handle;
};

//-------------------------------------------------------------------------------------
// ***** Latency Tester

// Sent when we receive Latency Tester samples.
class MessageLatencyTestSamples : public Message
{
public:
    MessageLatencyTestSamples(DeviceBase* dev)
        : Message(Message_LatencyTestSamples, dev)
    {
    }

    Array<Color>     Samples;
};

// Sent when a Latency Tester 'color detected' event occurs.
class MessageLatencyTestColorDetected : public Message
{
public:
    MessageLatencyTestColorDetected(DeviceBase* dev)
        : Message(Message_LatencyTestColorDetected, dev)
    {
    }

    UInt16      Elapsed;
    Color       DetectedValue;
    Color       TargetValue;
};

// Sent when a Latency Tester 'change color' event occurs.
class MessageLatencyTestStarted : public Message
{
public:
    MessageLatencyTestStarted(DeviceBase* dev)
        : Message(Message_LatencyTestStarted, dev)
    {
    }

    Color    TargetValue;
};

// Sent when a Latency Tester 'button' event occurs.
class MessageLatencyTestButton : public Message
{
public:
    MessageLatencyTestButton(DeviceBase* dev)
        : Message(Message_LatencyTestButton, dev)
    {
    }

};


} // namespace OVR

#endif