Esempio n. 1
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!");

            }
        }
Esempio n. 2
0
        private void initializePilotJoystickListener(JoystickStateStore stateStore)
        {
            MainPacketBuilder mainPacketBuilder = new MainPacketBuilder(pilotJoystick);
            pilotStickListener = new JoystickStateListener(pilotJoystick,
                mainPacketBuilder, stateStore);

            RunInBackgroundThread(pilotStickListener.Listen);
        }
        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);
        }