openvr
openvr copied to clipboard
How to control the status of device?(e.g. how to set device to sleep state)
Hi, I am now looking at how to set the status of controller. For example, when my device disconnect(sleep), the icon on steamvr turn gray like the HMD. I found one about HMD, but I am not sure other controller is same as HMD.
Usually openvr manages when a device should go into standby. This can be pointed out in your driver code as follows:
-
Set a string property for the vr::Prop_NamedIconPathDeviceStandby_String: vr::VRProperties()->SetStringProperty( m_ulPropertyContainer, vr::Prop_NamedIconPathDeviceStandby_String, "{your-driver-name}/icons/your_icon_status_standby.png" );
-
Created this icon "your_icon_status_standby.png" ?
-
Saved this icon to your "resources/icons" folder?
To know if your device enters standby you should implement the EnterStandby() function of the ITrackedDeviceServerDriver class.
https://github.com/ValveSoftware/openvr/blob/master/headers/openvr_driver.h#L2396
/** Handles a request from the system to put this device into standby mode. What that means is defined per-device. */
virtual void EnterStandby() = 0;
@peroht Yeah, it is the correct way to set icon, but the device status is not correct at all. For user diy controller, openvr does not know whether it is connected. From the wiki, it said the status will enter standby when
- For all devices when SteamVR exits
- For a device that the user has elected to turn off via the power menu. This option will only be shown to the user if Prop_DeviceCanPowerOff_Bool is true for that device.
- When the device has been inactive for longer than its configured timeout.
But I don't how to tell openvr that my device is disconnected.
I see your point. I believe this is possible with a VendorSpecificEvent() function and the VREvent_TrackedDeviceDeactivated. Have you tried that?
I believe a device would have to set this property for it to work: vr::ETrackedDeviceProperty::Prop_DeviceCanPowerOff_Bool
Emmm, I try this a moment ago but it does not work(my driver base on new input system). From the description of the function, it looks like the function was used to send some specific event defined by programmer.
/** Sends a vendor specific event (VREvent_VendorSpecific_Reserved_Start..VREvent_VendorSpecific_Reserved_End */
virtual void VendorSpecificEvent( uint32_t unWhichDevice, vr::EVREventType eventType, const VREvent_Data_t & eventData, double eventTimeOffset ) = 0;
Beside, I found EVRState which contain status enum but I don't how to post it to openvr system.
enum EVRState
{
VRState_Undefined = -1,
VRState_Off = 0,
VRState_Searching = 1,
VRState_Searching_Alert = 2,
VRState_Ready = 3,
VRState_Ready_Alert = 4,
VRState_NotReady = 5,
VRState_Standby = 6,
VRState_Ready_Alert_Low = 7,
};
When I try it myself with the new IVRInput system I get the error:
"VendorSpecificEvent 101 outside of reserved range"
so I guess we have to wait for Valve to implement it for the new IVRInput. I believe EVRState is only for reading the states of devices as they happen via the control of openvr.
--在RunFrame()函数内: 1.要不断调用GetPose(),即if (m_unObjectId != vr::k_unTrackedDeviceIndexInvalid) vr::VRServerDriverHost()->TrackedDevicePoseUpdated(m_unObjectId, GetPose(), sizeof(DriverPose_t));若不调用那么无法控制驱动状态且初始驱动时steamvr会一直显示驱动处于standby模式 --在GetPose()函数内: 1.设置pose.poseIsValid = false; pose.result = TrackingResult_Calibrating_OutOfRange;驱动会处于standby模式 2..设置pose.poseIsValid = true; pose.result = TrackingResult_Running_OK;驱动会处于正在定位状态 2.设置pose.deviceIsConnected=false,驱动会处于断开状态; 3.另外当pose.qRotation和pose.vecPosition长时间未更新时steamvr会将驱动设置为standby模式,退出standby模式的方法是更新pose.qRotation或pose.vecPosition的值!