Пример #1
0
        protected override void NonRealtimeCalculations(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            fpsCounter = 0;

            InPitsV2(e);
            CalculateGear(e);
            CalculateFuel(e);



            remainingTime = e.TelemetryInfo.SessionTimeRemain.Value;


            #region Set Fuel level

            fuelLevel = e.TelemetryInfo.FuelLevel.Value;
            sessionForm.Fuel_remain_value.Text = string.Format("{0:00.00}", fuelLevel);

            #endregion

            #region EngineWarnings (Stalled engine)

            sessionForm.engine_panel.Visible = engineWarning == 30 || engineWarning == 14 ? true : false;

            #endregion


            if (DriverCarIdx != -9999)
            {
                position = e.TelemetryInfo.CarIdxPosition.Value[DriverCarIdx];
            }
        }
Пример #2
0
        private void UpdateDriverTelemetry(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (_isUpdatingDrivers)
            {
                return;
            }

            var offtrackUpdates = new List <Offtrack>();

            foreach (var driver in _drivers)
            {
                driver.Driver.UpdateLiveInfo(e.TelemetryInfo);

                // driver.Driver.Live.CalculateSpeed(_previousTelemetry, e.TelemetryInfo, _trackLength);

                //var offtrack = driver.Driver.OfftrackHistory.RegisterTrackStatus(driver.Driver.Live.TrackSurface,
                //    e.TelemetryInfo.SessionTime.Value);
                //if (offtrack != null) offtrackUpdates.Add(offtrack);
            }

            this.CalculateLivePositions();
            this.UpdateTimeDelta();

            bool isLive = IsReplayLive(e.TelemetryInfo.SessionTime.Value, e.TelemetryInfo.ReplaySessionTime.Value);

            this.UpdateLiveStatus(isLive);
            this.UpdateWatchedDriver(e.TelemetryInfo.CamCarIdx.Value);
            //if (offtrackUpdates.Count > 0) this.UpdateOfftrackHistory(offtrackUpdates);
        }
Пример #3
0
        private void OnPitEntry(SdkWrapper.TelemetryUpdatedEventArgs e, bool inPits, SessionStates sessionState)
        {
            var oldInPits = m_inPits;

            m_inPits = inPits;

            if (!oldInPits)
            {
                // Entering pit, send off command to set fuel.
                m_logger.Debug("Entering Pits");
                m_logger.Debug("\t- Current fuel: {0}", e.TelemetryInfo.FuelLevel);

                if (m_sessionRemainingTime > 0 && sessionState == SessionStates.Racing && m_fuelToAdd > 0.0)
                {
                    m_logger.Debug("\t- Adding {0} litres of fuel", m_fuelToAdd);

                    if (m_autoFuel)
                    {
                        m_logger.Debug("\t- AutoFuel enabled.");
                        m_wrapper.PitCommands.AddFuel(m_fuelToAdd);
                    }
                    else
                    {
                        m_logger.Debug("\t- AutoFuel disabled.");
                    }
                }
            }
        }
Пример #4
0
        private void UpdateFuelCalc(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var avgFuel = m_fuelPerLap * (double)nudFuelMult.Value;

            m_estimatedLaps = Math.Max((int)Math.Ceiling(m_sessionRemainingTime / m_averageLapTime), 0);

            m_lapsRemaining = Math.Min(m_estimatedLaps, m_telemLaps);

            m_totalFuelRequired = avgFuel * (m_lapsRemaining + (int)nudLapOffset.Value) - e.TelemetryInfo.FuelLevel.Value;

            if (m_totalFuelRequired > 0.0)
            {
                m_estimatedStops = (int)Math.Ceiling(m_totalFuelRequired / m_maxFuel);

                if ((m_totalFuelRequired + e.TelemetryInfo.FuelLevel.Value) <= m_maxFuel)
                {
                    m_fuelToAdd = (int)Math.Ceiling(m_totalFuelRequired);
                }
                else
                {
                    m_fuelToAdd = (int)Math.Ceiling(m_maxFuel - e.TelemetryInfo.FuelLevel.Value);
                }

                if ((cbUnits.SelectedIndex == Unit_Automatic && !m_is_metric_units) || cbUnits.SelectedIndex == Unit_UsCustomary)
                {
                    m_fuelToAdd = (int)Math.Ceiling(Math.Ceiling(m_fuelToAdd / LitresPerGallon) * LitresPerGallon);
                }
            }
            else
            {
                m_estimatedStops = 0;
                m_fuelToAdd      = 0;
            }
        }
Пример #5
0
        public void CarLeftRight(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var carLeftRight = _wrapper.GetData("CarLeftRight").ToString();


            switch (Int32.Parse(carLeftRight))
            {
            case 2:
                _dashForm.carLeftPanel.Visible = true;
                break;

            case 3:
                _dashForm.carRightPanel.Visible = true;
                break;

            case 5:
                _dashForm.carLeftPanel.Visible  = true;
                _dashForm.carRightPanel.Visible = true;
                break;

            default:
                _dashForm.carLeftPanel.Visible  = false;
                _dashForm.carRightPanel.Visible = false;
                break;
            }
        }
Пример #6
0
        // Example method that adds some caution flags to the string builder if they are displayed in the sim
        private void BitfieldsExample(StringBuilder sb, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // The value of SessionFlags returns a SessionFlag object which contains information about all currently active flags
            // Use the Contains method to check if it contains a specific flag.

            // EngineWarnings and CameraStates behave similarly.

            SessionFlag flags = e.TelemetryInfo.SessionFlags.Value;

            if (flags.Contains(SessionFlags.Black))
            {
                sb.AppendLine("Black flag!");
            }
            if (flags.Contains(SessionFlags.Disqualify))
            {
                sb.AppendLine("DQ");
            }
            if (flags.Contains(SessionFlags.Repair))
            {
                sb.AppendLine("Repair");
            }
            if (flags.Contains(SessionFlags.Checkered))
            {
                sb.AppendLine("Checkered");
            }
        }
Пример #7
0
        private void CalculateFuel(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            #region Gathering required variables to calculate fuel

            //required vars
            //remaining time, avg fuel usage, avg laptime
            var avgFuelUsage = GetAverageFromList(fuelUsagePerLap);
            var avgLapTime   = GetAverageFromList(laptimes);

            #endregion

            #region Calculate estimate laps

            var remainingLapsWithFuel = fuelLevel / avgFuelUsage;
            if (HasValue(remainingLapsWithFuel))
            {
                sessionForm.Laps_estimate_value.Text = string.Format("{0:0.00}", remainingLapsWithFuel);
            }

            #endregion

            #region Calculate fuel to fill

            var timeWithoutFuel = remainingTime - (avgLapTime * remainingLapsWithFuel);

            if (timeWithoutFuel > 0)
            {
                var minimumLapsToFill = Math.Floor(timeWithoutFuel / avgLapTime);
                var leftOverSeconds   = timeWithoutFuel % avgLapTime;

                //calculate fuel for leftover seconds
                var fillForLeftover = (leftOverSeconds / (avgLapTime / 100)) * (avgFuelUsage / 100);

                if (HasValue(minimumLapsToFill) && HasValue(fillForLeftover))
                {
                    var toFill = (minimumLapsToFill * avgFuelUsage) + fillForLeftover + Math.Ceiling(avgFuelUsage) +
                                 1; //+1 liter for safety

                    sessionForm.Fuel_to_fill_value.Text = toFill > maxFuelOfCar
                        ? string.Format("{0:0.00}", maxFuelOfCar)
                        : string.Format("{0:0.00}", toFill);
                }
            }
            else
            {
                sessionForm.Fuel_to_fill_value.Text = "CHCK";
            }

            if (!HasValue(timeWithoutFuel))
            {
                sessionForm.Fuel_to_fill_value.Text = "N/A";
            }

            #endregion

            #region Calculate if fuel is enough/not to finish line respectively
            CalculateFuelTillFinishLine(remainingTime, avgFuelUsage, avgLapTime, timeWithoutFuel,
                                        remainingLapsWithFuel);
            #endregion
        }
Пример #8
0
        private static void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var stopwatch = Stopwatch.StartNew();

            const int IndicatorHalfWidth = 4;
            var       shftInd            = e.TelemetryInfo.ShiftIndicatorPct.Value;

            shftInd = shftInd.Remap(0, 1, 0, IndicatorHalfWidth);

            Console.SetCursorPosition(0, 0);

            Console.Write("Indicator:\t\t");

            byte indicator = 0;

            for (var i = 0; i < IndicatorHalfWidth * 2; i++)
            {
                indicator = (byte)(indicator << 1);
                if (i < shftInd.RoundToInt() || i >= (IndicatorHalfWidth * 2) - shftInd.RoundToInt())
                {
                    indicator |= 1;
                }
            }

            Console.WriteLine(Convert.ToString(indicator, 2).PadLeft(8, '0'));

            driver.Send(new DigitalWriteRequest(10, DigitalValue.Low));
            driver.Send(new ShiftOutRequest(12, 11, BitOrder.MSBFIRST, indicator));
            driver.Send(new DigitalWriteRequest(10, DigitalValue.High));

            stopwatch.Stop();

            Console.WriteLine($"Bitshift duration:\t{stopwatch.ElapsedMilliseconds} ms");
        }
Пример #9
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            currentRpm         = e.TelemetryInfo.RPM.Value;
            this.telemetryInfo = e;

            try
            {
                switch (wrapper.GetTelemetryValue <int>("SessionFlags").Value)
                {
                case 32:
                    flag = (int)Constants.FLAG_TYPE.BLUE_FLAG;
                    break;

                case 8:
                    flag = (int)Constants.FLAG_TYPE.YELLOW_FLAG;
                    break;

                default:
                    flag = (int)Constants.FLAG_TYPE.NO_FLAG;
                    break;
                }

                flag = ((int)wrapper.GetTelemetryValue <int>("EngineWarnings").Value & 0x10) == 0x10 ? (int)Constants.FLAG_TYPE.SPEED_LIMITER : flag;
            }
            catch (Exception ex)
            {
                logger.LogExceptionToFile(ex);
            }
        }
Пример #10
0
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            _telemetry = e.TelemetryInfo;

            try
            {
                App.Instance.Dispatcher.Invoke(() =>
                {
                    // Handle telemetry update
                    this.UpdateDriverTelemetry(e);

                    // Update session data
                    this.SessionData.Update(e.TelemetryInfo);

                    // Broadcast to windows
                    if (this.TelemetryUpdated != null)
                    {
                        this.TelemetryUpdated(sender, e);
                    }
                });
            }
            catch (Exception ex)
            {
                App.Instance.LogError("Updating telemetry.", ex);
            }

            _previousTelemetry = e.TelemetryInfo;
        }
Пример #11
0
        public void OnTelemetryUpdate(Object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // there is apparently nothing in the telemetry data to tell us the session identifier
            // (meaning the session id that would be displayed in iRacing results); the session
            // identifers in the telemetry seem be as follows:
            //   SessionNum      --> an index into the Sessions in the SessionInfo
            //   SessionUniqueId --> I've only seen the number 1 so far in an official practice
            // this means we can't know the sessionLogPath until it has been calculated by the
            // first session info update so can log no telemetry updates until that occurs; in
            // practice this seems to be fine
            if (record && sessionLogPath != null)
            {
                // NOTE: we only record fields which we've exposed in ITelemetryInfo for two reasons.
                // First, there is no way to simply get a copy of the whole binary record from iRSDKSharp,
                // so we'd have to loop across all the fields by name and read each one (we do a subset of
                // this of course in the solution below, but only on a smallish number of fields).
                // A second reason is simply to keep our session log file as small as possible.
                using (BinaryWriter w = AppendBinary(sessionLogPath))
                {
                    w.Write(2); // telemetry update record identifier
                    w.Write(e.TelemetryInfo.SessionFlags.Value.Value);
                    w.Write(e.TelemetryInfo.SessionNum.Value);
                    w.Write(e.TelemetryInfo.SessionUniqueID.Value);
                    w.Write(e.TelemetryInfo.SessionTimeRemain.Value);
                    w.Write(wrapper.GetTelemetryValue <int>("SessionLapsRemain").Value);
                }
            }

            telemetryUpdateHandlers.ForEach(
                h => h.Invoke(sender, new TelemetryUpdatedEventProxy(
                                  new TelemetryInfoProxy(wrapper, e.TelemetryInfo))));
        }
Пример #12
0
 private void NewLapCalculation(SdkWrapper.TelemetryUpdatedEventArgs e)
 {
     //NewLapSettings(e);
     //UpdateLapTimeV2(e);
     //CalculateDeltaV2(e);
     //CalculateFuelUsagePerLap(e);
 }
Пример #13
0
        public void CalculateDeltaV2(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var deltaObject = _wrapper.GetData("LapDeltaToSessionBestLap");
            var deltaInt    = Convert.ToDouble(deltaObject);

            if (deltaInt > 0 && deltaInt < 99.99)
            {
                _dashForm.delta_panel.BackColor = Color.Firebrick;
                _dashForm.Delta_value.Text      = string.Format("{0:+0.00}", deltaInt);
            }
            else if (deltaInt < 0 && deltaInt > -99.99)
            {
                _dashForm.delta_panel.BackColor = Color.Green;
                _dashForm.Delta_value.Text      = string.Format("{0:0.00}", deltaInt);
            }
            else if (deltaInt == 0)
            {
                _dashForm.delta_panel.BackColor = Color.FromArgb(255, 40, 40, 40);
                _dashForm.Delta_value.Text      = string.Format("{0:0.00}", deltaInt);
            }
            else if (deltaInt >= 99.99)
            {
                _dashForm.delta_panel.BackColor = Color.Firebrick;
                _dashForm.Delta_value.Text      = "+99.99";
            }
            else if (deltaInt <= -99.99)
            {
                _dashForm.delta_panel.BackColor = Color.Green;
                _dashForm.Delta_value.Text      = "-99.99";
            }
        }
Пример #14
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            float TCValue = 99;

            try
            {
                var tcVar = wrapper.GetTelemetryValue <float>("dcTractionControl");
                TCValue = tcVar.Value;
                if (TCValue < 0)
                {
                    TCValue = 99;
                }
            }
            catch {}

            float BBValue = 99;

            try
            {
                var bbVar = wrapper.GetTelemetryValue <float>("dcBrakeBias");
                BBValue = bbVar.Value;
                if (BBValue < 10)
                {
                    BBValue = 99;
                }
            }
            catch {}

            dataParser.ParseTelemetry(e, (int)TCValue, Math.Round(BBValue, 2));

            displayConnection.SendMessage(dataParser.GetDisplayString(), dataParser.GetLedAmount(), dataParser.GetDotBin());
        }
        public override void OnTelemetryUpdated(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
#if !DEBUG
            this.SessionTime       = e.TelemetryInfo.SessionTime.Value;
            this.ReplaySessionTime = e.TelemetryInfo.ReplaySessionTime.Value;
            this.UpdateEvents();
#endif
        }
Пример #16
0
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            this.CurrentSessionNumber = e.TelemetryInfo.SessionNum.Value;

            if (this.TelemetryUpdated != null)
            {
                this.TelemetryUpdated(this, e);
            }
        }
Пример #17
0
        private void CalculateFuelUsagePerLap(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (isItNewLap())
            {
                var actualFuelLevel = e.TelemetryInfo.FuelLevel.Value;

                InitFuelOnLapStart(actualFuelLevel);
                DisplayLastLapUsage(actualFuelLevel);
            }
        }
Пример #18
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            TelemetryData teleData = new TelemetryData(e.UpdateTime,
                                                       e.TelemetryInfo.Speed.Value,
                                                       e.TelemetryInfo.RPM.Value,
                                                       e.TelemetryInfo.Gear.Value,
                                                       e.TelemetryInfo.ShiftIndicatorPct.Value);

            hostWindow.TelemetryRecieved(teleData);
        }
Пример #19
0
        // Example method that adds speed and roll values to the string builder
        private void TelemetryExample(StringBuilder sb, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Important distinction: TelemetryInfo.Speed (for example) returns an object of type TelemetryValue.
            // This object contains more than just the value; also the unit, name and a description.
            // To get just the value, you use the Value property.
            // This goes for every property of the TelemetryInfo class.

            sb.AppendLine("Speed: " + e.TelemetryInfo.Speed.Value);      // Without unit
            sb.AppendLine("Speed: " + e.TelemetryInfo.Speed.ToString()); // with unit
            sb.AppendLine("Roll: " + e.TelemetryInfo.Roll.ToString());
        }
Пример #20
0
        protected override void FlashFlags(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var sessionFlag = e.TelemetryInfo.SessionFlags.Value?.ToString();

            if (sessionFlag == null)
            {
                return;
            }

            var sessionFlags = (SessionFlags)Enum.Parse(typeof(SessionFlags), sessionFlag.Replace('|', ','));

            switch (sessionFlags)
            {
            case var t when t.HasFlag(SessionFlags.Repair):
                LightPanel(sessionForm.warning_panel, Color.Black);

                break;

            case var t when t.HasFlag(SessionFlags.Blue):
                LightPanel(sessionForm.warning_panel, Color.Blue);

                break;

            case var t when t.HasFlag(SessionFlags.Yellow):
            case var t1 when t1.HasFlag(SessionFlags.Caution):
            case var t2 when t2.HasFlag(SessionFlags.CautionWaving):
            case var t3 when t3.HasFlag(SessionFlags.YellowWaving):
                LightPanel(sessionForm.warning_panel, Color.Yellow);

                break;

            case var t when t.HasFlag(SessionFlags.Green):
                raceStarted = true;

                raceStartLap = currentLap;
                LightPanel(sessionForm.warning_panel, Color.Green);
                break;

            case var t1 when t1.HasFlag(SessionFlags.GreenHeld):
            case var t2 when t2.HasFlag(SessionFlags.OneLapToGreen):
                LightPanel(sessionForm.warning_panel, Color.Green);

                break;

            case var t when t.HasFlag(SessionFlags.White):
                LightPanel(sessionForm.warning_panel, Color.White);

                break;

            default:
                sessionForm.warning_panel.BackColor = Color.Transparent;
                break;
            }
        }
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            telemetry = e.TelemetryInfo;

            if (telemetry.IsOnTrack.Value == oldIsOnTrack)
            {
                return;
            }

            ChangeScene();
            oldIsOnTrack = telemetry.IsOnTrack.Value;
        }
Пример #22
0
        public void UpdateLapTimeV2(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            var lapObject = _wrapper.GetData("LapCurrentLapTime");
            var lap       = Convert.ToDouble(lapObject);

            int    min = (int)(lap / 60);
            double sec = (lap % 60);
            string laptime;

            laptime = string.Format("{0:00}:{1:00.000}", min, sec);
            _dashForm.Laptime_value.Text = laptime;
        }
Пример #23
0
        private void SdkOnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            // Cache info
            _telemetry = e.TelemetryInfo;

            _isReplay = e.TelemetryInfo.IsReplayPlaying.Value;

            // Check if session changed
            if (_currentSessionNumber == null || (_currentSessionNumber.Value != e.TelemetryInfo.SessionNum.Value))
            {
                _mustUpdateSessionData = true;

                // Session changed, reset session info
                this.ResetSession();
            }

            // Store current session number
            _currentSessionNumber = e.TelemetryInfo.SessionNum.Value;

            // Get previous state
            var sessionWasFinished = this.SessionData.IsFinished;
            var prevFlags          = this.SessionData.Flags;

            // Update session state
            _sessionData.UpdateState(e.TelemetryInfo.SessionState.Value);

            // Update drivers telemetry
            this.UpdateDriverTelemetry(e.TelemetryInfo);

            // Update session data
            this.SessionData.Update(e.TelemetryInfo);

            // Check if flags updated
            this.CheckSessionFlagUpdates(prevFlags, this.SessionData.Flags);

            if (!sessionWasFinished && this.SessionData.IsFinished)
            {
                // If session just finished, get winners
                // Use result position (not live position)
                var winners =
                    Drivers.Where(d => d.CurrentResults != null && d.CurrentResults.ClassPosition == 1).OrderBy(d => d.CurrentResults.Position);
                foreach (var winner in winners)
                {
                    var ev = new WinnerRaceEvent();
                    ev.Driver      = winner;
                    ev.SessionTime = _telemetry.SessionTime.Value;
                    ev.Lap         = winner.Live.Lap;
                    this.OnRaceEvent(ev);
                }
            }
            this.OnTelemetryUpdated(e);
        }
Пример #24
0
        // Event handler called when the telemetry is updated
        // This happens (max) 60 times per second
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            telemetryLabel.Text = string.Format("Telemetry (last updated {0})", DateTime.Now.TimeOfDay.ToString());

            // Let's just write some random values:
            StringBuilder sb = new StringBuilder();

            this.TelemetryExample(sb, e);
            this.ArrayExample(sb, e);
            this.BitfieldsExample(sb, e);

            telemetryTextBox.Text = sb.ToString();
        }
Пример #25
0
 private void CarLeftRightCheck(SdkWrapper.TelemetryUpdatedEventArgs e)
 {
     if (wrapper.GetData("CarLeftRight") != null)
     {
         _carLR = wrapper.GetData("CarLeftRight").ToString();
         if (_carLR == null)
         {
             //do nothing... shouldn't get here
         }
         else if (_carLR == "0")
         {
             //do nothing... spotter disabled
         }
         else if (_carLR == "1")
         {
             //All clear
             CarLeftIndicator.Fill  = Brushes.Transparent;
             CarRightIndicator.Fill = Brushes.Transparent;
         }
         else if (_carLR == "2")
         {
             //1 car left
             CarLeftIndicator.Fill  = singleColor;
             CarRightIndicator.Fill = Brushes.Transparent;
         }
         else if (_carLR == "3")
         {
             //1 car right
             CarRightIndicator.Fill = singleColor;
             CarLeftIndicator.Fill  = Brushes.Transparent;
         }
         else if (_carLR == "4")
         {
             //cars on each side
             CarLeftIndicator.Fill  = middleColor;
             CarRightIndicator.Fill = middleColor;
         }
         else if (_carLR == "5")
         {
             //2(+?) cars left
             CarLeftIndicator.Fill  = doubleColor;
             CarRightIndicator.Fill = Brushes.Transparent;
         }
         else if (_carLR == "6")
         {
             //2(+?) cars right
             CarRightIndicator.Fill = doubleColor;
             CarLeftIndicator.Fill  = Brushes.Transparent;
         }
     }
 }
Пример #26
0
        public void CarSettingPanelFlash <T>(SdkWrapper.TelemetryUpdatedEventArgs e, ref T actualValue, ref T valueTemp,
                                             string title)
        {
            #region Set Traction Control TC1, TC2, Boost

            try
            {
                if (!actualValue.Equals(valueTemp))
                {
                    if (sessionDash.settingLabelTitle.Visible == false)
                    {
                        settingPanelFpsCounter = 0;
                    }

                    //panelek megjelenitése
                    if (settingPanelFpsCounter <= (int)(sessionWrapper.TelemetryUpdateFrequency / settingPanelFps))
                    {
                        sessionDash.settingLabelTitle.Text = title;
                        if (actualValue.GetType() == typeof(float))
                        {
                            sessionDash.settingLabelValue.Text = string.Format("{0:0.00}", actualValue);
                        }
                        else
                        {
                            sessionDash.settingLabelValue.Text = actualValue.ToString();
                        }


                        //settingsPanel.Visible = true;
                        sessionDash.settingLabelTitle.Visible = true;
                        sessionDash.settingLabelValue.Visible = true;
                    }
                    else
                    {
                        //settingsPanel.Visible = false;
                        sessionDash.settingLabelTitle.Visible = false;
                        sessionDash.settingLabelValue.Visible = false;
                        settingPanelFpsCounter = 0;
                        valueTemp = actualValue;
                    }
                }
            }
            catch (Exception ex)
            {
                sessionDash.settingLabelTitle.Text = title;
                sessionDash.settingLabelValue.Text = "N/A";
            }

            #endregion
        }
Пример #27
0
        // Event handler called when the telemetry is updated
        private void wrapper_TelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (connection.isOpen())
            {
                dataPacket data = new dataPacket(console);
                data.fetch(e.TelemetryInfo, wrapper.Sdk, fuelEst, chkBrake.Checked ? brk.getBrakeVibe(e.TelemetryInfo, trkTol.Value, trkSens.Value) : 0,
                           sendTimeReset, sendTime, prevFuel);
                connection.send(data.compile(this.cboSpdUnit.SelectedIndex == 0, this.trkIntensity.Value));
                sendTime      = false;
                sendTimeReset = false;

                float ll = Convert.ToSingle(wrapper.Sdk.GetData("LapLastLapTime"));

                if (ll != prevLapTime)
                {
                    if (prevFuel != 0 && ll > 0)
                    {
                        sendTime    = true;
                        prevLapTime = ll;
                    }
                }

                if (e.TelemetryInfo.Lap.Value > prevLap)
                {
                    sendTimeReset = true;
                    estimateFuel(e.TelemetryInfo);
                    prevLap = e.TelemetryInfo.Lap.Value;
                }

                if (wrapper.GetTelemetryValue <Boolean[]>("CarIdxOnPitRoad").Value[driverID])
                {
                    prevFuel = 0;
                }
            }

            if (ticker % 5 == 0)
            {
                printTelemInfo(e.TelemetryInfo);
                ticker += 1;
            }

            if (ticker == 40)
            {
                ticker = 0;
            }
            else
            {
                ticker += 1;
            }
        }
Пример #28
0
        private void CalculateFuelUsagePerLap(SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            //új kör esetén
            if (lapCount - lapCountTemp == 1)
            {
                var actualFuelLevel = e.TelemetryInfo.FuelLevel.Value;

                if (fuelLapStart != -1 && fuelLapStart - actualFuelLevel > 0)
                {
                    fuelUsagePerLap.Add(fuelLapStart - actualFuelLevel);
                }


                #region fuelLapStart init
                if (fuelLapStart == -1)
                {
                    fuelLapStart = actualFuelLevel;

                    fuelUsageLogger = new Logger(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\iRacingDash\\logs\\iRacingDash\\" + dateInString + "_W" + raceWeek + "_" + eventType + "_" + trackName + "\\fuelUsage.txt");
                    fuelUsageLogger.Log("Init",
                                        "Lap number:  " + lapCount + Environment.NewLine + "  fuelLapStart: " + fuelLapStart);
                    return;
                }
                #endregion

                var lapStartEndFuelDifference = fuelLapStart - actualFuelLevel;

                if (lapStartEndFuelDifference > 0)
                {
                    sessionForm.Last_lap_value.Text      = string.Format("{0:0.00}", lapStartEndFuelDifference);
                    sessionForm.Last_lap_value.ForeColor = Color.FromArgb(255, 128, 0);
                }
                else
                {
                    sessionForm.Last_lap_value.ForeColor = Color.Yellow;
                }


                fuelUsageLogger.Log("Difference", "Lap number: " + lapCount +
                                    Environment.NewLine + "  fuelLapStart: " + fuelLapStart +
                                    Environment.NewLine + "  actualFuelLevel: " + actualFuelLevel +
                                    Environment.NewLine + "  lapStartEndFuelDifference: " +
                                    lapStartEndFuelDifference +
                                    Environment.NewLine + "  fuelLapStart is set to actualFuelLevel" +
                                    Environment.NewLine + "FuelUsagePerLap: " + string.Join(",", fuelUsagePerLap));

                fuelLapStart = actualFuelLevel;
            }
        }
Пример #29
0
 protected void CalculateGear(SdkWrapper.TelemetryUpdatedEventArgs e)
 {
     gearValue = e.TelemetryInfo.Gear.Value;
     if (gearValue == -1)
     {
         sessionForm.gear.Text = "R";
     }
     else if (gearValue == 0)
     {
         sessionForm.gear.Text = "N";
     }
     else
     {
         sessionForm.gear.Text = gearValue.ToString();
     }
 }
Пример #30
0
        public void TestOnTelemetryUpdate_SupportsMultipleCallbacks()
        {
            var mockHandler1 = new Mock <EventHandler <ITelemetryUpdatedEvent> >();
            var mockHandler2 = new Mock <EventHandler <ITelemetryUpdatedEvent> >();

            proxy.AddTelemetryUpdateHandler(mockHandler1.Object);
            proxy.AddTelemetryUpdateHandler(mockHandler2.Object);

            var info = new TelemetryInfo(wrapper.Sdk);
            var evt  = new SdkWrapper.TelemetryUpdatedEventArgs(info, 0.0);

            proxy.OnTelemetryUpdate(this, evt);

            mockHandler1.Verify(h => h.Invoke(this, It.IsAny <ITelemetryUpdatedEvent>()), Times.Once());
            mockHandler2.Verify(h => h.Invoke(this, It.IsAny <ITelemetryUpdatedEvent>()), Times.Once());
        }