Beispiel #1
0
        private void ControlRead(object sender, EndpointDataEventArgs e)
        {
            var report = PSVRReport.Parse(e.Buffer);

            Debug.WriteLine("Report: " + report.ReportType);
            switch (report.ReportType)
            {
            case PSVRReportType.Info:
                //result for
                break;

            case PSVRReportType.Status:
                //hmd status
                break;

            case PSVRReportType.Result:
                //result for command
                var type = (PSVRReportType)report.Data[4];
                Debug.WriteLine("Got response to request: {0}", type);
                Action action;
                PostActions.TryGetValue(type, out action);
                if (action != null)
                {
                    PostActions.Remove(type);
                    ThreadPool.QueueUserWorkItem((a) => { ((Action)a).Invoke(); }, action);
                }
                break;
            }
        }
Beispiel #2
0
        public static PSVRReport Parse(byte[] data)
        {
            var report = new PSVRReport();

            report.ReportType = (PSVRReportType)data[0];
            Array.Copy(data, 0, report.Data, 0, data.Length);
            return(report);
        }
Beispiel #3
0
        public void PowerOffHeadset()
        {
            if (_controlWrite == null)
            {
                return;
            }
            var report = new PSVRReport(PSVRReportType.Power, BitConverter.GetBytes(0x00000001));
            int len;

            _controlWrite.Write(report.Data, 1000, out len);
        }
Beispiel #4
0
        public void SetVRMode(bool en, Action postAction = null)
        {
            if (!IsActive)
            {
                return;
            }
            var report = new PSVRReport(PSVRReportType.Mode, BitConverter.GetBytes(en ? 0x00000001 : 0x00000000));

            if (postAction != null)
            {
                PostActions[report.ReportType] = postAction;
            }
            int len;

            _controlWrite.Write(report.Data, 1000, out len);
        }
Beispiel #5
0
        public void EnableTracking(bool en, Action postAction = null)
        {
            if (!IsActive)
            {
                return;
            }
            var report = new PSVRReport(PSVRReportType.Tracking, new byte[] { (byte)(en ? 0x80 : 0x00), 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00 });

            if (postAction != null)
            {
                PostActions[report.ReportType] = postAction;
            }
            int len;

            _controlWrite.Write(report.Data, 1000, out len);
        }
Beispiel #6
0
        public void LedControl(bool en, Action postAction = null)
        {
            if (!IsActive)
            {
                return;
            }
            byte val    = (byte)(en ? 0x64 : 0x00);
            var  report = new PSVRReport(PSVRReportType.Led, new byte[] { (ushort)PSVRLed.All & 0xFF, ((ushort)PSVRLed.All >> 8) & 0xFF, val, val, val, val, val, val, val, val, val, 0, 0, 0, 0, 0 });

            if (postAction != null)
            {
                PostActions[report.ReportType] = postAction;
            }
            int len;

            _controlWrite.Write(report.Data, 1000, out len);
        }