コード例 #1
0
 public static Joystick getManipulatorRight(IntPtr windowHandle)
 {
     if (JoystickFactory.manipulatorRight != null)
         return manipulatorRight;
     else
         return JoystickFactory.manipulatorRight = new Joystick(
             windowHandle, 0, 250, JoystickType.ManipulatorRight);
 }
コード例 #2
0
 public static Joystick getMainController(IntPtr windowHandle)
 {
     if (JoystickFactory.mainController != null)
         return mainController;
     else
         return JoystickFactory.mainController = new Joystick(
             windowHandle, 0, 250, JoystickType.MainController);
 }
コード例 #3
0
 public static Joystick getManipulatorLeft(IntPtr windowHandle)
 {
     if (JoystickFactory.manipulatorLeft != null)
         return manipulatorLeft;
     else
         return JoystickFactory.manipulatorLeft = new Joystick(
             windowHandle, 1, 255, JoystickType.ManipulatorLeft);
 }
コード例 #4
0
        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!");

            }
        }
コード例 #5
0
 public ManipulatorRightPacketBuilder(Joystick joystick)
     : base(joystick)
 {
 }
コード例 #6
0
 private bool AllAxisesAreInNeutral(Joystick joystick)
 {
     return (joystick.Pitch() == 125 && joystick.Roll() == 125 && joystick.Throttle() == 125);
 }
コード例 #7
0
        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;
        }
コード例 #8
0
        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);
        }