static public ControllerState ReadFromPacket(byte[] packet) { if (packet.Length < PACKET_SIZE) { return(null); } var state = new ControllerStateBuilder(); for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS [i])) { continue; } state.SetButton(BUTTONS[i], packet[i] != 0x00); } state.SetAnalog("stick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length))); state.SetAnalog("stick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 8))); byte[] newPacket = new byte[4]; newPacket[0] = SignalTool.readByte(packet, 0); newPacket[1] = SignalTool.readByte(packet, 8); newPacket[2] = SignalTool.readByte(packet, 16); newPacket[3] = SignalTool.readByte(packet, 24); return(state.Build(newPacket)); }
static public ControllerState ReadFromPacket(byte[] packet) { if (packet.Length < PACKET_SIZE) { return(null); } // Currently only support digital and analog in red mode if (packet[0] != 0x41 && packet[0] != 0x73) { return(null); } var state = new ControllerStateBuilder(); for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS [i])) { continue; } state.SetButton(BUTTONS[i], packet[i] != 0x00); } if (packet[0] == 0x73) { state.SetAnalog("rstick_x", readStick(packet[17])); state.SetAnalog("rstick_y", readStick(packet[18])); state.SetAnalog("lstick_x", readStick(packet[19])); state.SetAnalog("lstick_y", readStick(packet[20])); } return(state.Build()); }
static public ControllerState ReadFromPacket(byte[] packet) { if (packet.Length < PACKET_SIZE) { return(null); } byte[] data = new byte[PACKET_SIZE / 8]; for (int i = 0; i < PACKET_SIZE / 8; i++) { data[i] = unencrypt(SignalTool.readByte(packet, i * 8)); } var state = new ControllerStateBuilder(); for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS[i])) { continue; } state.SetButton(BUTTONS[i], (data[4 + i / 8] & (0x01 << (i % 8))) == 0x00); } state.SetAnalog("lstick_x", readLeftStick(data[0] & 0x3F)); state.SetAnalog("lstick_y", readLeftStick(data[1] & 0x3F)); state.SetAnalog("rstick_x", readRightStick(((data[0] & 0xC0) >> 3) | ((data[1] & 0xC0) >> 5) | ((data[2] & 0x80) >> 7))); state.SetAnalog("rstick_y", readRightStick(data[2] & 0x1F)); state.SetAnalog("trig_l", readTrigger(((data[2] & 0x60) >> 2) | ((data[3] & 0xE0) >> 5))); state.SetAnalog("trig_r", readTrigger(data[3] & 0x1F)); return(state.Build()); }
static public ControllerState ReadFromPacket(byte[] packet) { if (packet.Length < PACKET_SIZE) { return(null); } var state = new ControllerStateBuilder(); for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS [i])) { continue; } state.SetButton(BUTTONS[i], packet[i] != 0x00); } state.SetAnalog("lstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length))); state.SetAnalog("lstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 8))); state.SetAnalog("cstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length + 16))); state.SetAnalog("cstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 24))); state.SetAnalog("trig_l", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 32))); state.SetAnalog("trig_r", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 40))); return(state.Build()); }
void tick(object sender, EventArgs e) { if (_joystick.Poll().IsFailure) { Finish(); if (ControllerDisconnected != null) { ControllerDisconnected(this, EventArgs.Empty); } return; } var outState = new ControllerStateBuilder(); var state = _joystick.GetCurrentState(); for (int i = 0; i < _joystick.Capabilities.ButtonCount; ++i) { outState.SetButton("b" + i.ToString(), state.IsPressed(i)); } int[] pov = state.GetPointOfViewControllers(); outState.SetButton("up", false); outState.SetButton("right", false); outState.SetButton("down", false); outState.SetButton("left", false); if (pov != null && pov.Length > 0 && pov[0] >= 0) { outState.SetButton("up", pov[0] > octantAngle(6) || pov[0] < octantAngle(1)); outState.SetButton("right", pov[0] > octantAngle(0) && pov[0] < octantAngle(3)); outState.SetButton("down", pov[0] > octantAngle(2) && pov[0] < octantAngle(5)); outState.SetButton("left", pov[0] > octantAngle(4) && pov[0] < octantAngle(7)); } float x = (float)state.X / RANGE; float y = (float)state.Y / RANGE; outState.SetAnalog("x", x); outState.SetButton(x < 0 ? "left" : "right", x != 0); outState.SetAnalog("y", y); outState.SetButton(y < 0 ? "up" : "down", y != 0); outState.SetAnalog("z", (float)state.Z / RANGE); outState.SetAnalog("rx", (float)state.RotationX / RANGE); outState.SetAnalog("ry", (float)state.RotationY / RANGE); outState.SetAnalog("rz", (float)state.RotationZ / RANGE); if (ControllerStateChanged != null) { ControllerStateChanged(this, outState.Build()); } }
static public ControllerState ReadFromPacket (byte[] packet) { if (packet.Length < PACKET_SIZE) return null; var state = new ControllerStateBuilder (); for (int i = 0 ; i < BUTTONS.Length ; ++i) { if (string.IsNullOrEmpty (BUTTONS [i])) continue; state.SetButton (BUTTONS[i], packet[i] != 0x00); } return state.Build (); }
static ControllerState readPacketButtons (byte[] packet, string[] buttons) { if (packet.Length < buttons.Length) return null; var state = new ControllerStateBuilder (); for (int i = 0 ; i < buttons.Length ; ++i) { if (string.IsNullOrEmpty (buttons [i])) continue; state.SetButton (buttons[i], packet[i] != 0x00); } return state.Build (); }
static public ControllerState ReadFromPacket(byte[] packet) { var state = new ControllerStateBuilder(); switch (packet.Length) { // Standard 64 bit packet size case PACKET_SIZE: for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS[i])) { continue; } state.SetButton(BUTTONS[i], packet[i] != 0x00); Console.WriteLine(i + ": " + packet[i]); } state.SetAnalog("lstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length))); state.SetAnalog("lstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 8))); state.SetAnalog("cstick_x", readStick(SignalTool.readByte(packet, BUTTONS.Length + 16))); state.SetAnalog("cstick_y", readStick(SignalTool.readByte(packet, BUTTONS.Length + 24))); state.SetAnalog("trig_l", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 32))); state.SetAnalog("trig_r", readTrigger(SignalTool.readByte(packet, BUTTONS.Length + 40))); break; // Packets are written as bytes when writing from the NicoHood API, so we're looking for a packet size of 8 (interpreted as bytes) case NICOHOOD_PACKET_SIZE: for (int i = 0; i < 16; i++) { if (string.IsNullOrEmpty(NICOHOOD_BUTTONS[i])) { continue; } int bitPacket = (packet[i / 8] >> (i % 8)) & 0x1; state.SetButton(NICOHOOD_BUTTONS[i], bitPacket != 0x00); } state.SetAnalog("lstick_x", readStick(packet[2])); state.SetAnalog("lstick_y", readStick(packet[3])); state.SetAnalog("cstick_x", readStick(packet[4])); state.SetAnalog("cstick_y", readStick(packet[5])); state.SetAnalog("trig_l", readTrigger(packet[6])); state.SetAnalog("trig_r", readTrigger(packet[7])); break; default: return(null); } return(state.Build()); }
static public ControllerState ReadFromPacket (byte[] packet) { if (packet.Length < PACKET_SIZE) return null; var state = new ControllerStateBuilder (); for (int i = 0 ; i < BUTTONS.Length ; ++i) { if (string.IsNullOrEmpty (BUTTONS [i])) continue; state.SetButton (BUTTONS[i], packet[i] != 0x00); } state.SetAnalog ("stick_x", readStick (SignalTool.readByte (packet, BUTTONS.Length ))); state.SetAnalog ("stick_y", readStick (SignalTool.readByte (packet, BUTTONS.Length + 8))); return state.Build (); }
void tick(object sender, EventArgs e) { var state = new XInputState(); if (XInputDLL.XInputGetState(_id, ref state) > 0) { if (ControllerDisconnected != null) { ControllerDisconnected(this, EventArgs.Empty); } Finish(); return; } var outState = new ControllerStateBuilder(); outState.SetButton("a", (state.wButtons & 0x1000) != 0); outState.SetButton("b", (state.wButtons & 0x2000) != 0); outState.SetButton("x", (state.wButtons & 0x4000) != 0); outState.SetButton("y", (state.wButtons & 0x8000) != 0); outState.SetButton("up", (state.wButtons & 0x0001) != 0); outState.SetButton("down", (state.wButtons & 0x0002) != 0); outState.SetButton("left", (state.wButtons & 0x0004) != 0); outState.SetButton("right", (state.wButtons & 0x0008) != 0); outState.SetButton("start", (state.wButtons & 0x0010) != 0); outState.SetButton("back", (state.wButtons & 0x0020) != 0); outState.SetButton("l3", (state.wButtons & 0x0040) != 0); outState.SetButton("r3", (state.wButtons & 0x0080) != 0); outState.SetButton("l", (state.wButtons & 0x0100) != 0); outState.SetButton("r", (state.wButtons & 0x0200) != 0); outState.SetAnalog("lstick_x", (float)state.sThumbLX / 32768); outState.SetAnalog("lstick_y", (float)state.sThumbLY / 32768); outState.SetAnalog("rstick_x", (float)state.sThumbRX / 32768); outState.SetAnalog("rstick_y", (float)state.sThumbRY / 32768); outState.SetAnalog("trig_l", (float)state.bLeftTrigger / 255); outState.SetAnalog("trig_r", (float)state.bRightTrigger / 255); if (ControllerStateChanged != null) { ControllerStateChanged(this, outState.Build()); } }
static ControllerState readPacketButtons(byte[] packet, string[] buttons) { if (packet.Length < buttons.Length) { return(null); } var state = new ControllerStateBuilder(); for (int i = 0; i < buttons.Length; ++i) { if (string.IsNullOrEmpty(buttons [i])) { continue; } state.SetButton(buttons[i], packet[i] != 0x00); } return(state.Build()); }
void tick (object sender, EventArgs e) { if (_joystick.Poll().IsFailure) { Finish (); if (ControllerDisconnected != null) ControllerDisconnected (this, EventArgs.Empty); return; } var outState = new ControllerStateBuilder (); var state = _joystick.GetCurrentState (); for (int i = 0; i < _joystick.Capabilities.ButtonCount; ++i) { outState.SetButton ("b"+i.ToString(), state.IsPressed(i)); } int[] pov = state.GetPointOfViewControllers (); outState.SetButton ("up", false); outState.SetButton ("right", false); outState.SetButton ("down", false); outState.SetButton ("left", false); if (pov != null && pov.Length > 0 && pov[0] >= 0) { outState.SetButton ("up", pov[0] > octantAngle (6) || pov[0] < octantAngle (1)); outState.SetButton ("right", pov[0] > octantAngle (0) && pov[0] < octantAngle (3)); outState.SetButton ("down", pov[0] > octantAngle (2) && pov[0] < octantAngle (5)); outState.SetButton ("left", pov[0] > octantAngle (4) && pov[0] < octantAngle (7)); } outState.SetAnalog ("x", (float)state.X / RANGE); outState.SetAnalog ("y", (float)state.Y / RANGE); outState.SetAnalog ("z", (float)state.Z / RANGE); outState.SetAnalog ("rx", (float)state.RotationX / RANGE); outState.SetAnalog ("ry", (float)state.RotationY / RANGE); outState.SetAnalog ("rz", (float)state.RotationZ / RANGE); if (ControllerStateChanged != null) ControllerStateChanged (this, outState.Build ()); }
static public ControllerState ReadFromPacket(byte[] packet) { if (packet.Length < PACKET_SIZE) { return(null); } var state = new ControllerStateBuilder(); for (int i = 0; i < BUTTONS.Length; ++i) { if (string.IsNullOrEmpty(BUTTONS[i])) { continue; } state.SetButton(BUTTONS[i], packet[i] != 0x00); if (packet[3] != 0x00) { state.SetAnalog("x", 1); } else if (packet[2] != 0x00) { state.SetAnalog("x", -1); } if (packet[0] != 0x00) { state.SetAnalog("y", 1); } else if (packet[1] != 0x00) { state.SetAnalog("y", -1); } } return(state.Build()); }
void tick (object sender, EventArgs e) { var state = new XInputState (); if (XInputDLL.XInputGetState (0, ref state) > 0) { if (ControllerDisconnected != null) ControllerDisconnected (this, EventArgs.Empty); Finish (); return; } var outState = new ControllerStateBuilder (); outState.SetButton ("a", (state.wButtons & 0x1000) != 0); outState.SetButton ("b", (state.wButtons & 0x2000) != 0); outState.SetButton ("x", (state.wButtons & 0x4000) != 0); outState.SetButton ("y", (state.wButtons & 0x8000) != 0); outState.SetButton ("up", (state.wButtons & 0x0001) != 0); outState.SetButton ("down", (state.wButtons & 0x0002) != 0); outState.SetButton ("left", (state.wButtons & 0x0004) != 0); outState.SetButton ("right", (state.wButtons & 0x0008) != 0); outState.SetButton ("start", (state.wButtons & 0x0010) != 0); outState.SetButton ("back", (state.wButtons & 0x0020) != 0); outState.SetButton ("l3", (state.wButtons & 0x0040) != 0); outState.SetButton ("r3", (state.wButtons & 0x0080) != 0); outState.SetButton ("l", (state.wButtons & 0x0100) != 0); outState.SetButton ("r", (state.wButtons & 0x0200) != 0); outState.SetAnalog ("lstick_x", (float)state.sThumbLX / 32768); outState.SetAnalog ("lstick_y", (float)state.sThumbLY / 32768); outState.SetAnalog ("rstick_x", (float)state.sThumbRX / 32768); outState.SetAnalog ("rstick_y", (float)state.sThumbRY / 32768); outState.SetAnalog ("trig_l", (float)state.bLeftTrigger / 255); outState.SetAnalog ("trig_r", (float)state.bRightTrigger / 255); if (ControllerStateChanged != null) ControllerStateChanged (this, outState.Build ()); }
public ControllerState Process(ControllerState state) { if (!ButtonEnabled && !AnalogEnabled && !MassEnabled) { return(state); } bool revert = false; bool filtered = false; _states.RemoveAt(0); // move by _states.Add(state); // one frame ControllerStateBuilder filteredStateBuilder = new ControllerStateBuilder(); { uint massCounter = 0; foreach (var button in _states[0].Buttons.Keys) { filteredStateBuilder.SetButton(button, _states[2].Buttons[button]); if (ButtonEnabled) { // previous previous frame equals current frame if (_states[0].Buttons[button] == _states[2].Buttons[button] && // AND current frame not equals previous frame _states[2].Buttons[button] != _states[1].Buttons[button]) { filteredStateBuilder.SetButton(button, false); // if noisy, we turn the button off filtered = true; } } if (MassEnabled) { if (_states[2].Buttons[button]) { massCounter++; } } } foreach (var button in _states[0].Analogs.Keys) { filteredStateBuilder.SetAnalog(button, _states[2].Analogs[button]); if (MassEnabled) { if (Math.Abs(Math.Abs(_states[2].Analogs[button]) - Math.Abs(_states[1].Analogs[button])) > 0.3) { massCounter++; } } if (AnalogEnabled) { // If we traveled over 0.5 Analog between the last three frames // but less than 0.1 in the frame before // we drop the change for this input if (Math.Abs(_states[2].Analogs[button] - _states[1].Analogs[button]) > .5f && Math.Abs(_states[1].Analogs[button] - _states[0].Analogs[button]) < 0.1f) { filteredStateBuilder.SetAnalog(button, _lastUnfiltered.Analogs[button]); filtered = true; } } } // if over 80% of the buttons are used we revert (this is either a reset button combo or a blink) if (massCounter > (_states[0].Analogs.Count + _states[0].Buttons.Count) * 0.8) { revert = true; } } if (revert) { return(_lastUnfiltered); } if (filtered) { return(filteredStateBuilder.Build()); } _lastUnfiltered = _states[2]; return(_states[2]); }
public void dataStream(object client_obj) { //Gecko Connection try { client = new TcpClient(); client.NoDelay = true; IAsyncResult ar = client.BeginConnect((string)client_obj, 7335, null, null); //Auto Splitter Input Display uses 7335 System.Threading.WaitHandle wh = ar.AsyncWaitHandle; try { if (!ar.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3), false)) { client.Close(); MessageBox.Show("WiiU: Connection Timeout!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); if (ControllerDisconnected != null) { _context.Post((SendOrPostCallback)(_ => ControllerDisconnected(this, EventArgs.Empty)), null); } return; } client.EndConnect(ar); } finally { wh.Close(); } } catch (Exception) { MessageBox.Show("WiiU: Connection Error. Check IP Address!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); if (ControllerDisconnected != null) { _context.Post((SendOrPostCallback)(_ => ControllerDisconnected(this, EventArgs.Empty)), null); } return; } //Handle Connection stream = client.GetStream(); EndianBinaryReader reader = new EndianBinaryReader(stream); try { float StickX, StickCX, StickY, StickCY = 0.0f; byte Buttons1, Buttons2, Buttons3 = 0; while (true) { byte cmd_byte = reader.ReadByte(); switch (cmd_byte) { case 0x01: //Input Data { //1 = 0 bit, 2 = 1 bit, 4 = 2 bit, 8 = 3 bit, 16 = 4 bit, 32 = 5 bit, 64 = 6 bit, 128 = 7 bit //Apply Inputs var outState = new ControllerStateBuilder(); StickX = reader.ReadSingle(); StickY = reader.ReadSingle(); if (StickX <= 1.0f && StickY <= 1.0f && StickX >= -1.0f && StickY >= -1.0f) { outState.SetAnalog("lstick_x", StickX); outState.SetAnalog("lstick_y", StickY); } StickCX = reader.ReadSingle(); StickCY = reader.ReadSingle(); if (StickCX <= 1.0f && StickCY <= 1.0f && StickCX >= -1.0f && StickCY >= -1.0f) { outState.SetAnalog("cstick_x", StickCX); outState.SetAnalog("cstick_y", StickCY); } Buttons1 = reader.ReadByte(); Buttons2 = reader.ReadByte(); Buttons3 = reader.ReadByte(); outState.SetButton("a", IsBitSet(Buttons1, 7)); outState.SetButton("b", IsBitSet(Buttons1, 6)); outState.SetButton("x", IsBitSet(Buttons1, 5)); outState.SetButton("y", IsBitSet(Buttons1, 4)); outState.SetButton("left", IsBitSet(Buttons1, 3)); outState.SetButton("right", IsBitSet(Buttons1, 2)); outState.SetButton("up", IsBitSet(Buttons1, 1)); outState.SetButton("down", IsBitSet(Buttons1, 0)); outState.SetButton("zl", IsBitSet(Buttons2, 7)); outState.SetButton("zr", IsBitSet(Buttons2, 6)); outState.SetButton("l", IsBitSet(Buttons2, 5)); outState.SetButton("r", IsBitSet(Buttons2, 4)); outState.SetButton("plus", IsBitSet(Buttons2, 3)); outState.SetButton("minus", IsBitSet(Buttons2, 2)); outState.SetButton("l3", IsBitSet(Buttons2, 1)); outState.SetButton("r3", IsBitSet(Buttons2, 0)); outState.SetButton("home", IsBitSet(Buttons3, 1)); outState.SetButton("touch", IsBitSet(Buttons3, 2)); if (ControllerStateChanged != null) { _context.Post((SendOrPostCallback)(_ => ControllerStateChanged(this, outState.Build())), null); } break; } default: throw new Exception("Invalid data"); } } } catch (ThreadAbortException) { } catch (Exception) { if (ControllerDisconnected != null) { _context.Post((SendOrPostCallback)(_ => ControllerDisconnected(this, EventArgs.Empty)), null); } } }