added enum wrappers for all used enums

This commit is contained in:
Rene Eichhorn
2016-05-07 16:58:35 +02:00
parent ad3219bb46
commit f36376b137
4 changed files with 105 additions and 11 deletions

View File

@ -4,6 +4,93 @@ use openvr_sys::Enum_ETrackedPropertyError::*;
use subsystems::*;
use error::*;
/// Describes a string property of a tracked device
#[derive(Debug, Copy, Clone)]
pub enum TrackedDeviceStringProperty {
TrackingSystemName,
ModelNumber,
SerialNumber,
RenderModelName,
ManufacturerName,
TrackingFirmwareVersion,
HardwareRevision,
AllWirelessDongleDescriptions,
ConnectedWirelessDongle,
FirmwareManualUpdateURL,
FirmwareProgrammingTarget,
DisplayMCImageLeft,
DisplayMCImageRight,
DisplayGCImage,
CameraFirmwareDescription,
AttachedDeviceId,
ModeLabel
}
impl TrackedDeviceStringProperty {
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceProperty {
use openvr_sys::Enum_ETrackedDeviceProperty::*;
use self::TrackedDeviceStringProperty::*;
match *self {
TrackingSystemName => ETrackedDeviceProperty_Prop_TrackingSystemName_String,
ModelNumber => ETrackedDeviceProperty_Prop_ModelNumber_String,
SerialNumber => ETrackedDeviceProperty_Prop_SerialNumber_String,
RenderModelName => ETrackedDeviceProperty_Prop_RenderModelName_String,
ManufacturerName => ETrackedDeviceProperty_Prop_ManufacturerName_String,
TrackingFirmwareVersion => ETrackedDeviceProperty_Prop_TrackingFirmwareVersion_String,
HardwareRevision => ETrackedDeviceProperty_Prop_HardwareRevision_String,
AllWirelessDongleDescriptions => ETrackedDeviceProperty_Prop_AllWirelessDongleDescriptions_String,
ConnectedWirelessDongle => ETrackedDeviceProperty_Prop_ConnectedWirelessDongle_String,
FirmwareManualUpdateURL => ETrackedDeviceProperty_Prop_Firmware_ManualUpdateURL_String,
FirmwareProgrammingTarget => ETrackedDeviceProperty_Prop_Firmware_ProgrammingTarget_String,
DisplayMCImageLeft => ETrackedDeviceProperty_Prop_DisplayMCImageLeft_String,
DisplayMCImageRight => ETrackedDeviceProperty_Prop_DisplayMCImageRight_String,
DisplayGCImage => ETrackedDeviceProperty_Prop_DisplayGCImage_String,
CameraFirmwareDescription => ETrackedDeviceProperty_Prop_CameraFirmwareDescription_String,
AttachedDeviceId => ETrackedDeviceProperty_Prop_AttachedDeviceId_String,
ModeLabel => ETrackedDeviceProperty_Prop_ModeLabel_String
}
}
}
/// Describes the class of a tracked device
#[derive(Debug, Copy, Clone)]
pub enum TrackedDeviceClass {
Invalid,
HMD,
Controller,
TrackingReference,
Other,
}
impl TrackedDeviceClass {
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceClass {
use self::TrackedDeviceClass::*;
use openvr_sys::Enum_ETrackedDeviceClass::*;
match *self {
Invalid => ETrackedDeviceClass_TrackedDeviceClass_Invalid,
HMD => ETrackedDeviceClass_TrackedDeviceClass_HMD,
Controller => ETrackedDeviceClass_TrackedDeviceClass_Controller,
TrackingReference => ETrackedDeviceClass_TrackedDeviceClass_TrackingReference,
Other => ETrackedDeviceClass_TrackedDeviceClass_Other,
}
}
pub fn from_raw(raw: openvr_sys::Enum_ETrackedDeviceClass) -> Self {
use self::TrackedDeviceClass::*;
use openvr_sys::Enum_ETrackedDeviceClass::*;
match raw {
ETrackedDeviceClass_TrackedDeviceClass_Invalid => Invalid,
ETrackedDeviceClass_TrackedDeviceClass_HMD => HMD,
ETrackedDeviceClass_TrackedDeviceClass_Controller => Controller,
ETrackedDeviceClass_TrackedDeviceClass_TrackingReference => TrackingReference,
ETrackedDeviceClass_TrackedDeviceClass_Other => Other,
}
}
}
#[derive(Debug, Copy, Clone)]
pub struct TrackedDevicePose {
pub index: usize,
@ -16,15 +103,15 @@ pub struct TrackedDevicePose {
impl TrackedDevicePose {
// returns the device class of the tracked object
pub fn device_class(&self) -> openvr_sys::Enum_ETrackedDeviceClass {
pub fn device_class(&self) -> TrackedDeviceClass {
unsafe {
let system = * { system().unwrap().0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable};
system.GetTrackedDeviceClass.unwrap()(self.index as u32)
TrackedDeviceClass::from_raw(system.GetTrackedDeviceClass.unwrap()(self.index as u32))
}
}
/// gets a propery as a string
pub fn get_property_string(&self, property: openvr_sys::Enum_ETrackedDeviceProperty) -> Result<String, Error<openvr_sys::Enum_ETrackedPropertyError>> {
pub fn get_property_string(&self, property: TrackedDeviceStringProperty) -> Result<String, Error<openvr_sys::Enum_ETrackedPropertyError>> {
unsafe {
let system = * { system().unwrap().0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable};
@ -33,7 +120,7 @@ impl TrackedDevicePose {
let size = system.GetStringTrackedDeviceProperty.unwrap()(
self.index as u32,
property,
property.to_raw(),
val_out.as_ptr() as *mut i8,
256,
&mut err