Exemplo n.º 1
0
 /// <summary>
 /// Serves as a hash function for a <see cref="OpenTK.Input.JoystickCapabilities"/> object.
 /// </summary>
 /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
 /// hash table.</returns>
 public override int GetHashCode()
 {
     return
         (AxisCount.GetHashCode() ^
          ButtonCount.GetHashCode() ^
          HatCount.GetHashCode() ^
          IsConnected.GetHashCode());
 }
Exemplo n.º 2
0
        /// <summary>
        /// ctor and init
        /// </summary>
        /// <param name="device">A DXInput device</param>
        /// <param name="hwnd">The WinHandle of the main window</param>
        /// <param name="joystickNum">The 0.. n-1 Joystick from DX enum</param>
        /// <param name="panel">The respective JS panel to show the properties</param>
        /// <param name="tabIndex">The Tab index in the GUI</param>
        public JoystickCls(SharpDX.DirectInput.Joystick device, Control hwnd, int joystickNum, UC_JoyPanel panel, int tabIndex)
        {
            log.DebugFormat("JoystickCls ctor - Entry with {0}", device.Information.ProductName);

            m_device         = device;
            m_hwnd           = hwnd;
            m_joystickNumber = joystickNum;     // this remains fixed
            m_xmlInstance    = joystickNum + 1; // initial assignment (is 1 based..)
            m_jPanel         = panel;
            MyTabPageIndex   = tabIndex;
            Activated_low    = false;

            m_senseLimit = AppConfiguration.AppConfig.jsSenseLimit; // can be changed in the app.config file if it is still too little

            // Set BufferSize in order to use buffered data.
            m_device.Properties.BufferSize = 128;

            m_jPanel.Caption      = m_device.Properties.ProductName;
            m_jPanel.nAxis        = AxisCount.ToString( );
            m_jPanel.nButtons     = ButtonCount.ToString( );
            m_jPanel.nPOVs        = POVCount.ToString( );
            m_jPanel.JsAssignment = 0; // default is no assignment

            m_ignoreButtons = new bool[m_state.Buttons.Length];
            ResetButtons(m_ignoreButtons);

            m_modifierButtons = new bool[m_state.Buttons.Length];
            ResetButtons(m_modifierButtons);

            log.Debug("Get JS Objects");
            try {
                // Set the data format to the c_dfDIJoystick pre-defined format.
                //m_device.SetDataFormat( DeviceDataFormat.Joystick );
                // Set the cooperative level for the device.
                m_device.SetCooperativeLevel(m_hwnd, CooperativeLevel.NonExclusive | CooperativeLevel.Background);
                // Enumerate all the objects on the device.
                foreach (DeviceObjectInstance d in m_device.GetObjects( ))
                {
                    // For axes that are returned, set the DIPROP_RANGE property for the
                    // enumerated axis in order to scale min/max values.
                    if ((0 != (d.ObjectId.Flags & DeviceObjectTypeFlags.Axis)))
                    {
                        // Set the range for the axis.
                        m_device.Properties.Range = new InputRange(-1000, +1000);
                    }
                    // Update the controls to reflect what objects the device supports.
                    UpdateControls(d);
                }
            }
            catch (Exception ex) {
                log.Error("Get JS Objects failed", ex);
            }

            ApplySettings_low( ); // get whatever is needed here from Settings
            JoystickCls.RegisteredDevices++;

            Activated_low = true;
        }