Ejemplo n.º 1
0
        public iRacingSLI()
        {
            InitializeComponent();
            this.Text = "iRacing SLI v" + Version;
            cfg = new configHandler(console);
            connection = new connectionHelper(console);
            connection.setupConnection(startConnection, cboPorts, cfg);
            brk = new brakeVibe();

            int top = Convert.ToInt16(cfg.readSetting("Top", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Top", "100")) : 100;
            int left = Convert.ToInt16(cfg.readSetting("Left", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Left", "100")) : 100;
            this.SetDesktopLocation(top, left);
            this.cboSpdUnit.SelectedIndex = Convert.ToInt16(cfg.readSetting("spdUnit", "0"));
            this.trkIntensity.Value = Convert.ToInt16(cfg.readSetting("intensity", "0"));
            this.chkTelem.Checked = Convert.ToBoolean(cfg.readSetting("telemEnable", "True"));
            this.chkBrake.Checked = Convert.ToBoolean(cfg.readSetting("brakeEnable", "False"));
            this.groupBox1.Enabled = this.chkBrake.Checked;
            this.trkTol.Value = Convert.ToInt16(cfg.readSetting("brakeTol", "35"));
            this.trkSens.Value = Convert.ToInt16(cfg.readSetting("brakeSens", "3"));

            console("Start iRacingSDK Wrapper");
            wrapper = new SdkWrapper();
            wrapper.EventRaiseType = SdkWrapper.EventRaiseTypes.CurrentThread;
            wrapper.TelemetryUpdateFrequency = 20;

            wrapper.Connected += wrapper_Connected;
            wrapper.Disconnected += wrapper_Disconnected;
            wrapper.SessionInfoUpdated += wrapper_SessionInfoUpdated;
            wrapper.TelemetryUpdated += wrapper_TelemetryUpdated;

            wrapper.Start();
            ticker = 39;
            prevLapTime = 0;
        }
Ejemplo n.º 2
0
 // Event handler called when the session info is updated
 private void wrapper_SessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
 {
     if (!hasInit)
     {
         hasInit  = true;
         track    = e.SessionInfo["WeekendInfo"]["TrackName"].Value;
         driverID = Convert.ToInt16(e.SessionInfo["DriverInfo"]["DriverCarIdx"].Value);
         car      = e.SessionInfo["DriverInfo"]["Drivers"]["CarIdx", driverID]["CarPath"].Value;
         fuelEst  = Convert.ToDouble(cfg.readSetting(track + "-" + car, "0"));
         fuelLaps = Convert.ToInt32(cfg.readSetting(track + "-" + car + "-l", "0"));
     }
 }
Ejemplo n.º 3
0
        public iRacingSLI()
        {
            InitializeComponent();
            this.Text  = "iRacing SLI v" + Version;
            cfg        = new configHandler(console);
            connection = new connectionHelper(console);
            connection.setupConnection(startConnection, cboPorts, cfg);
            brk = new brakeVibe();

            int top  = Convert.ToInt16(cfg.readSetting("Top", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Top", "100")) : 100;
            int left = Convert.ToInt16(cfg.readSetting("Left", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Left", "100")) : 100;

            this.SetDesktopLocation(top, left);
            this.cboSpdUnit.SelectedIndex = Convert.ToInt16(cfg.readSetting("spdUnit", "0"));
            this.trkIntensity.Value       = Convert.ToInt16(cfg.readSetting("intensity", "0"));
            this.chkTelem.Checked         = Convert.ToBoolean(cfg.readSetting("telemEnable", "True"));
            this.chkBrake.Checked         = Convert.ToBoolean(cfg.readSetting("brakeEnable", "False"));
            this.groupBox1.Enabled        = this.chkBrake.Checked;
            this.trkTol.Value             = Convert.ToInt16(cfg.readSetting("brakeTol", "35"));
            this.trkSens.Value            = Convert.ToInt16(cfg.readSetting("brakeSens", "3"));

            console("Start iRacingSDK Wrapper");
            wrapper = new SdkWrapper();
            wrapper.EventRaiseType           = SdkWrapper.EventRaiseTypes.CurrentThread;
            wrapper.TelemetryUpdateFrequency = 20;

            wrapper.Connected          += wrapper_Connected;
            wrapper.Disconnected       += wrapper_Disconnected;
            wrapper.SessionInfoUpdated += wrapper_SessionInfoUpdated;
            wrapper.TelemetryUpdated   += wrapper_TelemetryUpdated;

            wrapper.Start();
            ticker      = 39;
            prevLapTime = 0;
        }
Ejemplo n.º 4
0
        public void setupConnection(Action <String> startMethod, System.Windows.Forms.ComboBox cbo, configHandler cfg)
        {
            Object[] arrayPorts = null;
            int      startPort  = -1;
            String   setting    = cfg.readSetting("Port", "*");

            using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
            {
                string[] portnames = SerialPort.GetPortNames();
                var      ports     = searcher.Get().Cast <ManagementBaseObject>().ToList();
                arrayPorts = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select p["Caption"]).ToArray();
            }
            cbo.Items.AddRange(arrayPorts);

            if (setting != "*")
            {
                for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                {
                    if (SerialPort.GetPortNames()[j].Equals(setting))
                    {
                        try
                        {
                            startMethod(setting);
                            startPort = j;
                        }
                        catch {
                            cfg.writeSetting("Port", "*");
                        }
                    }
                }
                if (startPort == -1)
                {
                    cfg.writeSetting("Port", "*");
                }
            }
            else
            {
                for (int i = 0; i < cbo.Items.Count; i++)
                {
                    if (cbo.Items[i].ToString().Contains("Arduino"))
                    {
                        String port = Regex.Match(cbo.Items[i].ToString(), @"\(([^)]*)\)").Groups[1].Value;
                        console("Found Arduino On Port: " + port);
                        startMethod(port);

                        for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                        {
                            if (SerialPort.GetPortNames()[j].Equals(port))
                            {
                                startPort = j;
                            }
                        }

                        break;
                    }
                }
            }
            cbo.SelectedIndex = startPort;
        }
Ejemplo n.º 5
0
 // Event handler called when the session info is updated
 private void wrapper_SessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
 {
     if (!hasInit)
     {
         try
         {
             hasInit  = true;
             track    = e.SessionInfo["WeekendInfo"]["TrackName"].Value;
             driverID = Convert.ToInt16(e.SessionInfo["DriverInfo"]["DriverCarIdx"].Value);
             car      = e.SessionInfo["DriverInfo"]["Drivers"]["CarIdx", driverID]["CarPath"].Value;
             fuelEst  = Convert.ToDouble(cfg.readSetting(track + "-" + car, "0"));
             fuelLaps = Convert.ToInt32(cfg.readSetting(track + "-" + car + "-l", "0"));
             console("Load data for " + car + " at " + track);
         }
         catch (Exception exe)
         {
             ExceptionHelper.writeToLogFile(exe.Message, exe.ToString(), "Update Session Data", exe.LineNumber(), this.FindForm().Name);
         }
     }
 }
Ejemplo n.º 6
0
        public iRacingSLI()
        {
            try
            {
                InitializeComponent();
                this.Text  = "iRacing SLI v" + Version;
                cfg        = new configHandler(console);
                connection = new connectionHelper(console);
                connection.setupConnection(startConnection, cboPorts, cfg);

                int top  = Convert.ToInt16(cfg.readSetting("Top", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Top", "100")) : 100;
                int left = Convert.ToInt16(cfg.readSetting("Left", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Left", "100")) : 100;
                this.SetDesktopLocation(top, left);
                this.cboSpdUnit.SelectedIndex = Convert.ToInt16(cfg.readSetting("spdUnit", "0"));
                this.trkIntensity.Value       = Convert.ToInt16(cfg.readSetting("intensity", "0"));
                this.chkTelem.Checked         = Convert.ToBoolean(cfg.readSetting("telemEnable", "True"));

                console("Start iRacingSDK Wrapper");
                wrapper = new SdkWrapper();
                wrapper.EventRaiseType           = SdkWrapper.EventRaiseTypes.CurrentThread;
                wrapper.TelemetryUpdateFrequency = 20;
                //wrapper.ConnectSleepTime = 1;

                wrapper.Connected          += wrapper_Connected;
                wrapper.Disconnected       += wrapper_Disconnected;
                wrapper.SessionInfoUpdated += wrapper_SessionInfoUpdated;
                wrapper.TelemetryUpdated   += wrapper_TelemetryUpdated;

                wrapper.Start();
                ticker      = 39;
                prevLapTime = 0;
            }
            catch (Exception exe)
            {
                ExceptionHelper.writeToLogFile(exe.Message, exe.ToString(), "Constructor", exe.LineNumber(), this.FindForm().Name);
            }
        }
        public iRacingSLI()
        {
            try
            {
                InitializeComponent();
                this.Text = "iRacing SLI v" + Version;
                cfg = new configHandler(console);
                connection = new connectionHelper(console);
                connection.setupConnection(startConnection, cboPorts, cfg);

                int top = Convert.ToInt16(cfg.readSetting("Top", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Top", "100")) : 100;
                int left = Convert.ToInt16(cfg.readSetting("Left", "100")) > -3000 ? Convert.ToInt16(cfg.readSetting("Left", "100")) : 100;
                this.SetDesktopLocation(top, left);
                this.cboSpdUnit.SelectedIndex = Convert.ToInt16(cfg.readSetting("spdUnit", "0"));
                this.trkIntensity.Value = Convert.ToInt16(cfg.readSetting("intensity", "0"));
                this.chkTelem.Checked = Convert.ToBoolean(cfg.readSetting("telemEnable", "True"));

                console("Start iRacingSDK Wrapper");
                wrapper = new SdkWrapper();
                wrapper.EventRaiseType = SdkWrapper.EventRaiseTypes.CurrentThread;
                wrapper.TelemetryUpdateFrequency = 20;
                //wrapper.ConnectSleepTime = 1;

                wrapper.Connected += wrapper_Connected;
                wrapper.Disconnected += wrapper_Disconnected;
                wrapper.SessionInfoUpdated += wrapper_SessionInfoUpdated;
                wrapper.TelemetryUpdated += wrapper_TelemetryUpdated;

                wrapper.Start();
                ticker = 39;
                prevLapTime = 0;
            }
            catch (Exception exe)
            {
                ExceptionHelper.writeToLogFile(exe.Message, exe.ToString(), "Constructor", exe.LineNumber(), this.FindForm().Name);
            }
        }
        public void setupConnection(Action<String> startMethod, System.Windows.Forms.ComboBox cbo, configHandler cfg)
        {
            Object[] arrayPorts = null;
            int startPort = -1;
            String setting = cfg.readSetting("Port", "*");
            using (var searcher = new ManagementObjectSearcher("SELECT * FROM WIN32_SerialPort"))
            {
                string[] portnames = SerialPort.GetPortNames();
                var ports = searcher.Get().Cast<ManagementBaseObject>().ToList();
                arrayPorts = (from n in portnames join p in ports on n equals p["DeviceID"].ToString() select p["Caption"]).ToArray();
            }
            cbo.Items.Add("Local");
            cbo.Items.AddRange(arrayPorts);

            if (setting != "*")
            {
                if (setting == "Local")
                {
                    startMethod(setting);
                }
                else
                {
                    for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                    {
                        if (SerialPort.GetPortNames()[j].Equals(setting))
                        {
                            try
                            {
                                startMethod(setting);
                                startPort = j;
                            }
                            catch
                            {
                                cfg.writeSetting("Port", "*");
                            }
                        }
                    }
                    if (startPort == -1)
                        cfg.writeSetting("Port", "*");
                }
            }
            else
            {
                for (int i = 0; i < cbo.Items.Count; i++)
                {
                    if (cbo.Items[i].ToString().Contains("Arduino"))
                    {
                        String port = Regex.Match(cbo.Items[i].ToString(), @"\(([^)]*)\)").Groups[1].Value;
                        console("Found Arduino On Port: " + port);
                        startMethod(port);

                        for (int j = 0; j < SerialPort.GetPortNames().Length; j++)
                        {
                            if (SerialPort.GetPortNames()[j].Equals(port))
                                startPort = j;
                        }

                        break;
                    }
                }
            }
            cbo.SelectedIndex = startPort + 1;
        }