public void Feed() { // Just a randomizer to provide random values to simulate input; Random rndVal = new Random(); while (EmuClient.InputClientConnected) { // Provide axistype and value to set it's state. When AxisEnum is cast as integer, the values correspond to DirectInput axis gamepad values. // This is useful, when you want to directly bind from Axis array returned by DirectInput to Emucontroller, specifying indices for both, or example: // DirectInput Device Axis Array[i].value to EmuController Axes.SetAxis((AxisEnum)i, value); EmuControllerInputState ctrlState = (EmuControllerInputState)EmuClient.InputState; ctrlState.Axes.SetValue(AxisEnum.AxisY, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisY, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisZ, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisRx, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisRy, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisRz, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisSlider, (ushort)rndVal.Next(0, 65535)); ctrlState.Axes.SetValue(AxisEnum.AxisDial, (ushort)rndVal.Next(0, 65535)); // Supports 128 buttons that fit in 16 bytes. ctrlState.Buttons.SetValue(rndVal.Next(0, 31), true); ctrlState.Buttons.SetValue(rndVal.Next(0, 31), false); ctrlState.Buttons.SetValue(rndVal.Next(0, 31), true); ctrlState.Buttons.SetValue(rndVal.Next(0, 31), false); ctrlState.Buttons.SetValue(rndVal.Next(32, 127), true); ctrlState.Buttons.SetValue(rndVal.Next(32, 127), false); ctrlState.Buttons.SetValue(rndVal.Next(32, 127), true); ctrlState.Buttons.SetValue(rndVal.Next(32, 127), false); // Supports 4 dpads that have 8 directions. -1 = Null, 0 = North, // incrementing value will advance the dpad position 45 degrees clockwise; ctrlState.DPads.SetValue(0, (DPadDirectionEnum)rndVal.Next(-1, 7)); ctrlState.DPads.SetValue(1, (DPadDirectionEnum)rndVal.Next(-1, 7)); ctrlState.DPads.SetValue(2, (DPadDirectionEnum)rndVal.Next(-1, 7)); ctrlState.DPads.SetValue(3, (DPadDirectionEnum)rndVal.Next(-1, 7)); // There are two ways to update EmuController. // First one sends the whole input report. // The controls for which values are not set by user, will have the default values. //EmuClient.SendInputReport(); // The other option is to send only the values for controls that are updated by user. // Any control that has not been updated will retain the previous value that was sent // to Emucontroller device. EmuClient.SendUpdate(); } }
public void GetInputReportMessageTest() { int headerSize = 2; EmuControllerInputState emu = new EmuControllerInputState(); byte[] message = emu.GetInputReportMessage(); Assert.IsTrue(message.Length == message[1] + headerSize); int totalLength = headerSize + 1; totalLength += emu.Axes.AllValues.Length * sizeof(ushort); totalLength += emu.Buttons.AllValues.Length * sizeof(ushort); totalLength += emu.DPads.AllValues.Length; Assert.IsTrue(message.Length == totalLength); }
public void GetUpdatedValuesTest() { EmuControllerInputState emu = new EmuControllerInputState(); emu.Buttons.SetValue(0, true); emu.Buttons.SetValue(0, false); emu.Buttons.SetValue(8, true); emu.Buttons.SetValue(16, true); emu.Buttons.SetValue(16, false); ReadOnlySpan <ushort> updatedButtons = emu.Buttons.GetUpdatedValues(); Assert.IsTrue(updatedButtons.Length == 2); }
public void SetValueTest() { EmuControllerInputState emu = new EmuControllerInputState(); Random rndVal = new Random(); for (int i = 0; i < emu.Buttons.AllValues.Length * sizeof(ushort); i++) { int index = rndVal.Next(0, emu.Buttons.AllValues.Length * sizeof(ushort)); emu.Buttons.SetValue(index, true); Assert.IsTrue(Utils.IsBitSet(emu.Buttons.AllValues[index / 16], index % 16)); emu.Buttons.SetValue(index, false); Assert.IsFalse(Utils.IsBitSet(emu.Buttons.AllValues[index / 16], index % 16)); } }
public void GetStateUpdateMessageTest() { Random rndVal = new Random(); int headerSize = 2; EmuControllerInputState emu = new EmuControllerInputState(); for (int i = 0; i < 100; i++) { AxisEnum ax1 = (AxisEnum)rndVal.Next(0, 8); ushort ax1Val = (ushort)rndVal.Next(0, 65536); int buttonIndex1 = rndVal.Next(0, 128); int dpad1 = rndVal.Next(0, 4); DPadDirectionEnum dpad1Val = (DPadDirectionEnum)rndVal.Next(-1, 8); emu.Axes.SetValue(ax1, ax1Val); emu.Buttons.SetValue(buttonIndex1, true); emu.DPads.SetValue(dpad1, dpad1Val); byte[] message = emu.GetStateUpdateMessage(); int expectedMessageLen = 2 * sizeof(ushort) + sizeof(byte) + 6 + headerSize; Assert.IsTrue(message.Length == expectedMessageLen); Assert.IsTrue(message[1] == message.Length - headerSize); Assert.IsTrue(message[2] == (byte)UsageId.Axis); Assert.IsTrue(Utils.IsBitSet(message[3], (byte)ax1)); Assert.IsTrue(BitConverter.ToUInt16(message, 4) == ax1Val); Assert.IsTrue(message[6] == (byte)UsageId.Button); Assert.IsTrue(Utils.IsBitSet(message[7], buttonIndex1 / 16)); Assert.IsTrue(Utils.IsBitSet(BitConverter.ToUInt16(message, 8), buttonIndex1 % 16)); Assert.IsTrue(message[10] == (byte)UsageId.DPad); Assert.IsTrue(Utils.IsBitSet(message[11], (byte)dpad1)); Assert.IsTrue(message[12] == (byte)dpad1Val); } }
/// <summary> /// Initializes EmuControllerClient object and automatically populates ConnectedEmuControllerDevices with available devices. /// </summary> public EmuControllerClient() { InputState = new EmuControllerInputState(); GetEmuControllers(); }