Skip to content

Listening to haptic feedback

Łukasz Balukin edited this page Mar 12, 2018 · 3 revisions

Table of Contents

Quick facts

  • Works as PUB ZMQ socket publishing at port assigned by control service while VRidge is running.
  • Uses binary-serialized messages

Connecting

  • See Control channel page to find out how to connect to this endpoint.
  • Use Broadcast as endpoint name.
  • Use PUB socket instead of REQ.

Receiving haptic pulses

You need to subscribe to haptic topic.

// Setup
socket = new SubscriberSocket(endpointAddr);
socket.Subscribe("haptic");
// Listening loop
var topic = socket.ReceiveFrameString();
var msg = socket.ReceiveFrameBytes();

if (topic == "haptic")
{
    var hapticPulse =
        Helpers.SerializationHelpers.ProtoDeserialize<HapticPulse>(msg);

    YourHardwareAPI.SendPulse(hapticPulse.LengthUs)
}

See BroadcastProxy.cs for full example.

Packet layout

Haptic pulse

[ProtoContract]
public struct HapticPulse
{
    /// <summary>
    /// Identifier defined by controller when it sends its requests to OpenVR.
    /// </summary>
    [ProtoMember(1)]
    public int ControllerId;


    /// <summary>
    /// Duration of pulse in microseconds, provided by VR game.
    /// </summary>
    [ProtoMember(2)]
    public uint LengthUs;

    /// <summary>
    /// High resolution (1us) timestamp in microseconds - based on QueryPerformanceCounter().
    /// Can be optionally used to smooth out or join pulses together.
    /// 
    /// <remarks>
    /// Timestamp is created when the pulse was submitted to HMD driver.
    /// Wrap-arounds will happen so use it for interval measurement, not absolute timings. 
    /// </remarks>
    /// </summary>
    [ProtoMember(3)]
    public uint TimestampUs;
}

You can find this file here.