Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <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);
            }
        }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
        public void DisplayRobotJoystick(IJoystickSubState joystickData)
        {
            //Debug.WriteLine("RobotDashboard: DisplayRobotJoystick()   joystick: " + joystickData.ToString());

            rumblePad2Dashboard1.JoystickDataBlock.Post(joystickData);
        }
Exemplo n.º 7
0
 /// <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);
     }
 }
Exemplo n.º 8
0
 /// <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);
 }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        public void DisplayRobotJoystick(IJoystickSubState joystickData)
        {
            //Debug.WriteLine("RobotDashboard: DisplayRobotJoystick()   joystick: " + joystickData.ToString());

            rumblePad2Dashboard1.JoystickDataBlock.Post(joystickData);
        }