/// <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_controlWordCache = new HALControlWord(); m_lastControlWordUpdate = DateTime.MinValue; //Starts the driver station thread in the background. m_dsThread = new Thread(Task) { IsBackground = true, Name = "FRCDriverStation" }; m_dsThread.Start(); }
/// <summary> /// Gets the HAL Control Word /// </summary> /// <returns></returns> public static int HAL_GetControlWord(ref HALControlWord controlWord) { uint word = 0; int ret = NativeHALGetControlWord(ref word); controlWord = new HALControlWord((word & 1) != 0, ((word >> 1) & 1) != 0, ((word >> 2) & 1) != 0, ((word >> 3) & 1) != 0, ((word >> 4) & 1) != 0, ((word >> 5) & 1) != 0); return(ret); }
private void UpdateControlWord(bool force, out HALControlWord controlWord) { DateTime now = DateTime.UtcNow; lock (m_controlWordMutex) { if (now - m_lastControlWordUpdate > TimeSpan.FromMilliseconds(50) || force) { HAL_GetControlWord(ref m_controlWordCache); m_lastControlWordUpdate = now; } controlWord = m_controlWordCache; } }