-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM1OrientationTypes.h
149 lines (123 loc) · 4.42 KB
/
M1OrientationTypes.h
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
#pragma once
#include "m1_mathematics/Orientation.h"
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <variant>
struct M1OrientationTrackingResult {
Mach1::Orientation currentOrientation;
bool success;
};
enum M1OrientationDeviceType {
M1OrientationManagerDeviceTypeEmulator = -1,
M1OrientationManagerDeviceTypeNone = 0,
M1OrientationManagerDeviceTypeSerial,
M1OrientationManagerDeviceTypeBLE,
M1OrientationManagerDeviceTypeOSC,
M1OrientationManagerDeviceTypeCamera,
M1OrientationManagerDeviceTypeFusion, // TODO: Add Camera + [any] type
};
extern std::map<enum M1OrientationDeviceType, std::string> M1OrientationDeviceTypeName;
enum M1OrientationStatusType {
M1OrientationManagerStatusTypeError = -2,
M1OrientationManagerStatusTypeNotConnectable,
M1OrientationManagerStatusTypeConnectable,
M1OrientationManagerStatusTypeConnected,
};
extern std::map<enum M1OrientationStatusType, std::string> M1OrientationStatusTypeName;
struct M1OrientationDeviceInfo {
public:
// Constructor
M1OrientationDeviceInfo() {}
M1OrientationDeviceInfo(std::string name_, M1OrientationDeviceType type_, std::string address_, std::variant<bool, int> signalStrength_ = false, std::variant<bool, int> batteryPercentage_ = false) {
name = name_;
type = type_;
address = address_;
signalStrength = signalStrength_;
batteryPercentage = batteryPercentage_;
}
struct Hash {
std::size_t operator()(const M1OrientationDeviceInfo& k) const
{
// Joshua Bloch, Effective Java, Addison-Wesley Professional (2018), p. 53
std::size_t result = k.getDeviceNameHash();
result = 31 * result + k.getDeviceAddressHash();
return result;
}
};
std::string getDeviceName() {
return name;
}
std::size_t getDeviceNameHash() const {
return std::hash<std::string>()( name );
}
bool isDeviceName(const std::string& query_name) const {
return name.find(query_name) != std::string::npos;
}
M1OrientationDeviceType getDeviceType() {
return type;
}
std::string getDeviceAddress() {
// [Serial]: returns the path
// [BLE]: returns the UUID
return address;
}
std::size_t getDeviceAddressHash() const {
return std::hash<std::string>()( address);
}
bool isDeviceAddress(const std::string& query_address) const {
return address.find(query_address) != std::string::npos;
}
// Keeping these getters for ease of documentation but these variables are now public
std::variant<bool, int> getDeviceSignalStrength() {
return signalStrength;
/* Reference:
if (std::holds_alternative<bool>(signalStrength)) {
// it's false, which means the signal strength is unknown
} else {
// it has a signal strength value
}
*/
}
// Keeping these getters for ease of documentation but these variables are now public
std::variant<bool, int> getDeviceBatteryPercentage() {
return batteryPercentage;
/* Reference:
if (std::holds_alternative<bool>(batteryPercentage)) {
// it's false, which means the battery percentage is unknown
} else {
// it has a battery percentage value
}
*/
}
// Custom search function for string name of device
struct find_id {
std::string name;
find_id(std::string name):name(name) { }
bool operator()(M1OrientationDeviceInfo const& m) const {
return m.name == name;
}
};
bool operator==(const M1OrientationDeviceInfo& rhs) const {
return ((name == rhs.name) && (address == rhs.address));
}
bool operator!=(const M1OrientationDeviceInfo& rhs) const {
return ((name != rhs.name) || (address != rhs.address));
}
public:
bool notConnectable = false;
bool newErrorToParse = false;
std::string error = "";
// osc specific
int osc_port = 9901;
std::string osc_msg_addr_pttrn = "/orientation";
private:
std::string name = "";
M1OrientationDeviceType type = M1OrientationDeviceType::M1OrientationManagerDeviceTypeNone;
std::string address = ""; // Device path or UUID
public:
std::variant<bool, int> signalStrength = false;
std::variant<bool, int> batteryPercentage = false;
};