public static int HALGetJoystickDescriptor(byte joystickNum, ref HALJoystickDescriptor desc) { var stick = DriverStation.Joysticks[joystickNum]; desc.isXbox = (byte)stick.IsXbox; desc.type = stick.Type; CreateUTF8String(stick.Name, ref desc.name);//stick.Name; desc.axisCount = (byte)stick.Axes.Length; desc.buttonCount = (byte)(stick.Buttons.Length - 1); return 0; }
/// <summary> /// Gets the name of the joystick. /// </summary> /// <param name="stick">The joystick port number</param> /// <returns>The joystick name</returns> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown if the stick is out of range.</exception> public string GetJoystickName(int stick) { lock (m_lockObject) { if (stick < 0 || stick >= JoystickPorts) { throw new ArgumentOutOfRangeException(nameof(stick), $"Joystick Index is out of range, should be 0-{JoystickPorts}"); } //TODO: Remove this when calling for descriptor on empty stick if (1 > m_joystickButtons[stick].count && 1 > m_joystickAxes[stick].count) { ReportJoystickUnpluggedError("WARNING: Joystick on port " + stick + " not available, check if controller is plugged in\n"); return ""; } HALJoystickDescriptor desc = new HALJoystickDescriptor(); HAL.Base.HAL.HALGetJoystickDescriptor((byte)stick, ref desc); return desc.name.ToString(); } }
/// <summary> /// Driver Station constructor /// </summary> /// <remarks>This is normally created statically in the singleton instance.</remarks> protected DriverStation() { //Force all joysticks to have no value. for (int i = 0; i < JoystickPorts; i++) { m_joystickButtons[i].count = 0; m_joystickAxes[i].count = 0; m_joystickPOVs[i].count = 0; m_joystickDescriptors[i] = new HALJoystickDescriptor(); m_joystickDescriptors[i].isXbox = 0; m_joystickDescriptors[i].type = 0xFF; m_joystickDescriptors[i].name.byte0 = 0; m_joystickButtonsCache[i].count = 0; m_joystickAxesCache[i].count = 0; m_joystickPOVsCache[i].count = 0; m_joystickDescriptorsCache[i] = new HALJoystickDescriptor(); m_joystickDescriptorsCache[i].isXbox = 0; m_joystickDescriptorsCache[i].type = 0xFF; m_joystickDescriptorsCache[i].name.byte0 = 0; } m_readWriteLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); //Initializes the HAL semaphores m_dataSem = new object(); m_packetDataAvailableMutex = InitializeMutexNormal(); m_packetDataAvailableSem = InitializeMultiWait(); HALSetNewDataSem(m_packetDataAvailableSem); //Starts the driver station thread in the background. var thread = new Thread(Task) { Priority = ThreadPriority.AboveNormal, IsBackground = true, Name = "FRCDriverStation" }; thread.Start(); }