Exemple #1
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (m_maxFuel < 0.1)
            {
                m_wrapper.RequestSessionInfoUpdate();
            }

            var inPits = m_wrapper.GetTelemetryValue <bool>("OnPitRoad").Value;

            m_is_metric_units = m_wrapper.GetTelemetryValue <int>("DisplayUnits").Value == 1;
            var sessionState = e.TelemetryInfo.SessionState.Value;
            var lastLapId    = e.TelemetryInfo.LapCompleted.Value;

            var flag = e.TelemetryInfo.SessionFlags.Value;

            if (flag.Contains(SessionFlags.Green) && !m_isGreen)
            {
                m_isGreen = true;
                m_logger.Debug("Green Flag!");
            }
            else if (flag.Contains(SessionFlags.Caution) || flag.Contains(SessionFlags.CautionWaving) && m_isGreen)
            {
                m_isGreen = false;
                m_logger.Debug("Caution Flag!");
            }

            m_sessionRemainingTime = e.TelemetryInfo.SessionTimeRemain.Value;
            UpdateFuelCalc(e);

            if (lastLapId > 0 && m_lastLapCompleted != lastLapId)
            {
                m_lastLapCompleted = lastLapId;
                OnNewLap(e, inPits, sessionState);
            }

            if (m_inPits != inPits)
            {
                OnPitEntry(e, inPits, sessionState);
            }

            UpdateLabels();
        }
Exemple #2
0
        private void OnTelemetryUpdated(object sender, SdkWrapper.TelemetryUpdatedEventArgs e)
        {
            if (m_maxFuel < 0.1)
            {
                m_wrapper.RequestSessionInfoUpdate();
            }

            var inPits       = m_wrapper.GetTelemetryValue <bool>("OnPitRoad").Value;
            var sessionState = e.TelemetryInfo.SessionState.Value;
            var lastLapId    = e.TelemetryInfo.LapCompleted.Value;

            if (lastLapId > 0 && m_lastLapCompleted != lastLapId)
            {
                m_lastLapCompleted     = lastLapId;
                m_sessionRemainingTime = e.TelemetryInfo.SessionTimeRemain.Value;

                var fuelLevel = e.TelemetryInfo.FuelLevel.Value;
                var laptime   = m_wrapper.GetTelemetryValue <float>("LapLastLapTime").Value;
                var flag      = e.TelemetryInfo.SessionFlags.Value;

                m_logger.Debug("Lap Completed {0}", m_lastLapCompleted);
                m_logger.Debug("\t- Time: {0}", laptime);
                m_logger.Debug("\t- Fuel Level: {0}", fuelLevel);

                if (m_lastFuelLevel >= fuelLevel && !inPits)
                {
                    var fuelDelta = m_lastFuelLevel - fuelLevel;
                    if (!cbOnlyGreen.Checked || (cbOnlyGreen.Checked && sessionState == SessionStates.Racing && flag.Contains(SessionFlags.Green)))
                    {
                        m_lapTimes.Add(laptime);
                        m_fuelUsages.Add(fuelDelta);
                    }

                    m_fuelLastLap    = fuelDelta;
                    m_averageLapTime = GetAvg(m_lapTimes.Where(l => l > 0.0));
                    m_fuelPerLap     = GetAvg(m_fuelUsages);

                    var avgFuel = m_fuelPerLap * (double)nudFuelMult.Value;

                    m_estimatedLaps     = (int)Math.Ceiling(m_sessionRemainingTime / m_averageLapTime);
                    m_totalFuelRequired = avgFuel * (m_estimatedLaps + (int)nudLapOffset.Value);
                    m_estimatedStops    = (int)Math.Ceiling(m_totalFuelRequired / m_maxFuel);

                    var totalFuelThisStop = m_totalFuelRequired / m_estimatedStops;
                    m_fuelToAdd = (int)Math.Ceiling(totalFuelThisStop - e.TelemetryInfo.FuelLevel.Value);

                    m_logger.Debug("\t- Fuel Delta: {0}", fuelDelta);
                    m_logger.Debug("\t- Avg Laptime: {0}", m_averageLapTime);
                    m_logger.Debug("\t- Avg Fuel Delta: {0}", m_fuelPerLap);

                    m_logger.Debug("\t- Laps Remaining: {0}", m_estimatedLaps);
                    m_logger.Debug("\t- Total Fuel Required: {0}", m_totalFuelRequired);
                    m_logger.Debug("\t- Stops Remaining: {0}", m_estimatedStops);
                }

                m_lastFuelLevel = fuelLevel;

                UpdateLabels();
            }

            if (m_inPits != inPits)
            {
                var oldInPits = m_inPits;
                m_inPits = inPits;

                if (!oldInPits)
                {
                    // Entering pit, send off command to set fuel.
                    m_logger.Debug("Entering Pits");

                    if (m_sessionRemainingTime > 0 && m_averageLapTime > 0 && m_fuelPerLap > 0 && sessionState == SessionStates.Racing)
                    {
                        var fuelThisStop = (int)Math.Ceiling((m_totalFuelRequired / m_estimatedStops) - e.TelemetryInfo.FuelLevel.Value);
                        m_logger.Debug("\t- Adding {0} litres of fuel", fuelThisStop);

                        if (m_autoFuel)
                        {
                            m_logger.Debug("\t- AutoFuel enabled.");
                            m_wrapper.PitCommands.AddFuel(fuelThisStop);
                        }
                        else
                        {
                            m_logger.Debug("\t- AutoFuel disabled.");
                        }
                    }
                }
            }
        }