public Configuration SaveConfiguration(Dictionarys dicts)
        {
            var returnConf = new Configuration
                                 {
                                         Name = Name,
                                         FileLocation = FileLocation,
                                         DisplayConfigurations = new List<DisplayConfiguration>(),
                                         ControllerConfigurations = new List<ControllerConfiguration>(),
                                         TMDisplaySettings =
                                                 new TMDisplaySettings
                                                     {
                                                             ColourDeltaByDD = this.ColourDeltaByDD,
                                                             ShiftIntensity = this.ShiftIntensity,
                                                             Intensity = this.Intensity,
                                                             ShiftIntensityType =
                                                                     this.ShiftIntensityType,
                                                             ShiftIntensityAmount =
                                                                     this.ShiftIntensityAmount,
                                                             ShowHeaders = this.ShowHeader,
                                                             HeaderDisplayTime =
                                                                     this.HeaderDisplayTime + 1,
                                                             QuickInfoDisplayTime =
                                                                     this.QuickInfoDisplayTime + 1,
                                                             LapDisplayTime =
                                                                     this.LapTimeDisplayTime + 1,
                                                             DeltaRange = this.DeltaRange + 1,
                                                             DeltaMessageScreen =
                                                                     this.DeltaMessageScreen,
                                                             DeltaLightsOnDefault =
                                                                     this.DeltaLightsOnDefault,
                                                             WarningTextDisplayTime = this.WarningTextDisplayTime + 1,
                                                             QuickInfoLightsColour = this.QuickInfoLightsColour
                                                     },
                                         SerialPortSettings =
                                                 new SerialPortConfiguration
                                                     {
                                                             PreferredComPort =
                                                                     this
                                                                     .PreferredComPort,
                                                             SerialPortSpeed =
                                                                     AdvancedOptions
                                                                     .ParseSerialSpeedString
                                                                     (
                                                                             this
                                                                     .SerialPortSpeed),
                                                             UseCustomSerialSpeed =
                                                                     this
                                                                     .UseCustomSerialSpeed
                                                     },
                                         OtherSettings =
                                                 new OtherSettings
                                                     {
                                                             FuelCalculationLaps =
                                                                     this.FuelCalculationLaps + 2,
                                                             UseCustomFuelCalculationOptions =
                                                                     this
                                                                     .UseCustomFuelCalculationOptions,
                                                             UseWeightedFuelCalculations =
                                                                     this
                                                                     .UseWeightedFuelCalculations
                                                     },
                                         RefreshRates =
                                                 new RefreshRates
                                                     {
                                                             DisplayRefreshRate =
                                                                     AdvancedOptions
                                                                     .ParseRefreshRatesString(
                                                                             this
                                                                     .DisplayRefreshRate),
                                                             LEDRefreshRate =
                                                                     AdvancedOptions
                                                                     .ParseRefreshRatesString(
                                                                             this.LEDRefreshRate)
                                                     },
                                         AdvancedSettings =
                                                 new AdvancedSettings
                                                     {
                                                             LogArduinoMessages =
                                                                     this.LogArduinoMessages
                                                     }
                                 };
            if(returnConf.TMDisplaySettings.DeltaRange <= 0)
            {
                returnConf.TMDisplaySettings.DeltaRange = 1;
            }
            if (!UseCustomSerialSpeed) //Calculate and Auto Set Serial Speed
            {
                int numberTM1638 = 0;
                int numberTM1640 = 0;
                foreach (var unit in DisplayUnitConfigurations)
                {
                    if (unit.IsTM1640)
                    {
                        numberTM1640++;

                    }
                    else
                    {
                        numberTM1638++;
                    }

                }
                returnConf.SerialPortSettings.SerialPortSpeed = AdvancedOptions.CalculateRecommendSerialSpeed(
                returnConf.RefreshRates.DisplayRefreshRate,returnConf.RefreshRates.LEDRefreshRate, numberTM1638, numberTM1640);
            }
            //int controllerCount = 0;
            foreach (ControllerButtonConfiguration item in ControllerConfigurations)
            {
                var temp = new ControllerConfiguration();
                for (int y = 0; y < Constants.MaxNumberJoystickButtons; y++)
                {
                    var butFuncTemp = ButtonFunctionsEnum.None;

                    foreach (var butFunc in dicts.ButtonFunctions)
                    {
                        if (butFunc.Value.Name == item.ButtonFunctions[y])
                        {
                            butFuncTemp = butFunc.Key;
                        }
                    }
                    temp.ButtonFunctions[y] = butFuncTemp;
                    temp.ButtonOptions[y] = item.ButtonOptions[y];
                    temp.ButtonOptionsScreens[y] = item.ButtonOptionsScreens[y];
                    temp.ButtonNumbers[y] = item.ButtonNumbers[y];
                    temp.DeviceGuid = item.DeviceGuid;
                    temp.Selected = item.Selected;
                }
                //controllerCount++;
                returnConf.ControllerConfigurations.Add(temp);
            }
            returnConf.NumberControllers = returnConf.ControllerConfigurations.Count;
            foreach (DisplayUnitConfiguration displayConf in DisplayUnitConfigurations)
            {
                var temp = new DisplayConfiguration(false)
                    {
                        NumScreens = displayConf.NumScreens + 1,
                        Inverted = displayConf.Inverted,
                        IsTM1640 = displayConf.IsTM1640,
                        SwitchLEDs = displayConf.SwitchLEDs,
                        ShowDC = displayConf.ShowDC,
                        DCDisplayTime = displayConf.DCDisplayTime,
                        ShowLap = displayConf.ShowLap,
                        FFBClippingLights = displayConf.LEDsConfigurations.FFBClippingLights,
                        FFBClippingScreen = displayConf.LEDsConfigurations.FFBClippingScreen + 1,
                        PitLights = displayConf.LEDsConfigurations.PitLights,
                        ShiftClumps = displayConf.LEDsConfigurations.ShiftClumps,
                        RevLimiterLights = displayConf.LEDsConfigurations.RevLimiterLights,
                        ShowShiftLights = displayConf.LEDsConfigurations.ShowShiftLights,
                        DeltaLightsShow = displayConf.LEDsConfigurations.DeltaLightsShow,
                        ShowEngineWarnings = displayConf.ShowEngineWarnings
                    };
                List<Screen> screenTemp = displayConf.Screens;
                foreach (Screen screen in screenTemp)
                {
                    int place = 0;
                    while (place < screen.Variables.Count)
                    {
                        if (screen.Variables[place] == null || screen.Variables[place] == "")
                        {
                            screen.Variables.RemoveAt(place);
                        }
                        else
                        {
                            place++;
                        }
                    }
                    if (screen.Variables.Count == 0)
                    {
                        screen.Variables.Add("Space");
                    }
                }
                temp.Screens = displayConf.Screens;
                try
                {
                    temp.WarningType = dicts.WarningTypes[displayConf.WarningType];
                }
                catch
                {
                    Enum.TryParse(displayConf.WarningType, out temp.WarningType);
                }
                try
                {
                    temp.LapStyle = dicts.LapDisplayStyles[displayConf.LapStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LapStyle, out temp.LapStyle);
                }
                try
                {
                    temp.PitLimiterStyle = dicts.PitFlashStyles[displayConf.LEDsConfigurations.PitLimiterStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.PitLimiterStyle, out temp.PitLimiterStyle);
                }
                try
                {
                    temp.PitLimiterSpeed = dicts.PitFlashSpeeds[displayConf.LEDsConfigurations.PitLimiterSpeed];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.PitLimiterSpeed, out temp.PitLimiterSpeed);
                }
                try
                {
                    temp.ShiftLightStyle = dicts.ShiftStyles[displayConf.LEDsConfigurations.ShiftLightStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.ShiftLightStyle, out temp.ShiftLightStyle);
                }
                try
                {
                    temp.RevLimiterStyle = dicts.RevFlashStyles[displayConf.LEDsConfigurations.RevLimiterStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.RevLimiterStyle, out temp.RevLimiterStyle);
                }
                temp.MatchCarShiftStyle = displayConf.LEDsConfigurations.MatchCarShiftLights;
                temp.MatchRedShift = displayConf.LEDsConfigurations.MatchRedShift;
                try
                {
                    temp.MatchCarShiftStyleOption =
                        dicts.MatchCarShiftOptions[displayConf.LEDsConfigurations.MatchCarShiftOptions];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.MatchCarShiftOptions, out temp.MatchCarShiftStyleOption);
                }
                temp.DeltaLightsShow = displayConf.LEDsConfigurations.DeltaLightsShow;
                try
                {
                    temp.DeltaLightsPosition =
                        dicts.DeltaLightsPositionOptions[displayConf.LEDsConfigurations.DeltaLightsPosition];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.DeltaLightsPosition, out temp.DeltaLightsPosition);
                }
                for (int y = 0; y < Constants.NumberButtonsOnTm1638; y++)
                {
                    var butFuncTemp = ButtonFunctionsEnum.None;

                    foreach (var butFunc in dicts.ButtonFunctions)
                    {
                        if (butFunc.Value.Name == displayConf.ButtonConfigurations.ButtonFunctions[y])
                        {
                            butFuncTemp = butFunc.Key;
                        }
                    }
                    temp.ButtonFunctions[y] = butFuncTemp;
                    temp.ButtonOptions[y] = displayConf.ButtonConfigurations.ButtonOptions[y];
                    temp.ButtonOptionsScreens[y] = displayConf.ButtonConfigurations.ButtonOptionsScreens[y];
                }
                returnConf.DisplayConfigurations.Add(temp);
            }
            return returnConf;
        }
Beispiel #2
0
        public Configuration SaveConfiguration(Dictionarys dicts)
        {
            var returnConf = new Configuration
            {
                Name                     = Name,
                FileLocation             = FileLocation,
                DisplayConfigurations    = new List <DisplayConfiguration>(),
                ControllerConfigurations = new List <ControllerConfiguration>(),
                TMDisplaySettings        =
                    new TMDisplaySettings
                {
                    ColourDeltaByDD    = this.ColourDeltaByDD,
                    ShiftIntensity     = this.ShiftIntensity,
                    Intensity          = this.Intensity,
                    ShiftIntensityType =
                        this.ShiftIntensityType,
                    ShiftIntensityAmount =
                        this.ShiftIntensityAmount,
                    ShowHeaders       = this.ShowHeader,
                    HeaderDisplayTime =
                        this.HeaderDisplayTime + 1,
                    QuickInfoDisplayTime =
                        this.QuickInfoDisplayTime + 1,
                    LapDisplayTime =
                        this.LapTimeDisplayTime + 1,
                    DeltaRange         = this.DeltaRange + 1,
                    DeltaMessageScreen =
                        this.DeltaMessageScreen,
                    DeltaLightsOnDefault =
                        this.DeltaLightsOnDefault,
                    WarningTextDisplayTime = this.WarningTextDisplayTime + 1,
                    QuickInfoLightsColour  = this.QuickInfoLightsColour
                },
                SerialPortSettings =
                    new SerialPortConfiguration
                {
                    PreferredComPort =
                        this
                        .PreferredComPort,
                    SerialPortSpeed =
                        AdvancedOptions
                        .ParseSerialSpeedString
                        (
                            this
                            .SerialPortSpeed),
                    UseCustomSerialSpeed =
                        this
                        .UseCustomSerialSpeed
                },
                OtherSettings =
                    new OtherSettings
                {
                    FuelCalculationLaps =
                        this.FuelCalculationLaps + 2,
                    UseCustomFuelCalculationOptions =
                        this
                        .UseCustomFuelCalculationOptions,
                    UseWeightedFuelCalculations =
                        this
                        .UseWeightedFuelCalculations
                },
                RefreshRates =
                    new RefreshRates
                {
                    DisplayRefreshRate =
                        AdvancedOptions
                        .ParseRefreshRatesString(
                            this
                            .DisplayRefreshRate),
                    LEDRefreshRate =
                        AdvancedOptions
                        .ParseRefreshRatesString(
                            this.LEDRefreshRate)
                },
                AdvancedSettings =
                    new AdvancedSettings
                {
                    LogArduinoMessages =
                        this.LogArduinoMessages
                }
            };

            if (returnConf.TMDisplaySettings.DeltaRange <= 0)
            {
                returnConf.TMDisplaySettings.DeltaRange = 1;
            }
            if (!UseCustomSerialSpeed) //Calculate and Auto Set Serial Speed
            {
                int numberTM1638 = 0;
                int numberTM1640 = 0;
                foreach (var unit in DisplayUnitConfigurations)
                {
                    if (unit.IsTM1640)
                    {
                        numberTM1640++;
                    }
                    else
                    {
                        numberTM1638++;
                    }
                }
                returnConf.SerialPortSettings.SerialPortSpeed = AdvancedOptions.CalculateRecommendSerialSpeed(
                    returnConf.RefreshRates.DisplayRefreshRate, returnConf.RefreshRates.LEDRefreshRate, numberTM1638, numberTM1640);
            }
            //int controllerCount = 0;
            foreach (ControllerButtonConfiguration item in ControllerConfigurations)
            {
                var temp = new ControllerConfiguration();
                for (int y = 0; y < Constants.MaxNumberJoystickButtons; y++)
                {
                    var butFuncTemp = ButtonFunctionsEnum.None;

                    foreach (var butFunc in dicts.ButtonFunctions)
                    {
                        if (butFunc.Value.Name == item.ButtonFunctions[y])
                        {
                            butFuncTemp = butFunc.Key;
                        }
                    }
                    temp.ButtonFunctions[y]      = butFuncTemp;
                    temp.ButtonOptions[y]        = item.ButtonOptions[y];
                    temp.ButtonOptionsScreens[y] = item.ButtonOptionsScreens[y];
                    temp.ButtonNumbers[y]        = item.ButtonNumbers[y];
                    temp.DeviceGuid = item.DeviceGuid;
                    temp.Selected   = item.Selected;
                }
                //controllerCount++;
                returnConf.ControllerConfigurations.Add(temp);
            }
            returnConf.NumberControllers = returnConf.ControllerConfigurations.Count;
            foreach (DisplayUnitConfiguration displayConf in DisplayUnitConfigurations)
            {
                var temp = new DisplayConfiguration(false)
                {
                    NumScreens         = displayConf.NumScreens + 1,
                    Inverted           = displayConf.Inverted,
                    IsTM1640           = displayConf.IsTM1640,
                    SwitchLEDs         = displayConf.SwitchLEDs,
                    ShowDC             = displayConf.ShowDC,
                    DCDisplayTime      = displayConf.DCDisplayTime,
                    ShowLap            = displayConf.ShowLap,
                    FFBClippingLights  = displayConf.LEDsConfigurations.FFBClippingLights,
                    FFBClippingScreen  = displayConf.LEDsConfigurations.FFBClippingScreen + 1,
                    PitLights          = displayConf.LEDsConfigurations.PitLights,
                    ShiftClumps        = displayConf.LEDsConfigurations.ShiftClumps,
                    RevLimiterLights   = displayConf.LEDsConfigurations.RevLimiterLights,
                    ShowShiftLights    = displayConf.LEDsConfigurations.ShowShiftLights,
                    DeltaLightsShow    = displayConf.LEDsConfigurations.DeltaLightsShow,
                    ShowEngineWarnings = displayConf.ShowEngineWarnings
                };
                List <Screen> screenTemp = displayConf.Screens;
                foreach (Screen screen in screenTemp)
                {
                    int place = 0;
                    while (place < screen.Variables.Count)
                    {
                        if (screen.Variables[place] == null || screen.Variables[place] == "")
                        {
                            screen.Variables.RemoveAt(place);
                        }
                        else
                        {
                            place++;
                        }
                    }
                    if (screen.Variables.Count == 0)
                    {
                        screen.Variables.Add("Space");
                    }
                }
                temp.Screens = displayConf.Screens;
                try
                {
                    temp.WarningType = dicts.WarningTypes[displayConf.WarningType];
                }
                catch
                {
                    Enum.TryParse(displayConf.WarningType, out temp.WarningType);
                }
                try
                {
                    temp.LapStyle = dicts.LapDisplayStyles[displayConf.LapStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LapStyle, out temp.LapStyle);
                }
                try
                {
                    temp.PitLimiterStyle = dicts.PitFlashStyles[displayConf.LEDsConfigurations.PitLimiterStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.PitLimiterStyle, out temp.PitLimiterStyle);
                }
                try
                {
                    temp.PitLimiterSpeed = dicts.PitFlashSpeeds[displayConf.LEDsConfigurations.PitLimiterSpeed];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.PitLimiterSpeed, out temp.PitLimiterSpeed);
                }
                try
                {
                    temp.ShiftLightStyle = dicts.ShiftStyles[displayConf.LEDsConfigurations.ShiftLightStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.ShiftLightStyle, out temp.ShiftLightStyle);
                }
                try
                {
                    temp.RevLimiterStyle = dicts.RevFlashStyles[displayConf.LEDsConfigurations.RevLimiterStyle];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.RevLimiterStyle, out temp.RevLimiterStyle);
                }
                temp.MatchCarShiftStyle = displayConf.LEDsConfigurations.MatchCarShiftLights;
                temp.MatchRedShift      = displayConf.LEDsConfigurations.MatchRedShift;
                try
                {
                    temp.MatchCarShiftStyleOption =
                        dicts.MatchCarShiftOptions[displayConf.LEDsConfigurations.MatchCarShiftOptions];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.MatchCarShiftOptions, out temp.MatchCarShiftStyleOption);
                }
                temp.DeltaLightsShow = displayConf.LEDsConfigurations.DeltaLightsShow;
                try
                {
                    temp.DeltaLightsPosition =
                        dicts.DeltaLightsPositionOptions[displayConf.LEDsConfigurations.DeltaLightsPosition];
                }
                catch
                {
                    Enum.TryParse(displayConf.LEDsConfigurations.DeltaLightsPosition, out temp.DeltaLightsPosition);
                }
                for (int y = 0; y < Constants.NumberButtonsOnTm1638; y++)
                {
                    var butFuncTemp = ButtonFunctionsEnum.None;

                    foreach (var butFunc in dicts.ButtonFunctions)
                    {
                        if (butFunc.Value.Name == displayConf.ButtonConfigurations.ButtonFunctions[y])
                        {
                            butFuncTemp = butFunc.Key;
                        }
                    }
                    temp.ButtonFunctions[y]      = butFuncTemp;
                    temp.ButtonOptions[y]        = displayConf.ButtonConfigurations.ButtonOptions[y];
                    temp.ButtonOptionsScreens[y] = displayConf.ButtonConfigurations.ButtonOptionsScreens[y];
                }
                returnConf.DisplayConfigurations.Add(temp);
            }
            return(returnConf);
        }
        public void LoadConfiguration(Configuration configuration, Dictionarys dicts)
        {
            Name = configuration.Name;
            FileLocation = configuration.FileLocation;
            Intensity = configuration.TMDisplaySettings.Intensity;
            ShiftIntensity = configuration.TMDisplaySettings.ShiftIntensity;
            ShiftIntensityType = configuration.TMDisplaySettings.ShiftIntensityType;
            ShiftIntensityAmount = configuration.TMDisplaySettings.ShiftIntensityAmount;
            ShowHeader = configuration.TMDisplaySettings.ShowHeaders;
            HeaderDisplayTime = configuration.TMDisplaySettings.HeaderDisplayTime - 1;
            QuickInfoDisplayTime = configuration.TMDisplaySettings.QuickInfoDisplayTime - 1;
            LapTimeDisplayTime = configuration.TMDisplaySettings.LapDisplayTime - 1;
            PreferredComPort = configuration.SerialPortSettings.PreferredComPort;
            LogArduinoMessages = configuration.AdvancedSettings.LogArduinoMessages;
            SerialPortSpeed = configuration.SerialPortSettings.SerialPortSpeed.ToString(CultureInfo.InvariantCulture);
            DisplayRefreshRate = configuration.RefreshRates.DisplayRefreshRate.ToString(CultureInfo.InvariantCulture);
            LEDRefreshRate = configuration.RefreshRates.LEDRefreshRate.ToString(CultureInfo.InvariantCulture);
            UseCustomSerialSpeed = configuration.SerialPortSettings.UseCustomSerialSpeed;
            ColourDeltaByDD = configuration.TMDisplaySettings.ColourDeltaByDD;
            DeltaLightsOnDefault = configuration.TMDisplaySettings.DeltaLightsOnDefault;
            DeltaMessageScreen = configuration.TMDisplaySettings.DeltaMessageScreen;
            DeltaRange = configuration.TMDisplaySettings.DeltaRange - 1;
            UseCustomFuelCalculationOptions = configuration.OtherSettings.UseCustomFuelCalculationOptions;
            FuelCalculationLaps = configuration.OtherSettings.FuelCalculationLaps - 2;
            UseWeightedFuelCalculations = configuration.OtherSettings.UseWeightedFuelCalculations;
            WarningTextDisplayTime = configuration.TMDisplaySettings.WarningTextDisplayTime - 1;
            QuickInfoLightsColour = configuration.TMDisplaySettings.QuickInfoLightsColour;

            ArduinoIOConfiguration = new ArduinoIO();
            FergoTechConfiguration = new FergoTechComponents();

            ControllerConfigurations = new List<ControllerButtonConfiguration>();
            foreach (ControllerConfiguration item in configuration.ControllerConfigurations)
            {
                var temp = new ControllerButtonConfiguration
                    {
                        DeviceGuid = item.DeviceGuid,
                        ButtonNumbers = item.ButtonNumbers,
                        ButtonOptions = item.ButtonOptions,
                        ButtonOptionsScreens = item.ButtonOptionsScreens,
                        Selected = item.Selected
                    };
                for (int k = 0; k < Constants.MaxNumberJoystickButtons; k++)
                {
                    temp.ButtonFunctions[k] = dicts.ButtonFunctions[item.ButtonFunctions[k]].Name;
                }
                ControllerConfigurations.Add(temp);
            }
            NumberControllers = configuration.ControllerConfigurations.Count;
            DisplayUnitConfigurations = new List<DisplayUnitConfiguration>();
            int unitCount = 0;
            foreach (DisplayConfiguration displayConf in configuration.DisplayConfigurations)
            {
                unitCount++;
                var temp = new DisplayUnitConfiguration
                    {
                        NumScreens = displayConf.NumScreens - 1,
                        Inverted = displayConf.Inverted,
                        IsTM1640 = displayConf.IsTM1640,
                        SwitchLEDs = displayConf.SwitchLEDs,
                        ShowDC = displayConf.ShowDC,
                        DCDisplayTime = displayConf.DCDisplayTime,
                        ShowLap = displayConf.ShowLap,
                        ButtonConfigurations = new ButtonConfiguration(),
                        UnitNumber = unitCount,
                        ShowEngineWarnings = displayConf.ShowEngineWarnings
                    };
                DisplayConfiguration conf = displayConf;
                foreach (var lstyle in dicts.LapDisplayStyles.Where(lstyle => conf.LapStyle == lstyle.Value))
                {
                    temp.LapStyle = lstyle.Key;
                } foreach (var wtype in dicts.WarningTypes.Where(wtype => conf.WarningType == wtype.Value))
                {
                    temp.WarningType = wtype.Key;
                }

                for (int n = 0; n < Constants.NumberButtonsOnTm1638; n++)
                {
                    temp.ButtonConfigurations.ButtonFunctions[n] =
                        dicts.ButtonFunctions[displayConf.ButtonFunctions[n]].Name;
                    temp.ButtonConfigurations.ButtonOptions[n] = displayConf.ButtonOptions[n];
                    temp.ButtonConfigurations.ButtonOptionsScreens[n] = displayConf.ButtonOptionsScreens[n];
                }
                temp.LEDsConfigurations = new LEDsConfiguration
                                              {
                                                      FFBClippingLights = displayConf.FFBClippingLights,
                                                      FFBClippingScreen = displayConf.FFBClippingScreen - 1,
                                                      PitLights = displayConf.PitLights,
                                                      RevLimiterLights = displayConf.RevLimiterLights,
                                                      ShowShiftLights = displayConf.ShowShiftLights,
                                                      ShiftClumps = displayConf.ShiftClumps,
                                                      MatchCarShiftLights = displayConf.MatchCarShiftStyle,
                                                      MatchRedShift = displayConf.MatchRedShift,
                                                      DeltaLightsShow = displayConf.DeltaLightsShow,
                                                      MatchCarShiftOptions = "",
                                              };
                foreach (var opt in dicts.MatchCarShiftOptions)
                {
                    if (opt.Value == displayConf.MatchCarShiftStyleOption)
                    {
                        temp.LEDsConfigurations.MatchCarShiftOptions = opt.Key;
                    }
                }
                temp.LEDsConfigurations.DeltaLightsPosition = "";
                foreach (var opt in dicts.DeltaLightsPositionOptions)
                {
                    if (opt.Value == displayConf.DeltaLightsPosition)
                    {
                        temp.LEDsConfigurations.DeltaLightsPosition = opt.Key;
                    }
                }
                foreach (var plspeed in dicts.PitFlashSpeeds)
                {
                    if (plspeed.Value == displayConf.PitLimiterSpeed)
                    {
                        temp.LEDsConfigurations.PitLimiterSpeed = plspeed.Key;
                    }
                }
                foreach (var plstyle in dicts.PitFlashStyles)
                {
                    if (plstyle.Value == displayConf.PitLimiterStyle)
                    {
                        temp.LEDsConfigurations.PitLimiterStyle = plstyle.Key;
                    }
                }
                foreach (var revlstyle in dicts.RevFlashStyles)
                {
                    if (revlstyle.Value == displayConf.RevLimiterStyle)
                    {
                        temp.LEDsConfigurations.RevLimiterStyle = revlstyle.Key;
                    }
                }
                foreach (var shiftstyle in dicts.ShiftStyles)
                {
                    if (shiftstyle.Value == displayConf.ShiftLightStyle)
                    {
                        temp.LEDsConfigurations.ShiftLightStyle = shiftstyle.Key;
                    }
                }
                temp.Screens = displayConf.Screens;
                DisplayUnitConfigurations.Add(temp);
            }
        }
Beispiel #4
0
        public void LoadConfiguration(Configuration configuration, Dictionarys dicts)
        {
            Name                            = configuration.Name;
            FileLocation                    = configuration.FileLocation;
            Intensity                       = configuration.TMDisplaySettings.Intensity;
            ShiftIntensity                  = configuration.TMDisplaySettings.ShiftIntensity;
            ShiftIntensityType              = configuration.TMDisplaySettings.ShiftIntensityType;
            ShiftIntensityAmount            = configuration.TMDisplaySettings.ShiftIntensityAmount;
            ShowHeader                      = configuration.TMDisplaySettings.ShowHeaders;
            HeaderDisplayTime               = configuration.TMDisplaySettings.HeaderDisplayTime - 1;
            QuickInfoDisplayTime            = configuration.TMDisplaySettings.QuickInfoDisplayTime - 1;
            LapTimeDisplayTime              = configuration.TMDisplaySettings.LapDisplayTime - 1;
            PreferredComPort                = configuration.SerialPortSettings.PreferredComPort;
            LogArduinoMessages              = configuration.AdvancedSettings.LogArduinoMessages;
            SerialPortSpeed                 = configuration.SerialPortSettings.SerialPortSpeed.ToString(CultureInfo.InvariantCulture);
            DisplayRefreshRate              = configuration.RefreshRates.DisplayRefreshRate.ToString(CultureInfo.InvariantCulture);
            LEDRefreshRate                  = configuration.RefreshRates.LEDRefreshRate.ToString(CultureInfo.InvariantCulture);
            UseCustomSerialSpeed            = configuration.SerialPortSettings.UseCustomSerialSpeed;
            ColourDeltaByDD                 = configuration.TMDisplaySettings.ColourDeltaByDD;
            DeltaLightsOnDefault            = configuration.TMDisplaySettings.DeltaLightsOnDefault;
            DeltaMessageScreen              = configuration.TMDisplaySettings.DeltaMessageScreen;
            DeltaRange                      = configuration.TMDisplaySettings.DeltaRange - 1;
            UseCustomFuelCalculationOptions = configuration.OtherSettings.UseCustomFuelCalculationOptions;
            FuelCalculationLaps             = configuration.OtherSettings.FuelCalculationLaps - 2;
            UseWeightedFuelCalculations     = configuration.OtherSettings.UseWeightedFuelCalculations;
            WarningTextDisplayTime          = configuration.TMDisplaySettings.WarningTextDisplayTime - 1;
            QuickInfoLightsColour           = configuration.TMDisplaySettings.QuickInfoLightsColour;

            ControllerConfigurations = new List <ControllerButtonConfiguration>();
            foreach (ControllerConfiguration item in configuration.ControllerConfigurations)
            {
                var temp = new ControllerButtonConfiguration
                {
                    DeviceGuid           = item.DeviceGuid,
                    ButtonNumbers        = item.ButtonNumbers,
                    ButtonOptions        = item.ButtonOptions,
                    ButtonOptionsScreens = item.ButtonOptionsScreens,
                    Selected             = item.Selected
                };
                for (int k = 0; k < Constants.MaxNumberJoystickButtons; k++)
                {
                    temp.ButtonFunctions[k] = dicts.ButtonFunctions[item.ButtonFunctions[k]].Name;
                }
                ControllerConfigurations.Add(temp);
            }
            NumberControllers         = configuration.ControllerConfigurations.Count;
            DisplayUnitConfigurations = new List <DisplayUnitConfiguration>();
            int unitCount = 0;

            foreach (DisplayConfiguration displayConf in configuration.DisplayConfigurations)
            {
                unitCount++;
                var temp = new DisplayUnitConfiguration
                {
                    NumScreens           = displayConf.NumScreens - 1,
                    Inverted             = displayConf.Inverted,
                    IsTM1640             = displayConf.IsTM1640,
                    SwitchLEDs           = displayConf.SwitchLEDs,
                    ShowDC               = displayConf.ShowDC,
                    DCDisplayTime        = displayConf.DCDisplayTime,
                    ShowLap              = displayConf.ShowLap,
                    ButtonConfigurations = new ButtonConfiguration(),
                    UnitNumber           = unitCount,
                    ShowEngineWarnings   = displayConf.ShowEngineWarnings
                };
                DisplayConfiguration conf = displayConf;
                foreach (var lstyle in dicts.LapDisplayStyles.Where(lstyle => conf.LapStyle == lstyle.Value))
                {
                    temp.LapStyle = lstyle.Key;
                }
                foreach (var wtype in dicts.WarningTypes.Where(wtype => conf.WarningType == wtype.Value))
                {
                    temp.WarningType = wtype.Key;
                }

                for (int n = 0; n < Constants.NumberButtonsOnTm1638; n++)
                {
                    temp.ButtonConfigurations.ButtonFunctions[n] =
                        dicts.ButtonFunctions[displayConf.ButtonFunctions[n]].Name;
                    temp.ButtonConfigurations.ButtonOptions[n]        = displayConf.ButtonOptions[n];
                    temp.ButtonConfigurations.ButtonOptionsScreens[n] = displayConf.ButtonOptionsScreens[n];
                }
                temp.LEDsConfigurations = new LEDsConfiguration
                {
                    FFBClippingLights    = displayConf.FFBClippingLights,
                    FFBClippingScreen    = displayConf.FFBClippingScreen - 1,
                    PitLights            = displayConf.PitLights,
                    RevLimiterLights     = displayConf.RevLimiterLights,
                    ShowShiftLights      = displayConf.ShowShiftLights,
                    ShiftClumps          = displayConf.ShiftClumps,
                    MatchCarShiftLights  = displayConf.MatchCarShiftStyle,
                    MatchRedShift        = displayConf.MatchRedShift,
                    DeltaLightsShow      = displayConf.DeltaLightsShow,
                    MatchCarShiftOptions = "",
                };
                foreach (var opt in dicts.MatchCarShiftOptions)
                {
                    if (opt.Value == displayConf.MatchCarShiftStyleOption)
                    {
                        temp.LEDsConfigurations.MatchCarShiftOptions = opt.Key;
                    }
                }
                temp.LEDsConfigurations.DeltaLightsPosition = "";
                foreach (var opt in dicts.DeltaLightsPositionOptions)
                {
                    if (opt.Value == displayConf.DeltaLightsPosition)
                    {
                        temp.LEDsConfigurations.DeltaLightsPosition = opt.Key;
                    }
                }
                foreach (var plspeed in dicts.PitFlashSpeeds)
                {
                    if (plspeed.Value == displayConf.PitLimiterSpeed)
                    {
                        temp.LEDsConfigurations.PitLimiterSpeed = plspeed.Key;
                    }
                }
                foreach (var plstyle in dicts.PitFlashStyles)
                {
                    if (plstyle.Value == displayConf.PitLimiterStyle)
                    {
                        temp.LEDsConfigurations.PitLimiterStyle = plstyle.Key;
                    }
                }
                foreach (var revlstyle in dicts.RevFlashStyles)
                {
                    if (revlstyle.Value == displayConf.RevLimiterStyle)
                    {
                        temp.LEDsConfigurations.RevLimiterStyle = revlstyle.Key;
                    }
                }
                foreach (var shiftstyle in dicts.ShiftStyles)
                {
                    if (shiftstyle.Value == displayConf.ShiftLightStyle)
                    {
                        temp.LEDsConfigurations.ShiftLightStyle = shiftstyle.Key;
                    }
                }
                temp.Screens = displayConf.Screens;
                DisplayUnitConfigurations.Add(temp);
            }
        }
Beispiel #5
0
        public static string BuildDisplayString(SdkWrapper.TelemetryUpdatedEventArgs e, List <string> variables, Dictionarys dictionarys, SavedTelemetryValues savedTelemetry, int currentDeltaType)
        {
            var displayString = "";

            foreach (string dvString in variables)
            {
                DisplayVarsEnum dv;
                if (!Enum.TryParse(dvString, out dv))
                {
                    continue;
                }
                switch (dv)
                {
                case DisplayVarsEnum.Speed:
                    float speedtemp = e.TelemetryInfo.Speed.Value * 3.6f;
                    if (speedtemp > 1)
                    {
                        displayString += RightJustify((e.TelemetryInfo.Speed.Value * 3.6f).ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                    }
                    else
                    {
                        displayString += RightJustify("0", dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.SpeedMiles:
                    float speedtemp2 = e.TelemetryInfo.Speed.Value * 2.236f;
                    if (speedtemp2 > 1)
                    {
                        displayString += RightJustify((e.TelemetryInfo.Speed.Value * 2.236f).ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                    }
                    else
                    {
                        displayString += RightJustify("0", dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.Gear:
                    if (e.TelemetryInfo.Gear.Value > 0)
                    {
                        displayString += e.TelemetryInfo.Gear.Value.ToString(CultureInfo.InvariantCulture);
                    }
                    else if (e.TelemetryInfo.Gear.Value == 0)
                    {
                        displayString += "n";
                    }
                    else
                    {
                        displayString += "r";
                    }
                    break;

                case DisplayVarsEnum.RPM5:
                    displayString += RightJustify(e.TelemetryInfo.RPM.Value.ToString("0"),
                                                  dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.RPM4:
                    if (e.TelemetryInfo.RPM.Value >= 10000)
                    {
                        displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.00"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += RightJustify(e.TelemetryInfo.RPM.Value.ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.RPM3:
                    if (e.TelemetryInfo.RPM.Value >= 10000)
                    {
                        displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.0"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.00"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    break;

                case DisplayVarsEnum.Throttle:
                    displayString += RightJustify((e.TelemetryInfo.Throttle.Value * 100).ToString("0"),
                                                  dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Brake:
                    displayString += RightJustify((e.TelemetryInfo.Brake.Value * 100).ToString("0"),
                                                  dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Clutch:
                    displayString += RightJustify((e.TelemetryInfo.Clutch.Value * 100).ToString("0"),
                                                  dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.RaceLaps3:
                    displayString +=
                        RightJustify(e.TelemetryInfo.RaceLaps.Value.ToString(CultureInfo.InvariantCulture),
                                     dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.RaceLaps2:
                    displayString +=
                        RightJustify(e.TelemetryInfo.RaceLaps.Value.ToString(CultureInfo.InvariantCulture),
                                     dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Laps3:
                    displayString +=
                        RightJustify(e.TelemetryInfo.Lap.Value.ToString(CultureInfo.InvariantCulture),
                                     dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Laps2:
                    displayString +=
                        RightJustify(e.TelemetryInfo.Lap.Value.ToString(CultureInfo.InvariantCulture),
                                     dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.CurrentLapTime:
                    if (e.TelemetryInfo.LapCurrentLapTime.Value > 1)
                    {
                        TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(e.TelemetryInfo.LapCurrentLapTime.Value));
                        displayString += t.ToString("m\\-ss\\.ff");
                    }
                    else
                    {
                        displayString += "_-__.__";
                    }
                    break;

                case DisplayVarsEnum.SelectableLapDelta:
                    switch (currentDeltaType)
                    {
                    case 0:
                        if (e.TelemetryInfo.LapDeltaToBestLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToBestLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;

                    case 1:
                        if (e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToOptimalLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }

                        break;

                    case 2:
                        if (e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionBestLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }

                        break;

                    case 3:
                        if (e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;

                    default:
                        displayString += " _._";
                        break;
                    }
                    break;

                case DisplayVarsEnum.LapDeltaBest:
                    if (e.TelemetryInfo.LapDeltaToBestLap_OK.Value)
                    {
                        displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToBestLap.Value);
                    }
                    else
                    {
                        displayString += " _._";
                    }
                    break;

                case DisplayVarsEnum.LapDeltaOptimal:
                    if (e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value)
                    {
                        displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToOptimalLap.Value);
                    }
                    else
                    {
                        displayString += " _._";
                    }
                    break;

                case DisplayVarsEnum.LapDeltaSessionBest:
                    if (e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value)
                    {
                        displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionBestLap.Value);
                    }
                    else
                    {
                        displayString += " _._";
                    }
                    break;

                case DisplayVarsEnum.LapDeltaSessionOptimal:
                    if (e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value)
                    {
                        displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value);
                    }
                    else
                    {
                        displayString += " _._";
                    }
                    break;


                case DisplayVarsEnum.ForceFeedBackPCT:
                    displayString += RightJustify(
                        (e.TelemetryInfo.SteeringWheelPctTorque.Value * 100).ToString("0"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.FuelLitres:
                    if (e.TelemetryInfo.FuelLevel.Value < 100)
                    {
                        displayString += RightJustify(e.TelemetryInfo.FuelLevel.Value.ToString("0.0"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += RightJustify(e.TelemetryInfo.FuelLevel.Value.ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.FuelGallons:
                    float fuelGallons = e.TelemetryInfo.FuelLevel.Value * 0.26417f;
                    if (fuelGallons < 100)
                    {
                        displayString += RightJustify(fuelGallons.ToString("0.0"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += RightJustify(fuelGallons.ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.FuelPCT:
                    if (e.TelemetryInfo.FuelLevelPct.Value >= 100)
                    {
                        displayString += "100";
                    }
                    else
                    {
                        displayString += RightJustify((e.TelemetryInfo.FuelLevelPct.Value * 100).ToString("0.0"),
                                                      dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    break;

                case DisplayVarsEnum.FuelBurnRate:
                    if (savedTelemetry.Fuel.BurnRate >= 0.01f)
                    {
                        displayString += RightJustify(savedTelemetry.Fuel.BurnRate.ToString("0.00"), dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += "_.__";
                    }
                    break;

                case DisplayVarsEnum.FuelBurnRateGallons:
                    //System.Diagnostics.Debug.WriteLine(String.Format("FuelBurnGallons"));
                    float burnRateGallons = savedTelemetry.Fuel.BurnRate * 0.26417f;
                    //System.Diagnostics.Debug.WriteLine(String.Format("          Value: {0}",burnRateGallons));
                    if (burnRateGallons >= 0.01f)
                    {
                        displayString += RightJustify(burnRateGallons.ToString("0.00"), dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += "_.__";
                    }
                    break;

                case DisplayVarsEnum.FuelLapsLeft:
                    if (savedTelemetry.Fuel.LapsLeft > 100)
                    {
                        displayString += RightJustify(savedTelemetry.Fuel.LapsLeft.ToString("0"), dictionarys.DisplayVariables[dv].Length);
                    }
                    else if (savedTelemetry.Fuel.LapsLeft >= 0.1f)
                    {
                        displayString += RightJustify(savedTelemetry.Fuel.LapsLeft.ToString("0.0"), dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    else
                    {
                        displayString += "_._";
                    }
                    break;

                case DisplayVarsEnum.LongG:
                    displayString += RightJustify(
                        (e.TelemetryInfo.LongAccel.Value / 10).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.LatG:
                    displayString += RightJustify(
                        (e.TelemetryInfo.LatAccel.Value / 10).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.TotalG:
                    displayString +=
                        RightJustify(
                            (Math.Sqrt(e.TelemetryInfo.LongAccel.Value * e.TelemetryInfo.LongAccel.Value +
                                       e.TelemetryInfo.LatAccel.Value * e.TelemetryInfo.LatAccel.Value) / 10)
                            .ToString(" 0.0;-0.0; 0.0"), dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.Position:
                    displayString +=
                        RightJustify(savedTelemetry.Position.ToString(CultureInfo.InvariantCulture),
                                     dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Space:
                    displayString += " ";
                    break;

                case DisplayVarsEnum.DoubleSpace:
                    displayString += "  ";
                    break;

                case DisplayVarsEnum.Underscore:
                    displayString += "_";
                    break;

                case DisplayVarsEnum.FuelPressure:
                    displayString += RightJustify(
                        (e.TelemetryInfo.FuelPress.Value).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.FuelPressurePSi:
                    displayString += RightJustify(
                        (e.TelemetryInfo.FuelPress.Value * 14.5f).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.ManifoldPressure:
                    displayString += RightJustify(
                        (e.TelemetryInfo.ManifoldPressure.Value).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.ManifoldPressurePSi:
                    displayString += RightJustify(
                        (e.TelemetryInfo.ManifoldPressure.Value * 14.5f).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.OilLevel:
                    displayString += RightJustify(
                        (e.TelemetryInfo.OilLevel.Value).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.OilPressure:
                    displayString += RightJustify(
                        (e.TelemetryInfo.OilPress.Value).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.OilTemp:
                    displayString += RightJustify(
                        (e.TelemetryInfo.OilTemp.Value).ToString("000"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.OilLevelGallons:
                    displayString += RightJustify(
                        (e.TelemetryInfo.OilLevel.Value * 0.26417f).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.OilPressurePSi:
                    displayString += RightJustify(
                        (e.TelemetryInfo.OilPress.Value * 14.5f).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.OilTempFahrenheit:
                    displayString += RightJustify(
                        ((e.TelemetryInfo.OilTemp.Value) * 9f / 5f + 32).ToString("000"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.Pitch:
                    displayString += RightJustify(
                        (e.TelemetryInfo.Pitch.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.PitchRate:
                    displayString += RightJustify(
                        (e.TelemetryInfo.PitchRate.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.Roll:
                    displayString += RightJustify(
                        (e.TelemetryInfo.Roll.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.RollRate:
                    displayString += RightJustify(
                        (e.TelemetryInfo.RollRate.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.Yaw:
                    displayString += RightJustify(
                        (e.TelemetryInfo.Yaw.Value * 57.2957795).ToString(" 00;-00; 00"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.YawRate:
                    displayString += RightJustify(
                        (e.TelemetryInfo.YawRate.Value * 57.2957795).ToString(" 00;-00; 00"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.SteeringWheelAngle:
                    displayString += RightJustify(
                        (e.TelemetryInfo.SteeringWheelAngle.Value * 57.2957795).ToString(" 000;-000; 000"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.EngineVoltage:
                    displayString += RightJustify(
                        (e.TelemetryInfo.Voltage.Value).ToString("00.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.EngineWaterLevel:
                    displayString += RightJustify(
                        (e.TelemetryInfo.WaterLevel.Value).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.EngineWaterTemp:
                    displayString += RightJustify(
                        (e.TelemetryInfo.WaterTemp.Value).ToString("000"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.EngineWaterLevelGallons:
                    displayString += RightJustify(
                        (e.TelemetryInfo.WaterLevel.Value * 0.26417).ToString("0.0"),
                        dictionarys.DisplayVariables[dv].Length + 1);
                    break;

                case DisplayVarsEnum.EngineWaterTempFahrenheit:
                    displayString += RightJustify(
                        ((e.TelemetryInfo.WaterTemp.Value) * 9f / 5f + 32).ToString("000"),
                        dictionarys.DisplayVariables[dv].Length);
                    break;

                case DisplayVarsEnum.SessionLapsRemaining:
                    if (e.TelemetryInfo.SessionLapsRemaining != null)
                    {
                        displayString += RightJustify(
                            (e.TelemetryInfo.SessionLapsRemaining.Value).ToString("000"),
                            dictionarys.DisplayVariables[dv].Length);
                    }
                    break;

                case DisplayVarsEnum.SessionTime:
                    if (e.TelemetryInfo.SessionTime != null)
                    {
                        var tempST = new TimeSpan(0, 0, Convert.ToInt32(e.TelemetryInfo.SessionTime.Value));
                        displayString += RightJustify(
                            String.Format("{0}-{1}.{2}", tempST.Hours.ToString("0"),
                                          tempST.Minutes.ToString("00"), tempST.Seconds.ToString("00")),
                            dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    break;

                case DisplayVarsEnum.SessionTimeRemaining:
                    if (e.TelemetryInfo.SessionTimeRemaining != null)
                    {
                        var tempStr = new TimeSpan(0, 0,
                                                   Convert.ToInt32(e.TelemetryInfo.SessionTimeRemaining.Value));
                        displayString += RightJustify(
                            String.Format("{0}-{1}.{2}", tempStr.Hours.ToString("0"),
                                          tempStr.Minutes.ToString("00"), tempStr.Seconds.ToString("00")),
                            dictionarys.DisplayVariables[dv].Length + 1);
                    }
                    break;

                case DisplayVarsEnum.LapsSinceLastPit:
                    displayString += e.TelemetryInfo.Lap.Value - savedTelemetry.LapLastPited;
                    break;
                }
            }
            return(displayString);
        }
Beispiel #6
0
        /// <summary>
        ///     Gets LED bytes using ShiftStyles
        /// </summary>
        /// <param name="dictionarys"></param>
        /// <param name="currentRPM">Current RPM</param>
        /// <param name="shiftStart">RPM of first shift light</param>
        /// <param name="shiftEnd">RPM of last Shift light</param>
        /// <param name="shiftPoint">RPM of optimal shift point</param>
        /// <param name="style">Shift Light Style</param>
        /// <param name="pastShiftPoint"></param>
        /// <param name="red">RED LEDs byte</param>
        /// <param name="green">Green LEDS byte</param>
        /// <param name="shiftClumps"></param>
        public static void GetShiftLights(Dictionarys dictionarys, float currentRPM, float shiftStart, float shiftEnd, float shiftPoint,
                                          ShiftStyleEnum style, bool shiftClumps, out bool pastShiftPoint, out byte red, out byte green)
        {
            pastShiftPoint = false;
            red            = 0;
            green          = 0;
            if (style == ShiftStyleEnum.None)
            {
                return;
            }
            if (shiftStart < 1 || shiftEnd < 1)
            {
                if (shiftPoint > 1)
                {
                    shiftStart = shiftPoint - 1;
                    shiftEnd   = shiftPoint;
                }
                else
                {
                    return; // No Valid Shift values for this current gear/map/car
                }
            }
            if (shiftPoint < 1)
            {
                shiftPoint = 40000;
            }
            if (!(currentRPM >= shiftStart))
            {
                return;
            }
            //get length of shift style
            int shiftStyleLength = dictionarys.RPMStyles[style].Length;
            //calc point in shift lists to use
            float calc  = ((currentRPM - shiftStart) / (shiftEnd - shiftStart)) * Convert.ToSingle(shiftStyleLength - 1);
            int   place = Convert.ToInt32(Math.Floor(calc));

            if (place >= shiftStyleLength)
            {
                place = shiftStyleLength - 1;
            }
            if (shiftClumps)
            {
                if (place >= shiftStyleLength - 1)
                {
                    //last seg, all lights on so leave as is
                }
                else if (place >= (shiftStyleLength / 2) - 1)
                {
                    //middle seg
                    switch (shiftStyleLength)
                    {
                    case 4:
                        place = 1;
                        break;

                    case 8:
                        place = 4;
                        break;

                    case 16:
                        place = 10;
                        break;

                    case 32:
                        place = 20;
                        break;
                    }
                }
                else
                {
                    //first seg
                    switch (shiftStyleLength)
                    {
                    case 4:
                        place = 0;
                        break;

                    case 8:
                        place = 1;
                        break;

                    case 16:
                        place = 4;
                        break;

                    case 32:
                        place = 9;
                        break;
                    }
                }
            } //end shiftClumps
            if (shiftPoint <= 1) // Shift Point RPM value not valid
            {
                shiftPoint = 50000;
            }
            if (currentRPM >= shiftPoint && dictionarys.RPMStyles[style].UseShiftedArray)
            {
                pastShiftPoint = true;
                Lights temp = dictionarys.RPMStyles[style].Shifted[place];
                red   = temp.Red;
                green = temp.Green;
            }
            else
            {
                Lights temp = dictionarys.RPMStyles[style].Normal[place]; //-1?
                red   = temp.Red;
                green = temp.Green;
            }
        }
Beispiel #7
0
        public static string BuildDisplayString(SdkWrapper.TelemetryUpdatedEventArgs e, List<string> variables, Dictionarys dictionarys, SavedTelemetryValues savedTelemetry, int currentDeltaType)
        {
            var displayString = "";
            foreach (string dvString in variables)
            {
                DisplayVarsEnum dv;
                if (!Enum.TryParse(dvString, out dv)) continue;
                switch (dv)
                {
                    case DisplayVarsEnum.Speed:
                        float speedtemp = e.TelemetryInfo.Speed.Value * 3.6f;
                        if (speedtemp > 1)
                        {
                            displayString += RightJustify((e.TelemetryInfo.Speed.Value * 3.6f).ToString("0"),
                                                          dictionarys.DisplayVariables[dv].Length);
                        }
                        else
                        {
                            displayString += RightJustify("0", dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.SpeedMiles:
                        float speedtemp2 = e.TelemetryInfo.Speed.Value * 2.236f;
                        if (speedtemp2 > 1)
                        {
                            displayString += RightJustify((e.TelemetryInfo.Speed.Value * 2.236f).ToString("0"),
                                                          dictionarys.DisplayVariables[dv].Length);
                        }
                        else
                        {
                            displayString += RightJustify("0", dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.Gear:
                        if (e.TelemetryInfo.Gear.Value > 0)
                        {
                            displayString += e.TelemetryInfo.Gear.Value.ToString(CultureInfo.InvariantCulture);
                        }
                        else if (e.TelemetryInfo.Gear.Value == 0)
                        {
                            displayString += "n";
                        }
                        else
                        {
                            displayString += "r";
                        }
                        break;
                    case DisplayVarsEnum.RPM5:
                        displayString += RightJustify(e.TelemetryInfo.RPM.Value.ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.RPM4:
                        if (e.TelemetryInfo.RPM.Value >= 10000)
                        {
                            displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.00"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += RightJustify(e.TelemetryInfo.RPM.Value.ToString("0"),
                                                          dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.RPM3:
                        if (e.TelemetryInfo.RPM.Value >= 10000)
                        {
                            displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.0"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += RightJustify((e.TelemetryInfo.RPM.Value / 1000f).ToString("0.00"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        break;
                    case DisplayVarsEnum.Throttle:
                        displayString += RightJustify((e.TelemetryInfo.Throttle.Value * 100).ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Brake:
                        displayString += RightJustify((e.TelemetryInfo.Brake.Value * 100).ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Clutch:
                        displayString += RightJustify((e.TelemetryInfo.Clutch.Value * 100).ToString("0"),
                                                      dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.RaceLaps3:
                        displayString +=
                            RightJustify(e.TelemetryInfo.RaceLaps.Value.ToString(CultureInfo.InvariantCulture),
                                         dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.RaceLaps2:
                        displayString +=
                            RightJustify(e.TelemetryInfo.RaceLaps.Value.ToString(CultureInfo.InvariantCulture),
                                         dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Laps3:
                        displayString +=
                            RightJustify(e.TelemetryInfo.Lap.Value.ToString(CultureInfo.InvariantCulture),
                                         dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Laps2:
                        displayString +=
                            RightJustify(e.TelemetryInfo.Lap.Value.ToString(CultureInfo.InvariantCulture),
                                         dictionarys.DisplayVariables[dv].Length);
                        break;

                    case DisplayVarsEnum.CurrentLapTime:
                        if (e.TelemetryInfo.LapCurrentLapTime.Value > 1)
                        {
                            TimeSpan t = TimeSpan.FromSeconds(Convert.ToDouble(e.TelemetryInfo.LapCurrentLapTime.Value));
                            displayString += t.ToString("m\\-ss\\.ff");
                        }
                        else
                        {
                            displayString += "_-__.__";
                        }
                        break;
                    case DisplayVarsEnum.SelectableLapDelta:
                        switch (currentDeltaType)
                        {
                            case 0:
                                if (e.TelemetryInfo.LapDeltaToBestLap_OK.Value)
                                {
                                    displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToBestLap.Value);
                                }
                                else
                                {
                                    displayString += " _._";
                                }
                                break;
                            case 1:
                                if (e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value)
                                {
                                    displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToOptimalLap.Value);
                                }
                                else
                                {
                                    displayString += " _._";
                                }

                                break;
                            case 2:
                                if (e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value)
                                {
                                    displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionBestLap.Value);
                                }
                                else
                                {
                                    displayString += " _._";
                                }

                                break;
                            case 3:
                                if (e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value)
                                {
                                    displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value);
                                }
                                else
                                {
                                    displayString += " _._";
                                }
                                break;
                            default:
                                displayString += " _._";
                                break;
                        }
                        break;
                    case DisplayVarsEnum.LapDeltaBest:
                        if (e.TelemetryInfo.LapDeltaToBestLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToBestLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;
                    case DisplayVarsEnum.LapDeltaOptimal:
                        if (e.TelemetryInfo.LapDeltaToOptimalLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToOptimalLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;
                    case DisplayVarsEnum.LapDeltaSessionBest:
                        if (e.TelemetryInfo.LapDeltaToSessionBestLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionBestLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;
                    case DisplayVarsEnum.LapDeltaSessionOptimal:
                        if (e.TelemetryInfo.LapDeltaToSessionOptimalLap_OK.Value)
                        {
                            displayString += DeltaDisplay(e.TelemetryInfo.LapDeltaToSessionOptimalLap.Value);
                        }
                        else
                        {
                            displayString += " _._";
                        }
                        break;

                    case DisplayVarsEnum.ForceFeedBackPCT:
                        displayString += RightJustify(
                            (e.TelemetryInfo.SteeringWheelPctTorque.Value * 100).ToString("0"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.FuelLitres:
                        if (e.TelemetryInfo.FuelLevel.Value < 100)
                        {
                            displayString += RightJustify(e.TelemetryInfo.FuelLevel.Value.ToString("0.0"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += RightJustify(e.TelemetryInfo.FuelLevel.Value.ToString("0"),
                                                          dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.FuelGallons:
                        float fuelGallons = e.TelemetryInfo.FuelLevel.Value * 0.26417f;
                        if (fuelGallons < 100)
                        {
                            displayString += RightJustify(fuelGallons.ToString("0.0"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += RightJustify(fuelGallons.ToString("0"),
                                                          dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.FuelPCT:
                        if (e.TelemetryInfo.FuelLevelPct.Value >= 100)
                        {
                            displayString += "100";
                        }
                        else
                        {
                            displayString += RightJustify((e.TelemetryInfo.FuelLevelPct.Value * 100).ToString("0.0"),
                                                          dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        break;
                    case DisplayVarsEnum.FuelBurnRate:
                        if (savedTelemetry.Fuel.BurnRate >= 0.01f)
                        {
                            displayString += RightJustify(savedTelemetry.Fuel.BurnRate.ToString("0.00"), dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += "_.__";
                        }
                        break;
                    case DisplayVarsEnum.FuelBurnRateGallons:
                        //System.Diagnostics.Debug.WriteLine(String.Format("FuelBurnGallons"));
                        float burnRateGallons = savedTelemetry.Fuel.BurnRate * 0.26417f;
                        //System.Diagnostics.Debug.WriteLine(String.Format("          Value: {0}",burnRateGallons));
                        if (burnRateGallons >= 0.01f)
                        {
                            displayString += RightJustify(burnRateGallons.ToString("0.00"), dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += "_.__";
                        }
                        break;
                    case DisplayVarsEnum.FuelLapsLeft:
                        if (savedTelemetry.Fuel.LapsLeft > 100)
                        {
                            displayString += RightJustify(savedTelemetry.Fuel.LapsLeft.ToString("0"), dictionarys.DisplayVariables[dv].Length);
                        }
                        else if (savedTelemetry.Fuel.LapsLeft >= 0.1f)
                        {
                            displayString += RightJustify(savedTelemetry.Fuel.LapsLeft.ToString("0.0"), dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        else
                        {
                            displayString += "_._";
                        }
                        break;
                    case DisplayVarsEnum.LongG:
                        displayString += RightJustify(
                            (e.TelemetryInfo.LongAccel.Value / 10).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.LatG:
                        displayString += RightJustify(
                            (e.TelemetryInfo.LatAccel.Value / 10).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.TotalG:
                        displayString +=
                            RightJustify(
                                (Math.Sqrt(e.TelemetryInfo.LongAccel.Value * e.TelemetryInfo.LongAccel.Value +
                                           e.TelemetryInfo.LatAccel.Value * e.TelemetryInfo.LatAccel.Value) / 10)
                                    .ToString(" 0.0;-0.0; 0.0"), dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.Position:
                        displayString +=
                            RightJustify(savedTelemetry.Position.ToString(CultureInfo.InvariantCulture),
                                         dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Space:
                        displayString += " ";
                        break;
                    case DisplayVarsEnum.DoubleSpace:
                        displayString += "  ";
                        break;
                    case DisplayVarsEnum.Underscore:
                        displayString += "_";
                        break;
                    case DisplayVarsEnum.FuelPressure:
                        displayString += RightJustify(
                            (e.TelemetryInfo.FuelPress.Value).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.FuelPressurePSi:
                        displayString += RightJustify(
                            (e.TelemetryInfo.FuelPress.Value * 14.5f).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.ManifoldPressure:
                        displayString += RightJustify(
                            (e.TelemetryInfo.ManifoldPressure.Value).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.ManifoldPressurePSi:
                        displayString += RightJustify(
                            (e.TelemetryInfo.ManifoldPressure.Value * 14.5f).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.OilLevel:
                        displayString += RightJustify(
                            (e.TelemetryInfo.OilLevel.Value).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.OilPressure:
                        displayString += RightJustify(
                            (e.TelemetryInfo.OilPress.Value).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.OilTemp:
                        displayString += RightJustify(
                            (e.TelemetryInfo.OilTemp.Value).ToString("000"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.OilLevelGallons:
                        displayString += RightJustify(
                            (e.TelemetryInfo.OilLevel.Value * 0.26417f).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.OilPressurePSi:
                        displayString += RightJustify(
                            (e.TelemetryInfo.OilPress.Value * 14.5f).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.OilTempFahrenheit:
                        displayString += RightJustify(
                            ((e.TelemetryInfo.OilTemp.Value) * 9f/5f + 32).ToString("000"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.Pitch:
                        displayString += RightJustify(
                            (e.TelemetryInfo.Pitch.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.PitchRate:
                        displayString += RightJustify(
                            (e.TelemetryInfo.PitchRate.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.Roll:
                        displayString += RightJustify(
                            (e.TelemetryInfo.Roll.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.RollRate:
                        displayString += RightJustify(
                            (e.TelemetryInfo.RollRate.Value * 57.2957795).ToString(" 0.0;-0.0; 0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.Yaw:
                        displayString += RightJustify(
                            (e.TelemetryInfo.Yaw.Value * 57.2957795).ToString(" 00;-00; 00"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.YawRate:
                        displayString += RightJustify(
                            (e.TelemetryInfo.YawRate.Value * 57.2957795).ToString(" 00;-00; 00"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.SteeringWheelAngle:
                        displayString += RightJustify(
                            (e.TelemetryInfo.SteeringWheelAngle.Value * 57.2957795).ToString(" 000;-000; 000"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.EngineVoltage:
                        displayString += RightJustify(
                            (e.TelemetryInfo.Voltage.Value).ToString("00.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.EngineWaterLevel:
                        displayString += RightJustify(
                            (e.TelemetryInfo.WaterLevel.Value).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.EngineWaterTemp:
                        displayString += RightJustify(
                            (e.TelemetryInfo.WaterTemp.Value).ToString("000"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.EngineWaterLevelGallons:
                        displayString += RightJustify(
                            (e.TelemetryInfo.WaterLevel.Value * 0.26417).ToString("0.0"),
                            dictionarys.DisplayVariables[dv].Length + 1);
                        break;
                    case DisplayVarsEnum.EngineWaterTempFahrenheit:
                        displayString += RightJustify(
                            ((e.TelemetryInfo.WaterTemp.Value) * 9f/5f + 32).ToString("000"),
                            dictionarys.DisplayVariables[dv].Length);
                        break;
                    case DisplayVarsEnum.SessionLapsRemaining:
                        if (e.TelemetryInfo.SessionLapsRemaining != null)
                        {
                            displayString += RightJustify(
                                (e.TelemetryInfo.SessionLapsRemaining.Value).ToString("000"),
                                dictionarys.DisplayVariables[dv].Length);
                        }
                        break;
                    case DisplayVarsEnum.SessionTime:
                        if (e.TelemetryInfo.SessionTime != null)
                        {
                            var tempST = new TimeSpan(0, 0, Convert.ToInt32(e.TelemetryInfo.SessionTime.Value));
                            displayString += RightJustify(
                                String.Format("{0}-{1}.{2}", tempST.Hours.ToString("0"),
                                              tempST.Minutes.ToString("00"), tempST.Seconds.ToString("00")),
                                dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        break;
                    case DisplayVarsEnum.SessionTimeRemaining:
                        if (e.TelemetryInfo.SessionTimeRemaining != null)
                        {
                            var tempStr = new TimeSpan(0, 0,
                                                       Convert.ToInt32(e.TelemetryInfo.SessionTimeRemaining.Value));
                            displayString += RightJustify(
                                String.Format("{0}-{1}.{2}", tempStr.Hours.ToString("0"),
                                              tempStr.Minutes.ToString("00"), tempStr.Seconds.ToString("00")),
                                dictionarys.DisplayVariables[dv].Length + 1);
                        }
                        break;

                    case DisplayVarsEnum.LapsSinceLastPit:
                        displayString += e.TelemetryInfo.Lap.Value - savedTelemetry.LapLastPited;
                        break;
                }
            }
            return displayString;
        }
Beispiel #8
0
 /// <summary>
 ///     Gets LED bytes using ShiftStyles
 /// </summary>
 /// <param name="dictionarys"></param>
 /// <param name="currentRPM">Current RPM</param>
 /// <param name="shiftStart">RPM of first shift light</param>
 /// <param name="shiftEnd">RPM of last Shift light</param>
 /// <param name="shiftPoint">RPM of optimal shift point</param>
 /// <param name="style">Shift Light Style</param>
 /// <param name="pastShiftPoint"></param>
 /// <param name="red">RED LEDs byte</param>
 /// <param name="green">Green LEDS byte</param>
 /// <param name="shiftClumps"></param>
 public static void GetShiftLights(Dictionarys dictionarys,float currentRPM, float shiftStart, float shiftEnd, float shiftPoint,
                            ShiftStyleEnum style, bool shiftClumps,out bool pastShiftPoint, out byte red, out byte green)
 {
     pastShiftPoint = false;
     red = 0;
     green = 0;
     if (style == ShiftStyleEnum.None) return;
     if (shiftStart < 1 || shiftEnd < 1)
     {
         if (shiftPoint > 1)
         {
             shiftStart = shiftPoint - 1;
             shiftEnd = shiftPoint;
         }
         else
         {
             return; // No Valid Shift values for this current gear/map/car
         }
     }
     if (shiftPoint < 1) shiftPoint = 40000;
     if (!(currentRPM >= shiftStart)) return;
     //get length of shift style
     int shiftStyleLength = dictionarys.RPMStyles[style].Length;
     //calc point in shift lists to use
     float calc = ((currentRPM - shiftStart) / (shiftEnd - shiftStart)) * Convert.ToSingle(shiftStyleLength - 1);
     int place = Convert.ToInt32(Math.Floor(calc));
     if (place >= shiftStyleLength)
     {
         place = shiftStyleLength - 1;
     }
     if (shiftClumps)
     {
         if (place >= shiftStyleLength - 1)
         {
             //last seg, all lights on so leave as is
         }
         else if (place >= (shiftStyleLength / 2) - 1)
         {
             //middle seg
             switch (shiftStyleLength)
             {
                 case 4:
                     place = 1;
                     break;
                 case 8:
                     place = 4;
                     break;
                 case 16:
                     place = 10;
                     break;
                 case 32:
                     place = 20;
                     break;
             }
         }
         else
         {
             //first seg
             switch (shiftStyleLength)
             {
                 case 4:
                     place = 0;
                     break;
                 case 8:
                     place = 1;
                     break;
                 case 16:
                     place = 4;
                     break;
                 case 32:
                     place = 9;
                     break;
             }
         }
     } //end shiftClumps
     if (shiftPoint <= 1) // Shift Point RPM value not valid
     {
         shiftPoint = 50000;
     }
     if (currentRPM >= shiftPoint && dictionarys.RPMStyles[style].UseShiftedArray)
     {
         pastShiftPoint = true;
         Lights temp = dictionarys.RPMStyles[style].Shifted[place];
         red = temp.Red;
         green = temp.Green;
     }
     else
     {
         Lights temp = dictionarys.RPMStyles[style].Normal[place]; //-1?
         red = temp.Red;
         green = temp.Green;
     }
 }