Ejemplo n.º 1
0
        public static ComAutomation GetInstance()
        {
            if (instance == null)
            {
                var lck = new object();

                lock (lck) {
                    var t = new Thread(() => {
                        instance = new ComAutomation();

                        lock (lck)
                            Monitor.Pulse(lck);

                        instance.dispatchLoop();
                    });
                    t.Name         = "ComEventsDispatcher";
                    t.IsBackground = true;
                    t.Start();


                    Monitor.Wait(lck);
                }
            }

            return(instance);
        }
Ejemplo n.º 2
0
        public MainForm(string[] args)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            // lock width
            MaximumSize = new Size(Size.Width, 10000);
            MinimumSize = new Size(Size.Width, Size.Height);

            Instance = this;

            Channels = new int[256];

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionWindows"));
                break;

            case PlatformID.Unix:
                vJoyEnumerator = (VJoyCollectionBase)Activator.CreateInstance(Type.GetType("vJoySerialFeeder.VJoyCollectionLinux"));
                break;

            default:
                ErrorMessageBox("Unsupported platform", "Fatal");
                Application.Exit();
                break;
            }

            comboPorts.FormattingEnabled = true;
            comboPorts.Format           += (o, e) =>
            {
                // strip /dev/ on Linux, to be more compact
                e.Value = e.Value.ToString().Replace("/dev/", "");
            };
            reloadComPorts();
            reloadJoysticks();
            ChannelDataUpdate += onChannelDataUpdate;

            config = Configuration.Load();

            reloadProfiles();

            var defaultProfile = config.GetProfile(config.DefaultProfile);

            if (defaultProfile == null && comboProfiles.Items.Count > 0)
            {
                var first = comboProfiles.Items[0].ToString();
                defaultProfile     = config.GetProfile(first);
                comboProfiles.Text = first;
            }

            if (defaultProfile != null)
            {
                comboProfiles.Text = config.DefaultProfile;
                loadProfile(defaultProfile);
            }
            else
            {
                resetProfile();
            }

            toolStripStatusLabel.Text = "Disconnected";

            // initialize COM on windows platforms
            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                comAutomation = ComAutomation.GetInstance();
            }

            if (System.Environment.OSVersion.Platform != PlatformID.Win32NT)
            {
                // hide the Game Controllers shortcut on non-windows platforms
                menuGameControllers.Visible = false;
            }

            reloadGlobalOptions();

            // autoconnect
            if (config.Autoconnect)
            {
                connect();
            }
        }