protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); Window.AddFlags(WindowManagerFlags.KeepScreenOn); CrossCurrentActivity.Current.Init(this, bundle); Xamarin.Forms.Forms.Init(this, bundle); var container = InitDI(); _gameControllerService = container.Resolve <GameControllerService>(); var app = container.Resolve <App>(); LoadApplication(app); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); Window.AddFlags(WindowManagerFlags.KeepScreenOn); Platform.Init(this, bundle); Forms.SetFlags("SwipeView_Experimental"); Forms.Init(this, bundle); var container = InitDI(); _gameControllerService = container.Resolve <GameControllerService>(); var app = container.Resolve <App>(); LoadApplication(app); }
public async Task StartGameControllerTask() { var progressHandler = new Progress <GameControllerProgressArgs>(value => { if (value.Notification == GameControllerUpdateNotification.JoystickUpdate) { ProcessUpdate(value.Update); } else if (value.Notification == GameControllerUpdateNotification.ConnectedChanged) { ControllerConnected = GameControllerService.IsInstanceConnected(_OriginalController.Id); } }); var progress = progressHandler as IProgress <GameControllerProgressArgs>; _cts = new CancellationTokenSource(); var token = _cts.Token; try { await Task.Run(() => { System.Diagnostics.Debug.WriteLine("Game Controller Configuration task STARTED."); bool notResponding = false; // Initialize DirectInput using (var directInput = new DirectInput()) { while (true) { token.ThrowIfCancellationRequested(); try { // Instantiate the joystick using (Joystick joystick = new Joystick(directInput, _OriginalController.Id)) { joystick.Properties.Range = new InputRange(-500, 500); joystick.Properties.DeadZone = 2000; joystick.Properties.Saturation = 8000; // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // If configuring populate the joystick objects. if (_Controller.JoystickObjects.Count == 0) { foreach (DeviceObjectInstance doi in joystick.GetObjects()) { JoystickOffset offset; if (GameControllerService.USAGE_OFFSET.TryGetValue(doi.Usage, out offset)) { if (((int)doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0) { _Controller.JoystickObjects.Add(offset, doi.Name); } else if (((int)doi.ObjectId & (int)DeviceObjectTypeFlags.Button) != 0) { _Controller.JoystickObjects.Add(offset, doi.Name); } else if (((int)doi.ObjectId & (int)DeviceObjectTypeFlags.PointOfViewController) != 0) { _Controller.JoystickObjects.Add(offset, doi.Name); } } } } // Acquire the joystick joystick.Acquire(); while (true) { try { token.ThrowIfCancellationRequested(); joystick.Poll(); JoystickUpdate[] datas = joystick.GetBufferedData(); // Check for POV as this needs special handling to take the first value JoystickUpdate povUpdate = datas.Where(s => s.Offset == JoystickOffset.PointOfViewControllers0).OrderBy(s => s.Sequence).FirstOrDefault(); if (povUpdate.Timestamp > 0) { if (progress != null) { progress.Report(new GameControllerProgressArgs(povUpdate)); } } else { foreach (JoystickUpdate state in datas.Where(s => s.Value != -1)) // Just take the down clicks not the up. { if (progress != null) { progress.Report(new GameControllerProgressArgs(state)); } } } if (notResponding) { notResponding = false; progress.Report(new GameControllerProgressArgs()); } } catch (SharpDX.SharpDXException) { notResponding = true; progress.Report(new GameControllerProgressArgs()); Thread.Sleep(2000); break; } } } } catch (SharpDX.SharpDXException) { notResponding = true; progress.Report(new GameControllerProgressArgs()); Thread.Sleep(2000); } } } }); } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine("Game Controller Configuration task CANCELLED."); } }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> /// public GameControllerViewModel(GameController gameController) { _OriginalController = gameController; PopProperties(); ControllerConnected = GameControllerService.IsInstanceConnected(_OriginalController.Id); }
public DialogService(Activity context, GameControllerService gameControllerService) { _context = context; _gameControllerService = gameControllerService; }
public GameControllerEventDialog(Context context, GameControllerService gameControllerService) : this(context) { _gameControllerService = gameControllerService; }
public void StartGameControllerTask() { var progressHandler = new Progress <GameControllerProgressArgs>(value => { if (value.Notification == GameControllerUpdateNotification.ConnectedChanged) { ControllerConnected = GameControllerService.IsInstanceConnected(_PoledController.Id); } else if (value.Notification != GameControllerUpdateNotification.JoystickUpdate) { ProcessUpdate(value); } }); var progress = progressHandler as IProgress <GameControllerProgressArgs>; _controllerTokenSource = new CancellationTokenSource(); var token = _controllerTokenSource.Token; try { Task.Factory.StartNew(() => { if (_Controller == null) { return; } _PoledController = _Controller; bool cancelled = false; System.Diagnostics.Debug.WriteLine($"Game controller command task STARTED. ({_PoledController.Name})"); bool notResponding = false; // Initialize DirectInput using (var directInput = new DirectInput()) { while (true) { token.ThrowIfCancellationRequested(); try { // Instantiate the joystick using (Joystick joystick = new Joystick(directInput, _PoledController.Id)) { joystick.Properties.Range = new InputRange(-10000, 10000); joystick.Properties.DeadZone = 100; joystick.Properties.Saturation = 9990; // Set BufferSize in order to use buffered data. joystick.Properties.BufferSize = 128; // Acquire the joystick joystick.Acquire(); while (true) { try { token.ThrowIfCancellationRequested(); joystick.Poll(); JoystickUpdate[] datas = joystick.GetBufferedData(); // Reset not responding incase the controller has just been re-connected if (notResponding) { notResponding = false; progress.Report(new GameControllerProgressArgs()); } // Check for POV updates IEnumerable <JoystickUpdate> povUpdates = datas.Where(s => s.Offset == JoystickOffset.PointOfViewControllers0).OrderBy(s => s.Sequence); IEnumerable <JoystickUpdate> axisUpdates = datas.Where(s => s.RawOffset <= 20).OrderBy(s => s.Sequence); IEnumerable <JoystickUpdate> buttonUpdates = datas.Where(s => s.RawOffset >= 48 && s.RawOffset <= 57).OrderBy(s => s.Sequence); if (progress != null) { if (buttonUpdates.Any()) { ProcessButtons(_PoledController, buttonUpdates, progress); } if (povUpdates.Any()) { ProcessPOVs(_PoledController, povUpdates, progress); } if (axisUpdates.Any()) { ProcessAxes(_PoledController, axisUpdates, progress); } } } catch (SharpDX.SharpDXException) { notResponding = true; progress.Report(new GameControllerProgressArgs()); Thread.Sleep(2000); break; } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine($"Game controller command task CANCELLED. ({_PoledController.Name})"); cancelled = true; break; } } } } catch (SharpDX.SharpDXException) { notResponding = true; progress.Report(new GameControllerProgressArgs()); Thread.Sleep(2000); } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine($"Game controller command task CANCELLED. ({_PoledController.Name})"); cancelled = true; break; } // Outer loop if (cancelled) { break; } } } // Using DirectInput }, _controllerTokenSource.Token); } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine($"Game controller command task CANCELLED. ({_PoledController.Name})"); } finally { _PoledController = null; } }