public static Joystick getManipulatorRight(IntPtr windowHandle) { if (JoystickFactory.manipulatorRight != null) return manipulatorRight; else return JoystickFactory.manipulatorRight = new Joystick( windowHandle, 0, 250, JoystickType.ManipulatorRight); }
public static Joystick getMainController(IntPtr windowHandle) { if (JoystickFactory.mainController != null) return mainController; else return JoystickFactory.mainController = new Joystick( windowHandle, 0, 250, JoystickType.MainController); }
public static Joystick getManipulatorLeft(IntPtr windowHandle) { if (JoystickFactory.manipulatorLeft != null) return manipulatorLeft; else return JoystickFactory.manipulatorLeft = new Joystick( windowHandle, 1, 255, JoystickType.ManipulatorLeft); }
private void btnUsePort_Click(object sender, EventArgs e) { try { String port = cmbAvailablePorts.SelectedItem.ToString(); numberOfJoysticksAttached = Joystick.getNumberOfJoysticks(); if (numberOfJoysticksAttached == 3) { joystickManipulatorLeft = JoystickFactory.getManipulatorLeft(this.Handle); joystickManipulatorRight = JoystickFactory.getManipulatorRight(this.Handle); joystickManipulatorLeft.Acquire(); joystickManipulatorRight.Acquire(); } if (!String.IsNullOrEmpty(port)) { List<PacketBuilder> pb = new List<PacketBuilder>(); mainpacketbuilder = new MainPacketBuilder(joystick); pb.Add(mainpacketbuilder); if (numberOfJoysticksAttached == 3) { pb.Add(new ManipulatorLeftPacketBuilder(joystickManipulatorLeft)); pb.Add(new ManipulatorRightPacketBuilder(joystickManipulatorRight)); } stateSender = new StateSender(pb); btnUsePort.Enabled = false; stateReceiver = new StateReceiver(); stateReceiver.DataReceived += ComPort_DataReceived; } } catch (Exception) { MessageBox.Show("No compatible device found!"); } }
public ManipulatorRightPacketBuilder(Joystick joystick) : base(joystick) { }
private bool AllAxisesAreInNeutral(Joystick joystick) { return (joystick.Pitch() == 125 && joystick.Roll() == 125 && joystick.Throttle() == 125); }
private void JoystickTracker_Load(object sender, EventArgs e) { joystick = JoystickFactory.getMainController(this.Handle); joystick.Acquire(); string[] ports = SerialPort.GetPortNames(); cmbAvailablePorts.DataSource = ports; tmrRefreshStick.Enabled = true; }
private void JoystickTracker_Load(object sender, EventArgs e) { joystick = new Joystick(this.Handle, 0, 250, JoystickType.MainController); System.Threading.WaitHandle waitHandle = new System.Threading.AutoResetEvent(false); joystick.Acquire(waitHandle); stateStore = new JoystickStateStore(); if(Joystick.GetNumberOfJoysticks() > 1) { joystick2 = new Joystick(this.Handle, 0, 250, JoystickType.ManipulatorRight); System.Threading.WaitHandle waitHandle2 = new System.Threading.AutoResetEvent(false); joystick2.Acquire(waitHandle2); manipPacketBuilder = new ManipulatorRightPacketBuilder(joystick2); JoystickStateListener interruptListener2 = new JoystickStateListener(joystick2, manipPacketBuilder, stateStore); listener2 = new Thread(interruptListener2.Listen); listener2.IsBackground = true; listener2.Start(); } mainpacketbuilder = new MainPacketBuilder(joystick); JoystickStateListener interruptListener = new JoystickStateListener(joystick, mainpacketbuilder, stateStore); interruptListener.JoystickStateChanged += JoystickState_Changed; listener = new Thread(interruptListener.Listen); listener.IsBackground = true; listener.Start(); CommunicationServer comServer = new CommunicationServer(stateStore); comServer.RovStateReceived += RovState_Received; comThread = new Thread(comServer.Serve); comThread.IsBackground = true; comThread.Start(); SerialPortSingleton.Instance.Write(Constants.InitializationPacket, 0, Constants.InitializationPacket.Length); }