/// <summary> /// must return promptly /// </summary> /// <param name="sender"></param> /// <param name="jss"></param> private void Joystick_joystickEvent(object sender, IJoystickSubState jss) { jss.IsNew = false; currentJoystickData = (IJoystickSubState)jss.Clone(); string command = jss.GetCommand(); if (!string.IsNullOrWhiteSpace(command)) { //Debug.WriteLine("Joystick event: command: " + command); this.ControlDeviceCommand(command); } }
/// <summary> /// supports polling requests for latest Joystick SubState. /// </summary> /// <returns></returns> public IJoystickSubState GetJoystickSubState() { lock (jssLock) { if (jssCurrent != null && !jssCurrent.Equals(jssLast)) // only do something if the joystick state changed { jssLast = (IJoystickSubState)jssCurrent.Clone(); jssLast.IsNew = true; } } return(jssLast); }
/// <summary> /// Find a joystick, and if connected - poll it for latest Joystick SubState. /// May return null if no joystick found. /// </summary> /// <returns></returns> public async Task <IJoystickSubState> PollJoystick() { bool haveAJoystick = await FindOrCheck(); if (haveAJoystick) { IJoystickSubState jss = joystick.GetJoystickSubState(); return(jss); } else { return(null); } }
/// <summary> /// services control devices (joystick). /// </summary> private async void DoControlDevices() { // Repeat this loop until cancelled. while (!tokenSource.Token.IsCancellationRequested) { try { // call to open and maintain connection to joystick device: IJoystickSubState jss = await joystick.PollJoystick(); // just check for joystick existence. Data arrives in events. if (!joystick.IsEnabled) { Debug.WriteLine("ShortyTheRobot: Xbox Controller Not Found"); } shorty.ProcessControlDevices(); // give robot implementation a chance to maintain other control devices. } catch (Exception exc) { Debug.WriteLine("Error: DoControlDevices(): " + exc); } await Task.Delay(1000); } }
/// <summary> /// pass XBox360 Controller Joystick Event to subscribers of GenericJoystick class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void XBox360Controller_JoystickEvent(object sender, IJoystickSubState e) { //Debug.WriteLine("--------- Generic: Joystick Event"); joystickEvent?.Invoke(this, e); }
public void DisplayRobotJoystick(IJoystickSubState joystickData) { //Debug.WriteLine("RobotDashboard: DisplayRobotJoystick() joystick: " + joystickData.ToString()); rumblePad2Dashboard1.JoystickDataBlock.Post(joystickData); }
/// <summary> /// must return promptly /// </summary> /// <param name="sender"></param> /// <param name="jss"></param> private void Joystick_joystickEvent(object sender, IJoystickSubState jss) { jss.IsNew = false; string command = jss.GetCommand(); if (!string.IsNullOrWhiteSpace(command)) { //Debug.WriteLine("Joystick event: command: " + command); this.ControlDeviceCommand(command); } }
/// <summary> /// supports polling requests for latest Joystick SubState. /// </summary> /// <returns></returns> public IJoystickSubState GetJoystickSubState() { lock (jssLock) { if (jssCurrent != null && !jssCurrent.Equals(jssLast)) // only do something if the joystick state changed { jssLast = (IJoystickSubState)jssCurrent.Clone(); jssLast.IsNew = true; } } return jssLast; }