예제 #1
0
    public void Devices_HIDAxisLimits_DoNotUseDecimalFormatOfCurrentCulture()
    {
        var oldCulture = Thread.CurrentThread.CurrentCulture;

        try
        {
            // French locale uses comma as decimal separator.
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");

            var hidDescriptor =
                new HID.HIDDeviceDescriptorBuilder(HID.GenericDesktop.MultiAxisController)
                .StartReport(HID.HIDReportType.Input)
                .AddElement(HID.GenericDesktop.X, 16).WithLogicalMinMax(0, 65535).Finish();

            testRuntime.ReportNewInputDevice(
                new InputDeviceDescription
            {
                interfaceName = HID.kHIDInterface,
                manufacturer  = "TestVendor",
                product       = "TestHID",
                capabilities  = hidDescriptor.ToJson()
            }.ToJson());

            Assert.That(() => InputSystem.Update(), Throws.Nothing);
        }
        finally
        {
            Thread.CurrentThread.CurrentCulture = oldCulture;
        }
    }
예제 #2
0
    public void Devices_HIDAxesAreCenteredBetweenMinAndMax()
    {
        // Make up a HID that has both 16bit and 8bit axes in both signed and unsigned form.
        var hidDescriptor =
            new HID.HIDDeviceDescriptorBuilder(HID.GenericDesktop.MultiAxisController)
            .StartReport(HID.HIDReportType.Input)
            // 16bit [0..65535]
            .AddElement(HID.GenericDesktop.X, 16).WithLogicalMinMax(0, 65535)
            // 16bit [-32768..32767]
            .AddElement(HID.GenericDesktop.Y, 16).WithLogicalMinMax(-32768, 32767)
            // 8bit [0..255]
            .AddElement(HID.GenericDesktop.Rx, 8).WithLogicalMinMax(0, 255)
            // 8bit [-128..127]
            .AddElement(HID.GenericDesktop.Ry, 8).WithLogicalMinMax(-128, 127)
            // 16bit [0..10000]
            .AddElement(HID.GenericDesktop.Vx, 16).WithLogicalMinMax(0, 10000)
            // 16bit [-10000..10000]
            .AddElement(HID.GenericDesktop.Vy, 16).WithLogicalMinMax(-10000, 10000)
            .Finish();

        testRuntime.ReportNewInputDevice(
            new InputDeviceDescription
        {
            interfaceName = HID.kHIDInterface,
            manufacturer  = "TestVendor",
            product       = "TestHID",
            capabilities  = hidDescriptor.ToJson()
        }.ToJson());
        InputSystem.Update();

        var device = InputSystem.devices[0];

        // Test lower bound.
        InputSystem.QueueStateEvent(device, new SimpleAxisState
        {
            reportId = 1,
            x        = ushort.MinValue,
            y        = short.MinValue,
            rx       = byte.MinValue,
            ry       = sbyte.MinValue,
            vx       = 0,
            vy       = -10000,
        });
        InputSystem.Update();

        Assert.That(device["X"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));
        Assert.That(device["Y"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));
        Assert.That(device["Rx"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));
        Assert.That(device["Ry"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));
        Assert.That(device["Vx"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));
        Assert.That(device["Vy"].ReadValueAsObject(), Is.EqualTo(-1).Within(0.0001));

        // Test upper bound.
        InputSystem.QueueStateEvent(device, new SimpleAxisState
        {
            reportId = 1,
            x        = ushort.MaxValue,
            y        = short.MaxValue,
            rx       = byte.MaxValue,
            ry       = sbyte.MaxValue,
            vx       = 10000,
            vy       = 10000,
        });
        InputSystem.Update();

        Assert.That(device["X"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));
        Assert.That(device["Y"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));
        Assert.That(device["Rx"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));
        Assert.That(device["Ry"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));
        Assert.That(device["Vx"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));
        Assert.That(device["Vy"].ReadValueAsObject(), Is.EqualTo(1).Within(0.0001));

        // Test center.
        InputSystem.QueueStateEvent(device, new SimpleAxisState
        {
            reportId = 1,
            x        = ushort.MaxValue / 2,
            y        = 0,
            rx       = byte.MaxValue / 2,
            ry       = 0,
            vx       = 10000 / 2,
            vy       = 0,
        });
        InputSystem.Update();

        Assert.That(device["X"].ReadValueAsObject(), Is.EqualTo(0).Within(0.0001));
        Assert.That(device["Y"].ReadValueAsObject(), Is.EqualTo(0).Within(0.0001));
        ////FIXME: these accumulate some rather large errors
        Assert.That(device["Rx"].ReadValueAsObject(), Is.EqualTo(0).Within(0.004));
        Assert.That(device["Ry"].ReadValueAsObject(), Is.EqualTo(0).Within(0.004));
        Assert.That(device["Vx"].ReadValueAsObject(), Is.EqualTo(0).Within(0.0001));
        Assert.That(device["Vy"].ReadValueAsObject(), Is.EqualTo(0).Within(0.0001));
    }