예제 #1
0
        void Update()
        {
            iReport.bDevice = (byte)deviceId;

            var stick = stickAxis.WithDeadzone(joystickDeadzoneDegrees);

            iReport.AxisY    = ConvertStickAxisDegreesToAxisInt(stick.Pitch, HID_USAGES.HID_USAGE_Y);
            iReport.AxisX    = ConvertStickAxisDegreesToAxisInt(stick.Roll, HID_USAGES.HID_USAGE_X);
            iReport.AxisZRot = ConvertStickAxisDegreesToAxisInt(stick.Yaw, HID_USAGES.HID_USAGE_RZ);

            var dThrusters = thrusterAxis.WithDeadzone(directionalThrustersDeadzone);

            iReport.AxisXRot = ConvertAxisRatioToAxisInt(dThrusters.Value.x, HID_USAGES.HID_USAGE_RX);
            iReport.AxisYRot = ConvertAxisRatioToAxisInt(dThrusters.Value.y, HID_USAGES.HID_USAGE_RY);
            iReport.Slider   = ConvertAxisRatioToAxisInt(dThrusters.Value.z, HID_USAGES.HID_USAGE_SL0);

            var throttleWithDeadZone = Mathf.Abs(throttle) < (throttleDeadzonePercentage / 100f) ? 0f : throttle;

            iReport.AxisZ = ConvertAxisRatioToAxisInt(throttleWithDeadZone, HID_USAGES.HID_USAGE_Z);

            iReport.Buttons = buttons;

            iReport.bHats = (uint)((byte)hat[3] << 12)
                            | (uint)((byte)hat[2] << 8)
                            | (uint)((byte)hat[1] << 4)
                            | (uint)hat[0];

            if (!vjoy.UpdateVJD(deviceId, ref iReport))
            {
                SetStatus(VJoyStatus.DeviceError);
                enabled = false;
            }
        }
예제 #2
0
        void Update()
        {
            iReport.bDevice = (byte)deviceId;

            if (MapAxisEnabled)
            {
                // Translation
                iReport.AxisXRot = ConvertAxisRatioToAxisInt(mapTranslationAxis.x, HID_USAGES.HID_USAGE_RX);
                iReport.AxisYRot = ConvertAxisRatioToAxisInt(mapTranslationAxis.y, HID_USAGES.HID_USAGE_RY);
                iReport.Slider   = ConvertAxisRatioToAxisInt(mapTranslationAxis.z, HID_USAGES.HID_USAGE_SL0);

                // Pitch / Yaw
                iReport.AxisY    = ConvertAxisRatioToAxisInt(-mapPitchAxis, HID_USAGES.HID_USAGE_Y);
                iReport.AxisZRot = ConvertAxisRatioToAxisInt(mapYawAxis, HID_USAGES.HID_USAGE_RZ);

                // Zoom
                iReport.Dial = ConvertAxisRatioToAxisInt(mapZoomAxis, HID_USAGES.HID_USAGE_SL1);

                // Make sure all the joystick axis are reset
                iReport.AxisX = ConvertStickAxisDegreesToAxisInt(0, HID_USAGES.HID_USAGE_X);
                iReport.AxisZ = ConvertAxisRatioToAxisInt(0, HID_USAGES.HID_USAGE_Z);
            }
            else
            {
                var stick = stickAxis.WithDeadzone(joystickDeadzoneDegrees);

                iReport.AxisY    = ConvertStickAxisDegreesToAxisInt(-stick.Pitch, HID_USAGES.HID_USAGE_Y);
                iReport.AxisX    = ConvertStickAxisDegreesToAxisInt(stick.Roll, HID_USAGES.HID_USAGE_X);
                iReport.AxisZRot = ConvertStickAxisDegreesToAxisInt(stick.Yaw, HID_USAGES.HID_USAGE_RZ);

                var dThrusters = thrusterAxis.WithDeadzone(directionalThrustersDeadzonePercentage / 100f);

                iReport.AxisXRot = ConvertAxisRatioToAxisInt(dThrusters.Value.x, HID_USAGES.HID_USAGE_RX);
                iReport.AxisYRot = ConvertAxisRatioToAxisInt(dThrusters.Value.y, HID_USAGES.HID_USAGE_RY);
                iReport.Slider   = ConvertAxisRatioToAxisInt(dThrusters.Value.z, HID_USAGES.HID_USAGE_SL0);

                var throttleWithDeadZone = Mathf.Abs(throttle) < (throttleDeadzonePercentage / 100f) ? 0f : throttle;
                iReport.AxisZ = ConvertAxisRatioToAxisInt(throttleWithDeadZone, HID_USAGES.HID_USAGE_Z);
            }

            iReport.Buttons = buttons;

            iReport.bHats = (uint)((byte)hat[3] << 12)
                            | (uint)((byte)hat[2] << 8)
                            | (uint)((byte)hat[1] << 4)
                            | (uint)hat[0];

            if (!vjoy.UpdateVJD(deviceId, ref iReport))
            {
                SetStatus(VJoyStatus.DeviceError);
                enabled = false;
            }
        }
예제 #3
0
        void Update()
        {
            iReport.bDevice  = (byte)deviceId;
            iReport2.bDevice = (byte)secondaryDeviceId;

            // Device 1, joystick/throttle
            if (!MapAxisEnabled)
            {
                var stick = stickAxis.WithDeadzone(joystickDeadzoneDegrees);

                iReport.AxisY    = ConvertStickAxisDegreesToAxisInt(deviceId, -stick.Pitch, HID_USAGES.HID_USAGE_Y);
                iReport.AxisX    = ConvertStickAxisDegreesToAxisInt(deviceId, stick.Roll, HID_USAGES.HID_USAGE_X);
                iReport.AxisZRot = ConvertStickAxisDegreesToAxisInt(deviceId, stick.Yaw, HID_USAGES.HID_USAGE_RZ);

                var dThrusters = thrusterAxis.WithDeadzone(directionalThrustersDeadzonePercentage / 100f);

                iReport.AxisXRot = ConvertAxisRatioToAxisInt(deviceId, dThrusters.Value.x, HID_USAGES.HID_USAGE_RX);
                iReport.AxisYRot = ConvertAxisRatioToAxisInt(deviceId, dThrusters.Value.y, HID_USAGES.HID_USAGE_RY);
                iReport.Slider   = ConvertAxisRatioToAxisInt(deviceId, dThrusters.Value.z, HID_USAGES.HID_USAGE_SL0);

                var throttleWithDeadZone = Mathf.Abs(throttle) < (throttleDeadzonePercentage / 100f) ? 0f : throttle;
                iReport.AxisZ = ConvertAxisRatioToAxisInt(deviceId, throttleWithDeadZone, HID_USAGES.HID_USAGE_Z);

                // @todo Sensor zoom azis
                iReport.Dial = ConvertAxisRatioToAxisInt(deviceId, sensorZoom, HID_USAGES.HID_USAGE_SL1);
            }
            else
            {
                // Make sure all the joystick axis are reset
                iReport.AxisY    = ConvertStickAxisDegreesToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_Y);
                iReport.AxisX    = ConvertStickAxisDegreesToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_X);
                iReport.AxisZRot = ConvertStickAxisDegreesToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_RZ);
                iReport.AxisXRot = ConvertAxisRatioToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_RX);
                iReport.AxisYRot = ConvertAxisRatioToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_RY);
                iReport.Slider   = ConvertAxisRatioToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_SL0);
                iReport.AxisZ    = ConvertAxisRatioToAxisInt(deviceId, 0, HID_USAGES.HID_USAGE_Z);
            }

            iReport.Buttons = buttons;

            iReport.bHats = (uint)((byte)hat[3] << 12)
                            | (uint)((byte)hat[2] << 8)
                            | (uint)((byte)hat[1] << 4)
                            | (uint)hat[0];

            // Device 2, primarily map
            if (MapAxisEnabled)
            {
                // Translation
                iReport2.AxisX = ConvertAxisRatioToAxisInt(secondaryDeviceId, mapTranslationAxis.x, HID_USAGES.HID_USAGE_X);
                iReport2.AxisY = ConvertAxisRatioToAxisInt(secondaryDeviceId, mapTranslationAxis.y, HID_USAGES.HID_USAGE_Y);
                iReport2.AxisZ = ConvertAxisRatioToAxisInt(secondaryDeviceId, mapTranslationAxis.z, HID_USAGES.HID_USAGE_Z);

                // Pitch / Yaw
                iReport2.AxisXRot = ConvertAxisRatioToAxisInt(secondaryDeviceId, -mapPitchAxis, HID_USAGES.HID_USAGE_RX);
                iReport2.AxisZRot = ConvertAxisRatioToAxisInt(secondaryDeviceId, mapYawAxis, HID_USAGES.HID_USAGE_RZ);

                // Zoom
                iReport2.Dial = ConvertAxisRatioToAxisInt(secondaryDeviceId, -mapZoomAxis, HID_USAGES.HID_USAGE_SL1);
            }
            else
            {
                // Make sure the map axis are reset
                iReport2.AxisX    = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_X);
                iReport2.AxisY    = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_Y);
                iReport2.AxisZ    = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_Z);
                iReport2.AxisXRot = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_RX);
                iReport2.AxisZRot = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_RZ);
                iReport2.Dial     = ConvertAxisRatioToAxisInt(secondaryDeviceId, 0, HID_USAGES.HID_USAGE_SL1);
            }

            if (!vjoy.UpdateVJD(deviceId, ref iReport))
            {
                Debug.LogFormat("vJoy Device {0} update failed", deviceId);
                SetStatus(VJoyStatus.DeviceError);
                enabled = false;
            }
            if (!vjoy.UpdateVJD(secondaryDeviceId, ref iReport2))
            {
                Debug.LogFormat("vJoy Device {0} update failed", secondaryDeviceId);
                SetStatus(VJoyStatus.DeviceError);
                enabled = false;
            }
        }