public PropertyBox() { // Listen to G25 g25 = new Joystick(JoystickDevice.Search("G25")[0]); g25.Press += new JoystickButtonEvent(g25_Press); g25.Release += new JoystickButtonEvent(g25_Release); _mButtonRepeater = new Thread(ButtonRepeat); _mButtonRepeater.IsBackground = true; _mButtonRepeater.Start(); }
public Gauge_A1GP(Joystick j) { Counter = 0; if (j != null) { joy = j; j.Release += j_Release; } InitializeComponent(); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); t = new Timer{Interval=500, Enabled=true}; t.Tick += t_Tick; t.Start(); Telemetry.m.Session_Start += PaintBackground; Telemetry.m.Session_Stop += PaintBackground; Telemetry.m.Driving_Start += PaintBackground; _EmptyGauges = new Bitmap(this.Size.Width, this.Size.Height); }
private void j_Release(Joystick joystick, int button) { if(Counter == 10 && button == LiveTelemetry.Joystick_Button) { Counter = 0; LiveTelemetry.StatusMenu = 0; } }
static void Main(string[] args) { ThrottleMap = new Dictionary<double, Dictionary<double, double>>(); var throttles = new List<double>(new double[] {0,0, 10, 20, 30, 40, 50, 60, 70, 80 , 90 , 100}); string[] data = File.ReadAllLines("../../../Binaries/Map.csv"); foreach(string line in data) { string[] cols = line.Split(','); double rpm = double.Parse(cols[0]); var map = new Dictionary<double, double>(); for (int i = 1; i < cols.Length; i++) map.Add(throttles[i]/100.0, double.Parse(cols[i])/100.0); ThrottleMap.Add(rpm, map); } StringBuilder test = new StringBuilder(); for (double rpm =10000; rpm <= 18000; rpm+= 10) { test.Append(rpm); for (double throttle = 50; throttle<=50; throttle+= 1) { double t = GetThrottle(rpm/18000, throttle/100); test.Append("," + t); } test.AppendLine(); } File.WriteAllText("out.csv", test.ToString()); var rfactor = new Simulator(); rfactor.Initialize(); var g25s = JoystickDevice.Search("G25"); if(g25s.Count == 1) { double p = 0; JoystickDevice g25d = g25s[0]; VirtualJoystick ppjoy1 = new VirtualJoystick(VirtualJoystick.PPJOY_1); Joystick g25 = new Joystick(g25d); System.Threading.Thread.Sleep(50); bool FunnyRevLimit = false; while(true) { List<double> a = new List<double>(); for (int i = 0; i < 24; i++) { a.Add(g25.GetAxis(i)); } double throttle = 1 - (g25.GetAxis(2) / ((float)0xFFFF)); double rpm = rfactor.Player.Engine_RPM / 0.10471666666666666666666666666667; double rpm_max = rfactor.Player.Engine_RPM_Max_Live / 0.10471666666666666666666666666667; double rpm_funny = rpm_max - 500; int gear = rfactor.Player.Gear; double rpm_factor = rpm/rpm_max; if (FunnyRevLimit) { if (rpm > rpm_funny) throttle = 0; } else { if (rpm_factor >= 1) throttle = 0; } throttle = GetThrottle(rpm_factor, throttle); List<double> axis = new List<double>(); axis.Add(throttle); for(int i = 0; i < 7; i++) axis.Add(0); List<bool> buttons = new List<bool>(); for(int i = 0; i < 16; i++) buttons.Add(false); //axis[0] = p; p = 1 - p; ppjoy1.PostData(axis, buttons); System.Threading.Thread.Sleep(5); // This can be removed at a later stage. if (FunnyRevLimit && rpm > rpm_funny) System.Threading.Thread.Sleep(75); if (Console.KeyAvailable) { Console.ReadKey(); if(FunnyRevLimit) Console.WriteLine("Funny rev limit OFF"); else { Console.WriteLine("Funny rev limit ON"); } FunnyRevLimit = !FunnyRevLimit; } } } }
void g25_Press(Joystick joystick, int button) { ButtonsHolding.Add(button); Press(button); }
void g25_Release(Joystick joystick, int button) { ButtonsHolding.Remove(button); }
/// <summary> /// Initializes for the window. This setups the data back-end framework, as well searches for joystick /// configuration. Set-ups interface controls. /// </summary> public LiveTelemetry() { // Use EN-US for compatibility with functions as Convert.ToDouble etc. // This is mainly used within track parsers. Application.CurrentCulture = new CultureInfo("en-US"); if(false) { TelemetryViewer t = new TelemetryViewer(); t.ShowDialog(); return; } // Boot up the telemetry service. Wait for it to start and register events that trigger interface changes. Telemetry.m.Run(); while (Telemetry.m.Sims == null) System.Threading.Thread.Sleep(1); Telemetry.m.Sim_Start += mUpdateUI; Telemetry.m.Sim_Stop += mUpdateUI; Telemetry.m.Session_Start += mUpdateUI; Telemetry.m.Session_Stop += mUpdateUI; System.Threading.Thread.Sleep(500); if (Telemetry.m.Sim != null) Telemetry.m.Sim.Garage.Scan(); // TODO: Detect hardware devices (COM-ports or USB devices) // GameData is used for my own hardware extension projects. // Race dashboard: // https://dl.dropbox.com/u/207647/IMAG0924.jpg // https://dl.dropbox.com/u/207647/IMAG1204.jpg // Switchboard: // https://dl.dropbox.com/u/207647/IMAG0928.jpg // https://dl.dropbox.com/u/207647/IMAG0934.jpg //GameData g = new GameData(); // Form of singleton for public StatusMenu access. _liveTelemetry = this; // Read joystick configuration. if(File.Exists("config.txt") == false) { // TODO: Needs fancy dialogs to first-time setup. File.Create("config.txt"); MessageBox.Show( "Please edit config.txt:\r\ncontroller=[your controller you want to use for cyclign through panels]\r\nbutton=[the button on the controller you want to use]\r\n\r\nJust type the name of your controller (G25 alone is enough usually) and look up the button in Devices -> Game Controllers."); }else { string[] lines = File.ReadAllLines("config.txt"); string controller = ""; bool controlleruseindex = false; int controllerindex = 0; foreach (string line in lines) { string[] p = line.Trim().Split("=".ToCharArray()); if (line.StartsWith("button")) Joystick_Button = Convert.ToInt32(p[1]); if (line.StartsWith("index")) { controlleruseindex = true; controllerindex = Convert.ToInt32(p[1]); } if (line.StartsWith("controller")) controller = p[1]; } // Search for the joystick. List<JoystickDevice> devices = JoystickDevice.Search(); if (devices.Count == 0) { //MessageBox.Show("No (connected) joystick found for display panel control.\r\nTo utilize this please connect a joystick, configure and restart this program."); } else { if (controlleruseindex) { Joystick_Instance = new Joystick(devices[controllerindex]); Joystick_Instance.Release += Joy_Release; } else { int i = 0; foreach (JoystickDevice jd in devices) { if (jd.Name.Contains(controller.Trim())) { Joystick_Instance = new Joystick(jd); Joystick_Instance.Release += Joy_Release; } i++; } } } } // Set-up the main interface. FormClosing += LiveTelemetry_FormClosing; SizeChanged += Telemetry_ResizePanels; InitializeComponent(); this.SuspendLayout(); BackColor = Color.Black; ucLaps = new Gauge_Laps(); ucSplits = new Gauge_Splits(); ucA1GP = new Gauge_A1GP(Joystick_Instance); ucTyres = new Gauge_Tyres(); ucSessionData = new ucSessionInfo(); ucTrackmap = new LiveTrackMap(); ucLapChart = new LapChart(); btGarage = new Button(); btNetwork = new Button(); btSettings = new Button(); // Garage button btGarage.Text = "Garage"; btGarage.Size = new Size(75, 25); btGarage.BackColor = Color.White; btGarage.Location = new Point(10, 10); btGarage.Click += new EventHandler(btGarage_Click); // Settings button btSettings.Text = "Settings"; btSettings.Size = new Size(75, 25); btSettings.BackColor = Color.White; btSettings.Location = new Point(95, 10); btSettings.Click += new EventHandler(btSettings_Click); // Network btNetwork.Text = "Network"; btNetwork.Size = new Size(75, 25); btNetwork.BackColor = Color.White; btNetwork.Location = new Point(180, 10); btNetwork.Click += new EventHandler(btNetwork_Click); // Timers Tmr_HiSpeed = new Timer{Interval=20}; // 30fps Tmr_MdSpeed = new Timer{Interval = 450}; // ~2fps Tmr_LwSpeed = new Timer{Interval=1000}; // 1fps Tmr_HiSpeed.Tick += Tmr_HiSpeed_Tick; Tmr_MdSpeed.Tick += Tmr_MdSpeed_Tick; Tmr_LwSpeed.Tick += Tmr_LwSpeed_Tick; Tmr_HiSpeed.Start(); Tmr_MdSpeed.Start(); Tmr_LwSpeed.Start(); System.Threading.Thread.Sleep(500); #if DEBUG // This is for hardware peripheral support new GameData(); #endif SetupUI(); this.ResumeLayout(false); }
/// <summary> /// This method listens for joystick button releases and updates the StatusMenu property. /// This will in turn update the user interface. /// </summary> /// <param name="joystick">Joystick class from which the event was wired.</param> /// <param name="button">The button that was released.</param> private void Joy_Release(Joystick joystick, int button) { if (button == Joystick_Button) { StatusMenu++; } }