Tanoda
Device.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap {
10 using System;
11 using LeapInternal;
12
28 public class Device :
29 IEquatable<Device> {
30
39 public Device() { }
40
41 public Device(IntPtr deviceHandle,
42 IntPtr internalHandle,
43 float horizontalViewAngle,
44 float verticalViewAngle,
45 float range,
46 float baseline,
47 DeviceType type,
48 uint status,
49 string serialNumber) {
50 Handle = deviceHandle;
51 InternalHandle = internalHandle;
52 HorizontalViewAngle = horizontalViewAngle;
53 VerticalViewAngle = verticalViewAngle;
54 Range = range;
55 Baseline = baseline;
56 Type = type;
57 SerialNumber = serialNumber;
58 UpdateStatus((eLeapDeviceStatus)status);
59 }
60
64 public void Update(
65 float horizontalViewAngle,
66 float verticalViewAngle,
67 float range,
68 float baseline,
69 uint status,
70 string serialNumber) {
71 HorizontalViewAngle = horizontalViewAngle;
72 VerticalViewAngle = verticalViewAngle;
73 Range = range;
74 Baseline = baseline;
75 SerialNumber = serialNumber;
76 UpdateStatus((eLeapDeviceStatus)status);
77 }
78
82 public void Update(Device updatedDevice) {
85 Range = updatedDevice.Range;
86 Baseline = updatedDevice.Baseline;
87 IsStreaming = updatedDevice.IsStreaming;
88 SerialNumber = updatedDevice.SerialNumber;
89 }
90
94 internal void UpdateStatus(eLeapDeviceStatus status)
95 {
96 if ((status & eLeapDeviceStatus.eLeapDeviceStatus_Streaming) == eLeapDeviceStatus.eLeapDeviceStatus_Streaming)
97 IsStreaming = true;
98 else
99 IsStreaming = false;
100 if ((status & eLeapDeviceStatus.eLeapDeviceStatus_Smudged) == eLeapDeviceStatus.eLeapDeviceStatus_Smudged)
101 IsSmudged = true;
102 else
103 IsSmudged = false;
104 if ((status & eLeapDeviceStatus.eLeapDeviceStatus_Robust) == eLeapDeviceStatus.eLeapDeviceStatus_Robust)
105 IsLightingBad = true;
106 else
107 IsLightingBad = false;
108 if ((status & eLeapDeviceStatus.eLeapDeviceStatus_LowResource) == eLeapDeviceStatus.eLeapDeviceStatus_LowResource)
109 IsLowResource = true;
110 else
111 IsLowResource = false;
112 }
113
117 public IntPtr Handle { get; private set; }
118
119 private IntPtr InternalHandle;
120
121 public bool SetPaused(bool pause) {
122 eLeapRS result = LeapC.LeapSetPause(Handle, pause);
123 return result == eLeapRS.eLeapRS_Success;
124 }
125
134 public bool Equals(Device other) {
135 return SerialNumber == other.SerialNumber;
136 }
137
142 public override string ToString() {
143 return "Device serial# " + this.SerialNumber;
144 }
145
155 public float HorizontalViewAngle { get; private set; }
156
166 public float VerticalViewAngle { get; private set; }
167
178 public float Range { get; private set; }
179
188 public float Baseline { get; private set; }
189
196 public bool IsStreaming { get; internal set; }
197
208 public DeviceType Type { get; private set; }
209
219 public string SerialNumber { get; private set; }
220
224 protected uint GetDeviceStatus()
225 {
226 eLeapRS result;
227
228 LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO();
229 deviceInfo.serial = IntPtr.Zero;
230 deviceInfo.size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(deviceInfo);
231 result = LeapC.GetDeviceInfo(InternalHandle, ref deviceInfo);
232
233 if (result != eLeapRS.eLeapRS_Success)
234 return 0;
235 uint status = deviceInfo.status;
236 System.Runtime.InteropServices.Marshal.FreeCoTaskMem(deviceInfo.serial);
237 return status;
238 }
239
240
246 public bool IsSmudged { get; internal set; }
247
252 public bool IsLowResource { get; internal set; }
253
260 public bool IsLightingBad { get; internal set; }
261
265 public enum DeviceType {
266 TYPE_INVALID = -1,
267
272 TYPE_PERIPHERAL = (int)eLeapDeviceType.eLeapDeviceType_Peripheral,
273
277 TYPE_DRAGONFLY = (int)eLeapDeviceType.eLeapDeviceType_Dragonfly,
278
282 TYPE_NIGHTCRAWLER = (int)eLeapDeviceType.eLeapDeviceType_Nightcrawler,
283
287 TYPE_RIGEL = (int)eLeapDeviceType.eLeapDevicePID_Rigel,
288
289 [Obsolete]
290 TYPE_LAPTOP,
291 [Obsolete]
292 TYPE_KEYBOARD
293 }
294 }
295}
The Device class represents a physically connected device.
Definition: Device.cs:29
Device()
Constructs a default Device object.
Definition: Device.cs:39
bool Equals(Device other)
Compare Device object equality.
Definition: Device.cs:134
string SerialNumber
An alphanumeric serial number unique to each device.
Definition: Device.cs:219
bool IsLightingBad
The software has detected excessive IR illumination, which may interfere with tracking....
Definition: Device.cs:260
bool IsSmudged
The software has detected a possible smudge on the translucent cover over the Leap Motion cameras.
Definition: Device.cs:246
Device(IntPtr deviceHandle, IntPtr internalHandle, float horizontalViewAngle, float verticalViewAngle, float range, float baseline, DeviceType type, uint status, string serialNumber)
Definition: Device.cs:41
float Range
The maximum reliable tracking range from the center of this device.
Definition: Device.cs:178
override string ToString()
A string containing a brief, human readable description of the Device object.
Definition: Device.cs:142
void Update(Device updatedDevice)
For internal use only.
Definition: Device.cs:82
void Update(float horizontalViewAngle, float verticalViewAngle, float range, float baseline, uint status, string serialNumber)
For internal use only.
Definition: Device.cs:64
float Baseline
The distance in mm between the center points of the stereo sensors.
Definition: Device.cs:188
float VerticalViewAngle
The angle in radians of view along the z axis of this device.
Definition: Device.cs:166
DeviceType Type
The device type.
Definition: Device.cs:208
bool SetPaused(bool pause)
Definition: Device.cs:121
uint GetDeviceStatus()
Returns the internal status field of the current device
Definition: Device.cs:224
IntPtr Handle
For internal use only.
Definition: Device.cs:117
DeviceType
The available types of Leap Motion controllers.
Definition: Device.cs:265
bool IsLowResource
The software has entered low-resource mode
Definition: Device.cs:252
bool IsStreaming
Reports whether this device is streaming data to your application.
Definition: Device.cs:196
float HorizontalViewAngle
The angle in radians of view along the x axis of this device.
Definition: Device.cs:155
static eLeapRS GetDeviceInfo(IntPtr hDevice, ref LEAP_DEVICE_INFO info)
static eLeapRS LeapSetPause(IntPtr hConnection, bool pause)
eLeapDeviceStatus
Definition: LeapC.cs:108
eLeapDeviceType
Definition: LeapC.cs:40