Inheritance: System.Windows.Forms.UserControl
コード例 #1
0
ファイル: LiveTelemetry.cs プロジェクト: llenroc/SimTelemetry
        /// <summary>
        /// Initializes for the window. This setups the data back-end framework, as well searches for joystick
        /// configuration. Set-ups interface controls.
        /// </summary>
        public LiveTelemetry()
        {
            // Use EN-US for compatibility with functions as Convert.ToDouble etc.
            // This is mainly used within track parsers.
            Application.CurrentCulture = new CultureInfo("en-US");

            if (false)
            {
                TelemetryViewer t = new TelemetryViewer();
                t.ShowDialog();
                return;
            }

            // Boot up the telemetry service. Wait for it to start and register events that trigger interface changes.
            Telemetry.m.Run();
            while (Telemetry.m.Sims == null)
            {
                System.Threading.Thread.Sleep(1);
            }
            Telemetry.m.Sim_Start     += mUpdateUI;
            Telemetry.m.Sim_Stop      += mUpdateUI;
            Telemetry.m.Session_Start += mUpdateUI;
            Telemetry.m.Session_Stop  += mUpdateUI;

            System.Threading.Thread.Sleep(500);
            if (Telemetry.m.Sim != null)
            {
                Telemetry.m.Sim.Garage.Scan();
            }

            // TODO: Detect hardware devices (COM-ports or USB devices)
            // GameData is used for my own hardware extension projects.
            // Race dashboard:
            // https://dl.dropbox.com/u/207647/IMAG0924.jpg
            // https://dl.dropbox.com/u/207647/IMAG1204.jpg
            // Switchboard:
            // https://dl.dropbox.com/u/207647/IMAG0928.jpg
            // https://dl.dropbox.com/u/207647/IMAG0934.jpg
            //GameData g = new GameData();

            // Form of singleton for public StatusMenu access.
            _liveTelemetry = this;

            // Read joystick configuration.
            if (File.Exists("config.txt") == false)
            {
                // TODO: Needs fancy dialogs to first-time setup.
                File.Create("config.txt");
                MessageBox.Show(
                    "Please edit config.txt:\r\ncontroller=[your controller you want to use for cyclign through panels]\r\nbutton=[the button on the controller you want to use]\r\n\r\nJust type the name of your controller (G25 alone is enough usually) and look up the button in Devices -> Game Controllers.");
            }
            else
            {
                string[] lines              = File.ReadAllLines("config.txt");
                string   controller         = "";
                bool     controlleruseindex = false;
                int      controllerindex    = 0;
                foreach (string line in lines)
                {
                    string[] p = line.Trim().Split("=".ToCharArray());
                    if (line.StartsWith("button"))
                    {
                        Joystick_Button = Convert.ToInt32(p[1]);
                    }
                    if (line.StartsWith("index"))
                    {
                        controlleruseindex = true;
                        controllerindex    = Convert.ToInt32(p[1]);
                    }
                    if (line.StartsWith("controller"))
                    {
                        controller = p[1];
                    }
                }

                // Search for the joystick.
                List <JoystickDevice> devices = JoystickDevice.Search();
                if (devices.Count == 0)
                {
                    //MessageBox.Show("No (connected) joystick found for display panel control.\r\nTo utilize this please connect a joystick, configure and restart this program.");
                }
                else
                {
                    if (controlleruseindex)
                    {
                        Joystick_Instance          = new Joystick(devices[controllerindex]);
                        Joystick_Instance.Release += Joy_Release;
                    }
                    else
                    {
                        int i = 0;
                        foreach (JoystickDevice jd in devices)
                        {
                            if (jd.Name.Contains(controller.Trim()))
                            {
                                Joystick_Instance          = new Joystick(jd);
                                Joystick_Instance.Release += Joy_Release;
                            }
                            i++;
                        }
                    }
                }
            }

            // Set-up the main interface.
            FormClosing += LiveTelemetry_FormClosing;
            SizeChanged += Telemetry_ResizePanels;

            InitializeComponent();

            this.SuspendLayout();
            BackColor     = Color.Black;
            ucLaps        = new Gauge_Laps();
            ucSplits      = new Gauge_Splits();
            ucA1GP        = new Gauge_A1GP(Joystick_Instance);
            ucTyres       = new Gauge_Tyres();
            ucSessionData = new ucSessionInfo();
            ucTrackmap    = new LiveTrackMap();
            ucLapChart    = new LapChart();
            btGarage      = new Button();
            btNetwork     = new Button();
            btSettings    = new Button();

            // Garage button
            btGarage.Text      = "Garage";
            btGarage.Size      = new Size(75, 25);
            btGarage.BackColor = Color.White;
            btGarage.Location  = new Point(10, 10);
            btGarage.Click    += new EventHandler(btGarage_Click);

            // Settings button
            btSettings.Text      = "Settings";
            btSettings.Size      = new Size(75, 25);
            btSettings.BackColor = Color.White;
            btSettings.Location  = new Point(95, 10);
            btSettings.Click    += new EventHandler(btSettings_Click);

            // Network
            btNetwork.Text      = "Network";
            btNetwork.Size      = new Size(75, 25);
            btNetwork.BackColor = Color.White;
            btNetwork.Location  = new Point(180, 10);
            btNetwork.Click    += new EventHandler(btNetwork_Click);

            // Timers
            Tmr_HiSpeed = new Timer {
                Interval = 20
            };                                    // 30fps
            Tmr_MdSpeed = new Timer {
                Interval = 450
            };                                       // ~2fps
            Tmr_LwSpeed = new Timer {
                Interval = 1000
            };                                      // 1fps

            Tmr_HiSpeed.Tick += Tmr_HiSpeed_Tick;
            Tmr_MdSpeed.Tick += Tmr_MdSpeed_Tick;
            Tmr_LwSpeed.Tick += Tmr_LwSpeed_Tick;

            Tmr_HiSpeed.Start();
            Tmr_MdSpeed.Start();
            Tmr_LwSpeed.Start();

            System.Threading.Thread.Sleep(500);
#if DEBUG
            // This is for hardware peripheral support
            new GameData();
#endif
            SetupUI();
            this.ResumeLayout(false);
        }
コード例 #2
0
ファイル: LiveTelemetry.cs プロジェクト: nlhans/SimTelemetry
        /// <summary>
        /// Initializes for the window. This setups the data back-end framework, as well searches for joystick
        /// configuration. Set-ups interface controls.
        /// </summary>
        public LiveTelemetry()
        {
            // Use EN-US for compatibility with functions as Convert.ToDouble etc.
            // This is mainly used within track parsers.
            Application.CurrentCulture = new CultureInfo("en-US");

            if(false)
            {
                TelemetryViewer t = new TelemetryViewer();
                t.ShowDialog();
                return;
            }

            // Boot up the telemetry service. Wait for it to start and register events that trigger interface changes.
            Telemetry.m.Run();
            while (Telemetry.m.Sims == null) System.Threading.Thread.Sleep(1);
            Telemetry.m.Sim_Start += mUpdateUI;
            Telemetry.m.Sim_Stop += mUpdateUI;
            Telemetry.m.Session_Start += mUpdateUI;
            Telemetry.m.Session_Stop += mUpdateUI;

            System.Threading.Thread.Sleep(500);
            if (Telemetry.m.Sim != null)
                Telemetry.m.Sim.Garage.Scan();

            // TODO: Detect hardware devices (COM-ports or USB devices)
            // GameData is used for my own hardware extension projects.
            // Race dashboard:
            // https://dl.dropbox.com/u/207647/IMAG0924.jpg
            // https://dl.dropbox.com/u/207647/IMAG1204.jpg
            // Switchboard:
            // https://dl.dropbox.com/u/207647/IMAG0928.jpg
            // https://dl.dropbox.com/u/207647/IMAG0934.jpg
            //GameData g = new GameData();

            // Form of singleton for public StatusMenu access.
            _liveTelemetry = this;

            // Read joystick configuration.
            if(File.Exists("config.txt") == false)
            {
                // TODO: Needs fancy dialogs to first-time setup.
                File.Create("config.txt");
                MessageBox.Show(
                    "Please edit config.txt:\r\ncontroller=[your controller you want to use for cyclign through panels]\r\nbutton=[the button on the controller you want to use]\r\n\r\nJust type the name of your controller (G25 alone is enough usually) and look up the button in Devices -> Game Controllers.");
            }else
            {
                string[] lines = File.ReadAllLines("config.txt");
                string controller = "";
                bool controlleruseindex = false;
                int controllerindex = 0;
                foreach (string line in lines)
                {
                    string[] p = line.Trim().Split("=".ToCharArray());
                    if (line.StartsWith("button")) Joystick_Button = Convert.ToInt32(p[1]);
                    if (line.StartsWith("index"))
                    {
                        controlleruseindex = true;
                        controllerindex = Convert.ToInt32(p[1]);
                    }
                    if (line.StartsWith("controller"))
                        controller = p[1];

                }

                // Search for the joystick.
                List<JoystickDevice> devices = JoystickDevice.Search();
                if (devices.Count == 0)
                {
                    //MessageBox.Show("No (connected) joystick found for display panel control.\r\nTo utilize this please connect a joystick, configure and restart this program.");
                }
                else
                {
                    if (controlleruseindex)
                    {
                        Joystick_Instance = new Joystick(devices[controllerindex]);
                        Joystick_Instance.Release += Joy_Release;
                    }
                    else
                    {
                        int i = 0;
                        foreach (JoystickDevice jd in devices)
                        {
                            if (jd.Name.Contains(controller.Trim()))
                            {
                                Joystick_Instance = new Joystick(jd);
                                Joystick_Instance.Release += Joy_Release;
                            }
                            i++;
                        }
                    }
                }
            }

            // Set-up the main interface.
            FormClosing += LiveTelemetry_FormClosing;
            SizeChanged += Telemetry_ResizePanels;

            InitializeComponent();

            this.SuspendLayout();
            BackColor = Color.Black;
            ucLaps = new Gauge_Laps();
            ucSplits = new Gauge_Splits();
            ucA1GP = new Gauge_A1GP(Joystick_Instance);
            ucTyres = new Gauge_Tyres();
            ucSessionData = new ucSessionInfo();
            ucTrackmap = new LiveTrackMap();
            ucLapChart = new LapChart();
            btGarage = new Button();
            btNetwork = new Button();
            btSettings = new Button();

            // Garage button
            btGarage.Text = "Garage";
            btGarage.Size = new Size(75, 25);
            btGarage.BackColor = Color.White;
            btGarage.Location = new Point(10, 10);
            btGarage.Click += new EventHandler(btGarage_Click);

            // Settings button
            btSettings.Text = "Settings";
            btSettings.Size = new Size(75, 25);
            btSettings.BackColor = Color.White;
            btSettings.Location = new Point(95, 10);
            btSettings.Click += new EventHandler(btSettings_Click);

            // Network
            btNetwork.Text = "Network";
            btNetwork.Size = new Size(75, 25);
            btNetwork.BackColor = Color.White;
            btNetwork.Location = new Point(180, 10);
            btNetwork.Click += new EventHandler(btNetwork_Click);

            // Timers
            Tmr_HiSpeed = new Timer{Interval=20}; // 30fps
            Tmr_MdSpeed = new Timer{Interval = 450}; // ~2fps
            Tmr_LwSpeed = new Timer{Interval=1000}; // 1fps

            Tmr_HiSpeed.Tick += Tmr_HiSpeed_Tick;
            Tmr_MdSpeed.Tick += Tmr_MdSpeed_Tick;
            Tmr_LwSpeed.Tick += Tmr_LwSpeed_Tick;

            Tmr_HiSpeed.Start();
            Tmr_MdSpeed.Start();
            Tmr_LwSpeed.Start();

            System.Threading.Thread.Sleep(500);
            #if DEBUG
            // This is for hardware peripheral support
            new GameData();
            #endif
            SetupUI();
            this.ResumeLayout(false);
        }