Example #1
0
 private void initializeCommunicationServer(JoystickStateStore stateStore)
 {
     ICommunicationServer comServer = new CommunicationServer(stateStore);
     RunInBackgroundThread(comServer.Serve);
     new RovStateReceivedHandler(comServer, (IPilotViewHandler)pilotView, (ICoPilotViewHandler)coPilotView);
 }
        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);
        }