public void Update(F1Data data)
        {
            d_speed = Util.MPHtoKMH(data.Get("speed"));
            d_rpm   = data.Get("engineRate");

            float speed_degrees = Util.CalcDegrees(d_speed, start_range, end_range, MAX_SPEED);
            float rpm_degrees   = Util.CalcDegrees(d_rpm, start_range, end_range, MAX_RPM);

            this.UpdateSpeedLine(speed_degrees);
            this.UpdateRpmLine(rpm_degrees);
        }
Пример #2
0
        private void OnPacketReceived(byte[] packet)
        {
            prevData = data;
            data     = new F1Data(packet);
            // Calc
            float engineRate        = data.Get("engineRate");
            float engineRatePercent = Util.GetPercent(engineRate, 14000);

            float speed        = Util.MPHtoKMH(data.Get("speed"));
            float speedPercent = Util.GetPercent(speed, 100);

            float throttle        = data.Get("throttle");
            float throttlePercent = Util.GetPercent(throttle, 1);

            float brake        = data.Get("brake");
            float brakePercent = Util.GetPercent(brake, 1);

            // Update
            if (speed > speed_max)
            {
                speed_max = (int)speed;
            }
            if (prevData != null && data.Get("lap") != prevData.Get("lap"))
            {
                laps.Add(new Lap(prevData));
                foreach (Lap lap in laps)
                {
                    Console.WriteLine(lap.ToString());
                }
                Console.WriteLine("LAP: {0} LAP TIME: {1} LAP TIME: {2}", prevData.Get("lap"), prevData.Get("lapTime"), data.Get("last_lap_time"));
            }

            // Draw
            this.Dispatcher.Invoke(() =>
            {
                lbl_speed_max.Content     = String.Format("max: {0:N0} KM / h", speed_max);
                lbl_time.Content          = Formatter.Seconds(data.Get("time"));
                lbl_lapTime.Content       = Formatter.Seconds(data.Get("lapTime"));
                lbl_sector1_time.Content  = Formatter.Seconds(data.Get("sector1_time"));
                lbl_sector2_time.Content  = Formatter.Seconds(data.Get("sector2_time"));
                lbl_last_lap_time.Content = Formatter.Seconds(data.Get("last_lap_time"));
                pbar_throttle.Value       = throttlePercent;
                pbar_brake.Value          = brakePercent;

                sw_leds.Update(engineRate);
                sw_display.Update(data);
                speedometer.Update(data);

                sw_display.Draw();
            });
        }
        private List <Variable> LoadTableData(F1Data data)
        {
            List <Variable> vars = new List <Variable>();

            foreach (KeyValuePair <string, int> item in F1Data.VALUES)
            {
                vars.Add(new Variable()
                {
                    key   = item.Key,
                    value = data.Get(item.Key)
                });
            }

            return(vars);
        }
Пример #4
0
 public Lap(F1Data data)
 {
     time    = (float)data.Get("time");
     lapTime = (float)data.Get("lapTime");
 }
 public void Update(F1Data data)
 {
     this.d_gear     = Constants.GEARS[(int)data.Get("gear")];
     this.d_lap_time = Formatter.Seconds(data.Get("lapTime"));
 }
        private void OnPacketReceived(byte[] packet)
        {
            prevData = data;
            data     = new F1Data(packet);
            // Calc
            float engineRate        = (int)data.Get("engineRate");
            float engineRatePercent = engineRate * 100 / 14000;

            float speed        = (int)(data.Get("speed") * 3.6);
            float speedPercent = speed * 100 / 400;

            float throttle        = data.Get("throttle");
            float throttlePercent = throttle * 100 / 1;
            float brake           = data.Get("brake");
            float brakePercent    = brake * 100 / 1;

            // Update
            if (speed > speed_max)
            {
                this.speed_max = (int)speed;
            }

            // Draw
            this.Dispatcher.Invoke(() =>
            {
                this.lbl_rpm.Content           = String.Format("{0} RPM", engineRate, engineRatePercent);
                this.lbl_speed.Content         = String.Format("{0} KM/h", speed);
                this.lbl_speed_max.Content     = String.Format("max: {0} KM / h", speed_max);
                this.lbl_time.Content          = Formatter.Seconds(data.Get("time"));
                this.lbl_lapTime.Content       = Formatter.Seconds(data.Get("lapTime"));
                this.lbl_sector1_time.Content  = Formatter.Seconds(data.Get("sector1_time"));
                this.lbl_sector2_time.Content  = Formatter.Seconds(data.Get("sector2_time"));
                this.lbl_last_lap_time.Content = Formatter.Seconds(data.Get("last_lap_time"));
                this.pbar_rpm.Value            = engineRatePercent;
                this.pbar_speed.Value          = speedPercent;
                this.pbar_throttle.Value       = throttlePercent;
                this.pbar_brake.Value          = brakePercent;
                this.lbl_gear.Content          = Constants.GEARS[(int)data.Get("gear")];

                this.lbl_wheel_speed_bl.Content = data.Get("wheel_speed_bl");
                this.lbl_wheel_speed_br.Content = data.Get("wheel_speed_br");
                this.lbl_wheel_speed_fl.Content = data.Get("wheel_speed_fl");
                this.lbl_wheel_speed_fr.Content = data.Get("wheel_speed_fr");
                // this.dgrid_data.ItemsSource = LoadTableData(data);
            });
        }