Ejemplo n.º 1
0
        private async Task NamedPipeReader()
        {
            var pipeServer = new NamedPipeServerStream("GHRPipe", PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);
            await pipeServer.WaitForConnectionAsync().ConfigureAwait(false);

            while (true)
            {
                // Just make a stupid huge buffer, cause we get some crazy backtraces sometimes.
                var buffer = new byte[131072];
                var msg    = string.Empty;
                var len    = -1;
                while (len < 0 || (len == buffer.Length && buffer[131071] != '\0'))
                {
                    try
                    {
                        len = await pipeServer.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);

                        // TODO Actually check that we don't have more left waiting to be read.
                        if (len > 0)
                        {
                            var gvrMsg = GHRProtocolMessageContainer.Deserialize(new MemoryStream(buffer, 0, len));
                            MessageReceivedHandler?.Invoke(this, gvrMsg);
                        }
                    }
                    catch
                    {
                        // no-op?
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected async void OnGVRMessageReceived(object aObj, GHRProtocolMessageContainer aMsg)
        {
            // For now, treat Vive and Oculus clips the same. Assume that if we
            // get anything at all, we should be vibrating, and if our timer
            // runs out, we should stop. There's no real need to parse the
            // buffers yet, as there's no way our older motors can spin up/down
            // at the speed of HD rumble. Once we get Nintendo Joycon support,
            // this may change.
            if (aMsg.UnityXRViveHaptics != null || aMsg.UnityXROculusClipHaptics != null || aMsg.UnityXROculusInputHaptics != null)
            {
                var isEnabled = vrTimer.Enabled;
                vrTimer.Stop();
                vrTimer.Start();
                if (!isEnabled)
                {
                    await Dispatcher.Invoke(async() => { await _intifaceTab.Vibrate(Math.Min(Math.Max(_multiplier, _baseline), 1.0)); });
                }
            }
            else if (aMsg.XInputHaptics != null)
            {
                _lastXInput = aMsg.XInputHaptics;
                xinputTimer.Start();
                _needXInputRecalc = true;
            }
            else if (aMsg.Log != null)
            {
                _log.Info(aMsg.Log.Message);
                Debug.WriteLine(aMsg.Log.Message);
            }

            /*
             * switch (aMsg)
             * {
             *  case Log l:
             *      _logTab.AddLogMessage(l.Message);
             *      break;
             *  case Ping p:
             *      break;
             *  case XInputHaptics x:
             *      break;
             *  case UnityXRViveHaptics x:
             *      break;
             *  case UnityXROculusClipHaptics x:
             *      break;
             *  case UnityXROculusInputHaptics x:
             *      break;
             * }
             */
        }
 private void OnMessageReceived(object aObj, GHRProtocolMessageContainer aMsg)
 {
     MessageReceivedHandler?.Invoke(this, aMsg);
 }