Exemple #1
0
 private void Remove()
 {
     if (this.vjoyDevice != null)
     {
         this.vjoyDevice.RemoveRemoteController(this);
     }
     this.vjoyDevice = null;
 }
 private void VjoyServerControl_Load(object sender, EventArgs e)
 {
     this.vjoyDevice = Program.VjoyInterface.GetDevice(VjoyDeviceId);
     this.vjoyDevice.StatusChanged   += VjoyDevice_StatusChanged;
     this.vjoyDevice.ExportedChanged += VjoyDevice_StatusChanged;
     this.vjoyDeviceLabel.Text        = string.Format("vJoy #{0}", VjoyDeviceId);
     UpdateVjoyDeviceStatus();
 }
Exemple #3
0
        private void VjoyDevice_StatusChanged(object sender, EventArgs e)
        {
            VjoyDevice vjoyDevice = (VjoyDevice)sender;
            uint       id         = vjoyDevice.GetVjoyDeviceId();
            string     status     = GetJoystickStatus(vjoyDevice);
            string     msg        = string.Format("/set_var JOYSTICK_STATUS/{0} '{1}'\n", id, status);

            Send(msg);
        }
Exemple #4
0
        private void VjoyDevice_StatusChanged(object sender, EventArgs e)
        {
            VjoyDevice vjoyDevice   = (VjoyDevice)sender;
            uint       vjoyDeviceId = vjoyDevice.GetVjoyDeviceId();
            string     status       = GetJoystickStatus(vjoyDevice);
            string     msg          = string.Format("vjoy_status {0} {1}\n", vjoyDeviceId, status);

            Send(msg);
        }
Exemple #5
0
        private void ProcessLogMsg(string level, string source, string content)
        {
            string[] source_nodes = source.Split(new char[] { '/' });
            if (source == "vrchost/vrc")
            {
                string[] words = content.Split(new char[] { ' ' });
                if (words.Length == 2 && words[0] == "joystick_request")
                {
                    uint id = uint.Parse(words[1]);
                    if (id == 0)
                    {
                        if (this.vjoyDevice != null)
                        {
                            this.vjoyDevice.RemoveRemoteController(this);
                        }
                        this.vjoyDevice = null;
                    }
                    else
                    {
                        VjoyDevice oldVjoyDevice = this.vjoyDevice;
                        this.vjoyDevice = Program.VjoyInterface.GetDevice(id);
                        if (this.vjoyDevice == null)
                        {
                            return;
                        }
                        if (this.vjoyDevice.AddRemoteController(this) == false)
                        {
                            return;
                        }
                        if (oldVjoyDevice != null)
                        {
                            oldVjoyDevice.RemoveRemoteController(this);
                        }
                    }
                    string cmd = string.Format("/set_var ACTIVE_JOYSTICK_ID '{0}'\n", id);
                    Send(cmd);
                }
            }

            /*
             * else if (this.activeGui == Gui.JoystickScreen
             * && source.EndsWith("vrc")
             * && content == "joystick disabled")
             * {
             *  if (this.vjoyDevice == null)
             *      return;
             *  this.vjoyDevice.RemoveRemoteController(this);
             *  string cmd = string.Format("/set_var ACTIVE_JOYSTICK_ID '{0}'\n", 0);
             *  Send(cmd);
             *  this.activeGui = Gui.OptionsScreen;
             * }
             */
        }
Exemple #6
0
 public VRC(IPAddress address, int tcpPort)
 {
     this.tcpClient     = new TcpClient();
     this.address       = address;
     this.tcpPort       = tcpPort;
     this.controllerId  = -1;
     this.vjoyDevice    = null;
     this.activeGui     = Gui.None;
     this.joystickState = new JoystickState();
     this.setupThread   = new Thread(SetupThread);
     this.setupThread.Start();
     this.sendLock = new Object();
 }
Exemple #7
0
        private string GetJoystickStatus(VjoyDevice vjoyDevice)
        {
            string status = "";

            if (vjoyDevice.IsExported())
            {
                switch (vjoyDevice.GetStatus())
                {
                case VjoyDevice.Status.Acquired:
                case VjoyDevice.Status.Busy:
                    status = "taken"; break;

                case VjoyDevice.Status.Free:
                    status = "free"; break;
                }
            }
            return(status);
        }
Exemple #8
0
        public VjoyClient(TcpClient tcpClient)
        {
            this.clientAddress = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address;
            this.clientId      = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Port;
            this.tcpClient     = tcpClient;
            this.sendLock      = new Object();
            this.controllers   = new VjoyController[16];
            for (uint i = 0; i < 16; i++)
            {
                VjoyController controller           = new VjoyController();
                VjoyDevice     device               = Program.VjoyInterface.GetDevice(i + 1);
                device.GetConfig().PropertyChanged += VjoyDeviceConfig_PropertyChanged;
                device.AddRemoteController(controller);
                this.controllers[i] = controller;
            }

            //this.setupThread = new Thread(SetupThread);
            //this.setupThread.Start();
            string lines = "";

            lines += string.Format("init {0} {1} {2}\n", Environment.MachineName,
                                   Program.NetworkInterface.GetUdpPort(), this.clientId);
            VjoyDevice[] vjoyDevices = Program.VjoyInterface.GetDevices();
            foreach (VjoyDevice vjoyDevice in vjoyDevices)
            {
                vjoyDevice.StatusChanged   += VjoyDevice_StatusChanged;
                vjoyDevice.ExportedChanged += VjoyDevice_StatusChanged;
                uint   id     = vjoyDevice.GetVjoyDeviceId();
                string status = GetJoystickStatus(vjoyDevice);
                lines += string.Format("vjoy_status {0} {1}\n", id, status);
                foreach (string prop in vjoyDevice.GetConfig().GetProperties())
                {
                    lines += string.Format("vjoy_config {0} {1}\n", id, prop);
                }
            }
            Send(lines);
        }