diff --git a/src/property.rs b/src/property.rs new file mode 100644 index 0000000..b015424 --- /dev/null +++ b/src/property.rs @@ -0,0 +1,123 @@ +#![allow(non_upper_case_globals)] + +use openvr_sys as sys; +use super::TrackedDeviceProperty; + +pub const Invalid: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Invalid; +pub const TrackingSystemName_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_TrackingSystemName_String; +pub const ModelNumber_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ModelNumber_String; +pub const SerialNumber_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_SerialNumber_String; +pub const RenderModelName_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_RenderModelName_String; +pub const WillDriftInYaw_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_WillDriftInYaw_Bool; +pub const ManufacturerName_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ManufacturerName_String; +pub const TrackingFirmwareVersion_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_TrackingFirmwareVersion_String; +pub const HardwareRevision_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HardwareRevision_String; +pub const AllWirelessDongleDescriptions_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_AllWirelessDongleDescriptions_String; +pub const ConnectedWirelessDongle_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ConnectedWirelessDongle_String; +pub const DeviceIsWireless_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceIsWireless_Bool; +pub const DeviceIsCharging_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceIsCharging_Bool; +pub const DeviceBatteryPercentage_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceBatteryPercentage_Float; +pub const StatusDisplayTransform_Matrix34: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_StatusDisplayTransform_Matrix34; +pub const Firmware_UpdateAvailable_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Firmware_UpdateAvailable_Bool; +pub const Firmware_ManualUpdate_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Firmware_ManualUpdate_Bool; +pub const Firmware_ManualUpdateURL_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Firmware_ManualUpdateURL_String; +pub const HardwareRevision_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HardwareRevision_Uint64; +pub const FirmwareVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FirmwareVersion_Uint64; +pub const FPGAVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FPGAVersion_Uint64; +pub const VRCVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_VRCVersion_Uint64; +pub const RadioVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_RadioVersion_Uint64; +pub const DongleVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DongleVersion_Uint64; +pub const BlockServerShutdown_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_BlockServerShutdown_Bool; +pub const CanUnifyCoordinateSystemWithHmd_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CanUnifyCoordinateSystemWithHmd_Bool; +pub const ContainsProximitySensor_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ContainsProximitySensor_Bool; +pub const DeviceProvidesBatteryStatus_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceProvidesBatteryStatus_Bool; +pub const DeviceCanPowerOff_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceCanPowerOff_Bool; +pub const Firmware_ProgrammingTarget_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Firmware_ProgrammingTarget_String; +pub const DeviceClass_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DeviceClass_Int32; +pub const HasCamera_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasCamera_Bool; +pub const DriverVersion_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DriverVersion_String; +pub const Firmware_ForceUpdateRequired_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Firmware_ForceUpdateRequired_Bool; +pub const ViveSystemButtonFixRequired_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ViveSystemButtonFixRequired_Bool; +pub const ParentDriver_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ParentDriver_Uint64; +pub const ResourceRoot_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ResourceRoot_String; +pub const ReportsTimeSinceVSync_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ReportsTimeSinceVSync_Bool; +pub const SecondsFromVsyncToPhotons_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_SecondsFromVsyncToPhotons_Float; +pub const DisplayFrequency_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayFrequency_Float; +pub const UserIpdMeters_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_UserIpdMeters_Float; +pub const CurrentUniverseId_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CurrentUniverseId_Uint64; +pub const PreviousUniverseId_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_PreviousUniverseId_Uint64; +pub const DisplayFirmwareVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayFirmwareVersion_Uint64; +pub const IsOnDesktop_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_IsOnDesktop_Bool; +pub const DisplayMCType_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCType_Int32; +pub const DisplayMCOffset_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCOffset_Float; +pub const DisplayMCScale_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCScale_Float; +pub const EdidVendorID_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_EdidVendorID_Int32; +pub const DisplayMCImageLeft_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageLeft_String; +pub const DisplayMCImageRight_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageRight_String; +pub const DisplayGCBlackClamp_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCBlackClamp_Float; +pub const EdidProductID_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_EdidProductID_Int32; +pub const CameraToHeadTransform_Matrix34: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CameraToHeadTransform_Matrix34; +pub const DisplayGCType_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCType_Int32; +pub const DisplayGCOffset_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCOffset_Float; +pub const DisplayGCScale_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCScale_Float; +pub const DisplayGCPrescale_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCPrescale_Float; +pub const DisplayGCImage_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayGCImage_String; +pub const LensCenterLeftU_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_LensCenterLeftU_Float; +pub const LensCenterLeftV_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_LensCenterLeftV_Float; +pub const LensCenterRightU_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_LensCenterRightU_Float; +pub const LensCenterRightV_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_LensCenterRightV_Float; +pub const UserHeadToEyeDepthMeters_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_UserHeadToEyeDepthMeters_Float; +pub const CameraFirmwareVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CameraFirmwareVersion_Uint64; +pub const CameraFirmwareDescription_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CameraFirmwareDescription_String; +pub const DisplayFPGAVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayFPGAVersion_Uint64; +pub const DisplayBootloaderVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayBootloaderVersion_Uint64; +pub const DisplayHardwareVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayHardwareVersion_Uint64; +pub const AudioFirmwareVersion_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_AudioFirmwareVersion_Uint64; +pub const CameraCompatibilityMode_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_CameraCompatibilityMode_Int32; +pub const ScreenshotHorizontalFieldOfViewDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ScreenshotHorizontalFieldOfViewDegrees_Float; +pub const ScreenshotVerticalFieldOfViewDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ScreenshotVerticalFieldOfViewDegrees_Float; +pub const DisplaySuppressed_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplaySuppressed_Bool; +pub const DisplayAllowNightMode_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayAllowNightMode_Bool; +pub const DisplayMCImageWidth_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageWidth_Int32; +pub const DisplayMCImageHeight_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageHeight_Int32; +pub const DisplayMCImageNumChannels_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageNumChannels_Int32; +pub const DisplayMCImageData_Binary: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayMCImageData_Binary; +pub const SecondsFromPhotonsToVblank_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_SecondsFromPhotonsToVblank_Float; +pub const DriverDirectModeSendsVsyncEvents_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DriverDirectModeSendsVsyncEvents_Bool; +pub const DisplayDebugMode_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayDebugMode_Bool; +pub const GraphicsAdapterLuid_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_GraphicsAdapterLuid_Uint64; +pub const AttachedDeviceId_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_AttachedDeviceId_String; +pub const SupportedButtons_Uint64: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_SupportedButtons_Uint64; +pub const Axis0Type_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Axis0Type_Int32; +pub const Axis1Type_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Axis1Type_Int32; +pub const Axis2Type_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Axis2Type_Int32; +pub const Axis3Type_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Axis3Type_Int32; +pub const Axis4Type_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_Axis4Type_Int32; +pub const ControllerRoleHint_Int32: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ControllerRoleHint_Int32; +pub const FieldOfViewLeftDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FieldOfViewLeftDegrees_Float; +pub const FieldOfViewRightDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FieldOfViewRightDegrees_Float; +pub const FieldOfViewTopDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FieldOfViewTopDegrees_Float; +pub const FieldOfViewBottomDegrees_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_FieldOfViewBottomDegrees_Float; +pub const TrackingRangeMinimumMeters_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_TrackingRangeMinimumMeters_Float; +pub const TrackingRangeMaximumMeters_Float: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_TrackingRangeMaximumMeters_Float; +pub const ModeLabel_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_ModeLabel_String; +pub const IconPathName_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_IconPathName_String; +pub const NamedIconPathDeviceOff_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceOff_String; +pub const NamedIconPathDeviceSearching_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceSearching_String; +pub const NamedIconPathDeviceSearchingAlert_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceSearchingAlert_String; +pub const NamedIconPathDeviceReady_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceReady_String; +pub const NamedIconPathDeviceReadyAlert_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceReadyAlert_String; +pub const NamedIconPathDeviceNotReady_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceNotReady_String; +pub const NamedIconPathDeviceStandby_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceStandby_String; +pub const NamedIconPathDeviceAlertLow_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_NamedIconPathDeviceAlertLow_String; +pub const DisplayHiddenArea_Binary_Start: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayHiddenArea_Binary_Start; +pub const DisplayHiddenArea_Binary_End: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_DisplayHiddenArea_Binary_End; +pub const UserConfigPath_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_UserConfigPath_String; +pub const InstallPath_String: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_InstallPath_String; +pub const HasDisplayComponent_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasDisplayComponent_Bool; +pub const HasControllerComponent_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasControllerComponent_Bool; +pub const HasCameraComponent_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasCameraComponent_Bool; +pub const HasDriverDirectModeComponent_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasDriverDirectModeComponent_Bool; +pub const HasVirtualDisplayComponent_Bool: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_HasVirtualDisplayComponent_Bool; +pub const VendorSpecific_Reserved_Start: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_VendorSpecific_Reserved_Start; +pub const VendorSpecific_Reserved_End: TrackedDeviceProperty = sys::ETrackedDeviceProperty_ETrackedDeviceProperty_Prop_VendorSpecific_Reserved_End; diff --git a/src/system/mod.rs b/src/system/mod.rs index fe93b27..e528bb4 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -1,7 +1,8 @@ //! The `System` interface provides access to display configuration information, tracking data, controller state, //! events, and device properties. It is the main interface of OpenVR. -use std::mem; +use std::{mem, ptr}; +use std::ffi::CString; use openvr_sys as sys; @@ -160,6 +161,59 @@ impl<'a> System<'a> { if device == 0 { None } else { Some(device as usize as *mut _) } } } + + pub fn bool_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result { + unsafe { + let mut error: TrackedPropertyError = mem::uninitialized(); + let r = self.0.GetBoolTrackedDeviceProperty.unwrap()(device, property, &mut error.0); + if error == tracked_property_error::SUCCESS { Ok(r) } else { Err(error) } + } + } + + pub fn float_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result { + unsafe { + let mut error: TrackedPropertyError = mem::uninitialized(); + let r = self.0.GetFloatTrackedDeviceProperty.unwrap()(device, property, &mut error.0); + if error == tracked_property_error::SUCCESS { Ok(r) } else { Err(error) } + } + } + + pub fn int32_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result { + unsafe { + let mut error: TrackedPropertyError = mem::uninitialized(); + let r = self.0.GetInt32TrackedDeviceProperty.unwrap()(device, property, &mut error.0); + if error == tracked_property_error::SUCCESS { Ok(r) } else { Err(error) } + } + } + + pub fn uint64_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result { + unsafe { + let mut error: TrackedPropertyError = mem::uninitialized(); + let r = self.0.GetUint64TrackedDeviceProperty.unwrap()(device, property, &mut error.0); + if error == tracked_property_error::SUCCESS { Ok(r) } else { Err(error) } + } + } + + pub fn matrix34_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result<[[f32; 4]; 3], TrackedPropertyError> { + unsafe { + let mut error: TrackedPropertyError = mem::uninitialized(); + let r = self.0.GetMatrix34TrackedDeviceProperty.unwrap()(device, property, &mut error.0); + if error == tracked_property_error::SUCCESS { Ok(r.m) } else { Err(error) } + } + } + + pub fn string_tracked_device_property(&self, device: TrackedDeviceIndex, property: TrackedDeviceProperty) -> Result { + unsafe { + let mut error = mem::uninitialized(); + let n = self.0.GetStringTrackedDeviceProperty.unwrap()(device, property, ptr::null_mut(), 0, &mut error); + if n == 0 { return Err(TrackedPropertyError(error)); } + let mut storage = Vec::new(); + storage.reserve_exact(n as usize); + storage.resize(n as usize, mem::uninitialized()); + self.0.GetStringTrackedDeviceProperty.unwrap()(device, property, storage.as_mut_ptr() as *mut i8, n, ptr::null_mut()); + Ok(CString::from_vec_unchecked(storage)) + } + } } /// Values represent the tangents of the half-angles from the center view axis @@ -181,3 +235,56 @@ pub struct DistortionCoordinates { pub green: [f32; 2], pub blue: [f32; 2], } + +#[derive(Copy, Clone, Eq, PartialEq)] +pub struct TrackedPropertyError(sys::TrackedPropertyError); + +pub mod tracked_property_error { + use super::{sys, TrackedPropertyError}; + + pub const SUCCESS: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_Success); + pub const WRONG_DATA_TYPE: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_WrongDataType); + pub const WRONG_DEVICE_CLASS: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_WrongDeviceClass); + pub const BUFFER_TOO_SMALL: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_BufferTooSmall); + pub const UNKNOWN_PROPERTY: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_UnknownProperty); + pub const INVALID_DEVICE: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_InvalidDevice); + pub const COULD_NOT_CONTACT_SERVER: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_CouldNotContactServer); + pub const VALUE_NOT_PROVIDED_BY_DEVICE: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_ValueNotProvidedByDevice); + pub const STRING_EXCEEDS_MAXIMUM_LENGTH: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_StringExceedsMaximumLength); + pub const NOT_YET_AVAILABLE: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_NotYetAvailable); + pub const PERMISSION_DENIED: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_PermissionDenied); + pub const INVALID_OPERATION: TrackedPropertyError = TrackedPropertyError(sys::ETrackedPropertyError_ETrackedPropertyError_TrackedProp_InvalidOperation); +} + +impl fmt::Debug for TrackedPropertyError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad(::std::error::Error::description(self)) + } +} + +impl ::std::error::Error for TrackedPropertyError { + fn description(&self) -> &str { + use self::tracked_property_error::*; + match *self { + SUCCESS => "SUCCESS", + WRONG_DATA_TYPE => "WRONG_DATA_TYPE", + WRONG_DEVICE_CLASS => "WRONG_DEVICE_CLASS", + BUFFER_TOO_SMALL => "BUFFER_TOO_SMALL", + UNKNOWN_PROPERTY => "UNKNOWN_PROPERTY", + INVALID_DEVICE => "INVALID_DEVICE", + COULD_NOT_CONTACT_SERVER => "COULD_NOT_CONTACT_SERVER", + VALUE_NOT_PROVIDED_BY_DEVICE => "VALUE_NOT_PROVIDED_BY_DEVICE", + STRING_EXCEEDS_MAXIMUM_LENGTH => "STRING_EXCEEDS_MAXIMUM_LENGTH", + NOT_YET_AVAILABLE => "NOT_YET_AVAILABLE", + PERMISSION_DENIED => "PERMISSION_DENIED", + INVALID_OPERATION => "INVALID_OPERATION", + _ => "UNKNOWN", + } + } +} + +impl fmt::Display for TrackedPropertyError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad(::std::error::Error::description(self)) + } +}