public void Devices_HIDsWithoutProductName_AreNamedByTheirVendorAndProductID() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); var device = (HID)InputSystem.devices.First(x => x is HID); Assert.That(device.name, Is.EqualTo("1234-5678")); }
public void Devices_SupportsMultipleHIDHatSwitches() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.HatSwitch, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 4, reportOffsetInBits = 0, logicalMin = 0, logicalMax = 7, physicalMin = 0, physicalMax = 315, flags = HID.HIDElementFlags.NullState }, new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.HatSwitch, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 4, reportOffsetInBits = 4, logicalMin = 0, logicalMax = 7, physicalMin = 0, physicalMax = 315, flags = HID.HIDElementFlags.NullState } } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); var hid = (HID)InputSystem.devices.First(x => x is HID); Assert.That(hid["dpad"], Is.TypeOf <DpadControl>()); Assert.That(hid["dpad1"], Is.TypeOf <DpadControl>()); Assert.That(hid["dpad"].stateBlock.byteOffset, Is.EqualTo(0)); Assert.That(hid["dpad"].stateBlock.bitOffset, Is.EqualTo(0)); Assert.That(hid["dpad1"].stateBlock.byteOffset, Is.EqualTo(0)); Assert.That(hid["dpad1"].stateBlock.bitOffset, Is.EqualTo(4)); }
public void Devices_HIDDescriptorSurvivesReload() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); InputSystem.Save(); InputSystem.Reset(); InputSystem.Restore(); var hid = (HID)InputSystem.devices.First(x => x is HID); Assert.That(hid.hidDescriptor.vendorId, Is.EqualTo(0x1234)); Assert.That(hid.hidDescriptor.productId, Is.EqualTo(0x5678)); }
public void Devices_HIDsIgnoreUnusedExcessElements() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, inputReportSize = 36, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, new HID.HIDElementDescriptor { usage = 0x23435, usagePage = (HID.UsagePage) 0x544314, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 } } }; testRuntime.ReportNewInputDevice(new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); var device = InputSystem.devices.First(x => x is HID); Assert.That(device.stateBlock.sizeInBits, Is.EqualTo(32)); }
public void Devices_CanGetDescriptorFromHID() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, productId = 1234, vendorId = 5678, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); var device = (HID)InputSystem.devices.First(x => x is HID); Assert.That(device.hidDescriptor.productId, Is.EqualTo(1234)); Assert.That(device.hidDescriptor.vendorId, Is.EqualTo(5678)); Assert.That(device.hidDescriptor.elements.Length, Is.EqualTo(1)); }
public void Devices_SupportsHIDNpad() { var hidDescriptor = new HID.HIDDeviceDescriptor { vendorId = 0x57e, productId = 0x2009, }; var device = InputSystem.AddDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }); Assert.That(device, Is.TypeOf <SwitchProControllerHID>()); var controller = (SwitchProControllerHID)device; InputSystem.QueueStateEvent(controller, new SwitchProControllerHIDInputState { leftStickX = 0x10, leftStickY = 0x10, rightStickX = 0x80, rightStickY = 0xf2, }); InputSystem.Update(); var leftStickDeadzone = controller.leftStick.TryGetProcessor <StickDeadzoneProcessor>(); var rightStickDeadzone = controller.rightStick.TryGetProcessor <StickDeadzoneProcessor>(); var currentLeft = controller.leftStick.ReadValue(); var expectedLeft = leftStickDeadzone.Process(new Vector2(-1.0f, 1.0f)); var currentRight = controller.rightStick.ReadValue(); var expectedRight = rightStickDeadzone.Process(new Vector2(0.0f, -1.0f)); Assert.That(currentLeft, Is.EqualTo(expectedLeft).Using(Vector2EqualityComparer.Instance)); Assert.That(currentRight, Is.EqualTo(expectedRight).Using(new Vector2EqualityComparer(0.01f))); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.A), controller.buttonEast); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.B), controller.buttonSouth); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.X), controller.buttonNorth); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.Y), controller.buttonWest); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.StickL), controller.leftStickButton); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.StickR), controller.rightStickButton); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.L), controller.leftShoulder); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.R), controller.rightShoulder); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.ZL), controller.leftTrigger); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.ZR), controller.rightTrigger); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.Plus), controller.startButton); AssertButtonPress(controller, StateWithButton(SwitchProControllerHIDInputState.Button.Minus), controller.selectButton); }
public void Devices_GenericHIDXAndYDrivesStickControl() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.Joystick, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 9, elements = new[] { // 16bit X and Y axes. new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 0, reportSizeInBits = 16 }, new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.Y, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 16, reportSizeInBits = 16 }, } }; runtime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); var device = InputSystem.devices[0]; Assert.That(device, Is.TypeOf <Joystick>()); Assert.That(device["Stick"], Is.TypeOf <StickControl>()); InputSystem.QueueStateEvent(device, new SimpleJoystickLayout { reportId = 1, x = ushort.MaxValue, y = ushort.MaxValue }); InputSystem.Update(); Vector2 stickValue = (device["Stick"] as StickControl).ReadValue(); Assert.That(stickValue.x, Is.EqualTo(1.0f).Within(0.01f)); Assert.That(stickValue.y, Is.EqualTo(1.0f).Within(0.01f)); }
public void Devices_SupportsSwitchLikeControllers(int vendorId, int productId) { var hidDescriptor = new HID.HIDDeviceDescriptor { vendorId = vendorId, productId = productId, }; var device = InputSystem.AddDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }); Assert.That(device, Is.TypeOf <SwitchProControllerHID>()); }
public void Editor_DomainReload_CanRestoreDevicesBuiltWithDynamicallyGeneratedLayouts() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf <HID>()); InputSystem.SaveAndReset(); Assert.That(InputSystem.devices, Is.Empty); var state = InputSystem.GetSavedState(); var manager = InputSystem.s_Manager; manager.m_SavedAvailableDevices = state.managerState.availableDevices; manager.m_SavedDeviceStates = state.managerState.devices; manager.RestoreDevicesAfterDomainReload(); Assert.That(InputSystem.devices, Has.Exactly(1).TypeOf <HID>()); InputSystem.Restore(); }
public void Devices_HIDDevicesDifferingOnlyByUsageGetSeparateLayouts() { var hidDescriptor1 = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, productId = 1234, vendorId = 5678, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 32 }, } }; var hidDescriptor2 = hidDescriptor1; hidDescriptor2.usage = (int)HID.GenericDesktop.Gamepad; runtime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor1.ToJson() }.ToJson()); runtime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor2.ToJson() }.ToJson()); InputSystem.Update(); Assert.AreEqual(InputSystem.devices.Count(), 2); Assert.AreNotEqual(InputSystem.devices[0].layout, InputSystem.devices[1].layout); }
public void Devices_DevicesNotAllowedByShouldCreateHIDAreSkipped() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = 1234, usagePage = (HID.UsagePage) 5678, // need at least one valid element for the device not to be ignored elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 0, reportSizeInBits = 16 }, } }; var descriptionJson = new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor.ToJson() }.ToJson(); var deviceId = runtime.AllocateDeviceId(); runtime.ReportNewInputDevice(descriptionJson, deviceId); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(0)); Assert.That(InputSystem.GetDeviceById(deviceId), Is.Null); HIDSupport.shouldCreateHID += descriptor => descriptor.usagePage == (HID.UsagePage) 5678 && descriptor.usage == 1234 ? true : (bool?)null; runtime.ReportNewInputDevice(descriptionJson, deviceId); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); Assert.That(InputSystem.GetDeviceById(deviceId), Is.Not.Null); }
public void Devices_GenericHIDConvertsXAndYUsagesToStickControl() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.Joystick, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { // 16bit X and Y axes. new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 0, reportSizeInBits = 16 }, new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.Y, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 16, reportSizeInBits = 16 }, } }; runtime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); var device = InputSystem.devices[0]; Assert.That(device, Is.TypeOf <Joystick>()); Assert.That(device["Stick"], Is.TypeOf <StickControl>()); }
public unsafe void Devices_SupportsHIDHatSwitches() { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, vendorId = 0x1234, productId = 0x5678, inputReportSize = 4, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.HatSwitch, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportSizeInBits = 4, reportOffsetInBits = 0, logicalMin = 0, logicalMax = 7, // This combination of min/max means that 8 (given we have 4 bits) is out of range and thus the null state. physicalMin = 0, physicalMax = 315, flags = HID.HIDElementFlags.NullState } } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); var hid = (HID)InputSystem.devices.First(x => x is HID); Assert.That(hid["dpad"], Is.TypeOf <DpadControl>()); // Assert that default state is set correctly. Assert.That(hid["dpad/up"].ReadValueAsObject(), Is.EqualTo(0).Within(0.00001)); Assert.That(hid["dpad/down"].ReadValueAsObject(), Is.EqualTo(0).Within(0.00001)); Assert.That(hid["dpad/left"].ReadValueAsObject(), Is.EqualTo(0).Within(0.00001)); Assert.That(hid["dpad/right"].ReadValueAsObject(), Is.EqualTo(0).Within(0.00001)); InputEventPtr eventPtr; using (StateEvent.From(hid, out eventPtr)) { var stateData = (byte *)StateEvent.From(eventPtr)->state; const int kNull = 8; const int kUp = 0; const int kUpRight = 1; const int kRight = 2; const int kRightDown = 3; const int kDown = 4; const int kDownLeft = 5; const int kLeft = 6; const int kLeftUp = 7; stateData[0] = kNull; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo(Vector2.zero).Using(vector2Comparer)); stateData[0] = kUp; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo(Vector2.up).Using(vector2Comparer)); stateData[0] = kUpRight; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo((Vector2.up + Vector2.right).normalized).Using(vector2Comparer)); stateData[0] = kRight; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo(Vector2.right).Using(vector2Comparer)); stateData[0] = kRightDown; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo((Vector2.right + Vector2.down).normalized).Using(vector2Comparer)); stateData[0] = kDown; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo(Vector2.down).Using(vector2Comparer)); stateData[0] = kDownLeft; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo((Vector2.down + Vector2.left).normalized).Using(vector2Comparer)); stateData[0] = kLeft; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo(Vector2.left).Using(vector2Comparer)); stateData[0] = kLeftUp; InputSystem.QueueEvent(eventPtr); InputSystem.Update(); Assert.That(hid["dpad"].ReadValueAsObject(), Is.EqualTo((Vector2.left + Vector2.up).normalized).Using(vector2Comparer)); } }
public void Devices_CanCreateGenericHID_FromDeviceWithParsedReportDescriptor() { var deviceId = testRuntime.AllocateDeviceId(); unsafe { testRuntime.SetDeviceCommandCallback(deviceId, (id, commandPtr) => { if (commandPtr->type == HID.QueryHIDParsedReportDescriptorDeviceCommandType) { var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, elements = new[] { new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 0, reportSizeInBits = 16 }, new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.Y, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 16, reportSizeInBits = 16 }, new HID.HIDElementDescriptor { usage = (int)HID.Button.Primary, usagePage = HID.UsagePage.Button, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 32, reportSizeInBits = 1 }, new HID.HIDElementDescriptor { usage = (int)HID.Button.Secondary, usagePage = HID.UsagePage.Button, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 33, reportSizeInBits = 1 }, } }; var hidDescriptorString = hidDescriptor.ToJson(); var utf8 = Encoding.UTF8.GetBytes(hidDescriptorString); var utf8Length = utf8.Length; if (commandPtr->payloadSizeInBytes < utf8Length) { return(-utf8Length); } fixed(byte *utf8Ptr = utf8) { UnsafeUtility.MemCpy(commandPtr->payloadPtr, utf8Ptr, utf8Length); } return(utf8Length); } return(-1); }); } testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", }.ToJson(), deviceId); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); var device = InputSystem.devices[0]; Assert.That(device, Is.TypeOf <HID>()); Assert.That(device.description.interfaceName, Is.EqualTo(HID.kHIDInterface)); var hid = (HID)device; Assert.That(hid.hidDescriptor.elements, Is.Not.Null); Assert.That(hid.hidDescriptor.elements.Length, Is.EqualTo(4)); Assert.That(device.children, Has.Count.EqualTo(4)); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("x").And.TypeOf <AxisControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("y").And.TypeOf <AxisControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("button1").And.TypeOf <ButtonControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("button2").And.TypeOf <ButtonControl>()); }
public void Devices_CanCreateGenericHID() { // Construct a HID descriptor for a bogus multi-axis controller. var hidDescriptor = new HID.HIDDeviceDescriptor { usage = (int)HID.GenericDesktop.MultiAxisController, usagePage = HID.UsagePage.GenericDesktop, elements = new[] { // 16bit X and Y axes. new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.X, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 0, reportSizeInBits = 16 }, new HID.HIDElementDescriptor { usage = (int)HID.GenericDesktop.Y, usagePage = HID.UsagePage.GenericDesktop, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 16, reportSizeInBits = 16 }, // 1bit primary and secondary buttons. new HID.HIDElementDescriptor { usage = (int)HID.Button.Primary, usagePage = HID.UsagePage.Button, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 32, reportSizeInBits = 1 }, new HID.HIDElementDescriptor { usage = (int)HID.Button.Secondary, usagePage = HID.UsagePage.Button, reportType = HID.HIDReportType.Input, reportId = 1, reportOffsetInBits = 33, reportSizeInBits = 1 }, } }; testRuntime.ReportNewInputDevice( new InputDeviceDescription { interfaceName = HID.kHIDInterface, manufacturer = "TestVendor", product = "TestHID", capabilities = hidDescriptor.ToJson() }.ToJson()); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); var device = InputSystem.devices[0]; Assert.That(device, Is.TypeOf <HID>()); Assert.That(device.description.interfaceName, Is.EqualTo(HID.kHIDInterface)); Assert.That(device.children, Has.Count.EqualTo(4)); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("x").And.TypeOf <AxisControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("y").And.TypeOf <AxisControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("button1").And.TypeOf <ButtonControl>()); Assert.That(device.children, Has.Exactly(1).With.Property("name").EqualTo("button2").And.TypeOf <ButtonControl>()); var x = device["x"]; var y = device["y"]; var button1 = device["button1"]; var button2 = device["button2"]; Assert.That(device.stateBlock.sizeInBits, Is.EqualTo(5 * 8)); Assert.That(x.stateBlock.byteOffset, Is.Zero); Assert.That(y.stateBlock.byteOffset, Is.EqualTo(2)); Assert.That(x.stateBlock.bitOffset, Is.Zero); Assert.That(y.stateBlock.bitOffset, Is.Zero); Assert.That(button1.stateBlock.byteOffset, Is.EqualTo(4)); Assert.That(button2.stateBlock.byteOffset, Is.EqualTo(4)); Assert.That(button1.stateBlock.bitOffset, Is.EqualTo(0)); Assert.That(button2.stateBlock.bitOffset, Is.EqualTo(1)); }