private IEnumerator _InitSpringForce(int sat, int coeff) { yield return(new WaitForSeconds(1f)); Debug.Log("stopping spring" + DirectInputWrapper.StopSpringForce(wheelIndex)); yield return(new WaitForSeconds(1f)); long res = -1; int tries = 0; while (res < 0) { res = DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(sat * FFBGain), Mathf.RoundToInt(coeff * FFBGain)); Debug.Log("starting spring" + res); tries++; if (tries > 150) { Debug.Log("coudn't init spring force. aborting"); break; } yield return(null); } }
// Update is called once per frame void Update() { DirectInputWrapper.Update(); DeviceState state = DirectInputWrapper.GetStateManaged(0); if (Input.GetKeyDown(KeyCode.P)) { //Debug.Log("PLAY: " + DirectInputWrapper.PlaySpringForce(0, 0, sat, coeff)); //Debug.Log("PLAY: " + DirectInputWrapper.PlayConstantForce(0, constant)); Debug.Log("PLAY: " + DirectInputWrapper.PlayDamperForce(0, damper)); playing = true; } if (Input.GetKeyDown(KeyCode.S)) { //Debug.Log("STOP:" + DirectInputWrapper.StopSpringForce(0)); //Debug.Log("STOP:" + DirectInputWrapper.StopConstantForce(0)); Debug.Log("STOP:" + DirectInputWrapper.StopDamperForce(0)); playing = false; } if(playing) { // DirectInputWrapper.UpdateConstantForce(0, constant); } }
void OnApplicationQuit() { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) { DirectInputWrapper.Close(); } }
public void StopSpringForce() { if (available && SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) { DirectInputWrapper.StopSpringForce(wheelIndex); } }
public void StopSpringForce() { Debug.Log("stopping spring" + DirectInputWrapper.StopSpringForce(wheelIndex)); if (MasterSteeringWheel) { Debug.Log("stopping spring" + DirectInputWrapper.StopSpringForce(masterIndex)); } }
void InitWheel() { if (inited == null) { inited = this; } else { return; } if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) { try { DirectInputWrapper.Init(); } catch (DllNotFoundException) { // in case DirectInput wrapper dll file is not found Debug.Log("DirectInput wrapper dll file is not found"); available = false; return; } for (int i = 0; i < DirectInputWrapper.DevicesCount(); i++) { if (!DirectInputWrapper.HasForceFeedback(i)) { continue; } wheelIndex = i; available = true; break; } if (!available) { Debug.Log("STEERINGWHEEL: Multiple devices and couldn't find steering wheel device index"); return; } } else { // WARNING: Input.GetJoystickNames or GetAxis/Buttons will crash if no valid Joystick is connected available = Environment.GetEnvironmentVariable("SDL_GAMECONTROLLERCONFIG") != null; // if (available) // { // foreach (var joy in Input.GetJoystickNames()) // { // Debug.Log($"Available joystick: {joy}, Preconfigured = {Input.IsJoystickPreconfigured(joy)}"); // } // } } }
protected override void Start() { base.Start(); debugStyle = new GUIStyle(); debugStyle.fontSize = 45; debugStyle.normal.textColor = Color.white; if (inited == null) { inited = this; } else { return; } DirectInputWrapper.Init(); bool ff0 = DirectInputWrapper.HasForceFeedback(0); if (DirectInputWrapper.DevicesCount() > 1) { bool ff1 = DirectInputWrapper.HasForceFeedback(1); if (ff1 && !ff0) { wheelIndex = 1; pedalIndex = 0; } else if (ff0 && !ff1) { wheelIndex = 0; pedalIndex = 1; } else { //Debug.Log("STEERINGWHEEL: Multiple devices and couldn't find steering wheel device index"); wheelIndex = 0; pedalIndex = 1; } } minBrake = AppController.Instance.appSettings.minBrake; maxBrake = AppController.Instance.appSettings.maxBrake; minGas = AppController.Instance.appSettings.minGas; maxGas = AppController.Instance.appSettings.maxGas; gasAxis = AppController.Instance.appSettings.gasAxis; brakeAxis = AppController.Instance.appSettings.brakeAxis; FFBGain = AppController.Instance.appSettings.FFBMultiplier; }
void Start() { Debug.Log("init: " + DirectInputWrapper.Init()); Debug.Log("Count: " + DirectInputWrapper.DevicesCount()); for (int i = 0; i < DirectInputWrapper.DevicesCount(); i++) { Debug.Log("Name: " + DirectInputWrapper.GetProductNameManaged(i)); Debug.Log("FFB: " + DirectInputWrapper.HasForceFeedback(i)); for(int j = 0; j < DirectInputWrapper.GetNumEffects(i); j++) { Debug.Log("EFFECT: " + DirectInputWrapper.GetEffectNameManaged(i, j)); } } }
void OnDestroy() { //destroy if single one, otherwise transfer control if (inited == this) { inited = null; var other = FindObjectOfType <SteeringWheelInputController>(); if (other != null) { other.Init(); } else { if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) { DirectInputWrapper.Close(); } } } }
private IEnumerator _InitSpringForce(int sat, int coeff) { yield return(new WaitForSeconds(1f)); yield return(new WaitForSeconds(1f)); long res = -1; int tries = 0; while (res < 0) { res = DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(sat * forceFeedbackGain), Mathf.RoundToInt(coeff * forceFeedbackGain)); tries++; if (tries > 150) { break; } yield return(null); } }
// Use this for initialization void Start() { DirectInputWrapper.Init(); /*LogitechGSDK.LogiControllerPropertiesData properties = new LogitechGSDK.LogiControllerPropertiesData(); * properties.wheelRange = 900; * properties.forceEnable = true; * properties.overallGain = 80; * properties.springGain = 80; * properties.damperGain = 80; * properties.allowGameSettings = true; * properties.combinePedals = true; * properties.defaultSpringEnabled = false; * properties.defaultSpringGain = 0; * LogitechGSDK.LogiSetPreferredControllerProperties(properties); */ bool ff0 = DirectInputWrapper.HasForceFeedback(0); if (DirectInputWrapper.DevicesCount() > 1) { bool ff1 = DirectInputWrapper.HasForceFeedback(1); if (ff1 && !ff0) { wheelIndex = 1; pedalIndex = 0; } else if (ff0 && !ff1) { wheelIndex = 0; pedalIndex = 1; } else { Debug.Log("STEERINGWHEEL: Multiple devices and couldn't find steering wheel device index"); } } }
public int reportMasterWheel(string wheelName) { int returnVal = -1; for (int i = 0; i < DirectInputWrapper.DevicesCount(); i++) { if (DirectInputWrapper.GetProductNameManaged(i) == wheelName) { Debug.Log("We got the FantaTec as a Master now! "); returnVal = i; break; } else { Debug.Log("Number" + i + "is not fanatec, moving on"); } } return(returnVal); }
// Update is called once per frame void Update() { DirectInputWrapper.Update(); DeviceState rec = DirectInputWrapper.GetStateManaged(wheelIndex); // steerInput = rec.lX / 32768f; // accelInput = rec.rglSlider[0] / -32768f; x = rec.lX; y = rec.lY; z = rec.lZ; s0 = rec.rglSlider[0]; s1 = rec.rglSlider[1]; Debug.Log("d0 = " + DirectInputWrapper.GetProductNameManaged(wheelIndex)); Debug.Log("ff0 = " + DirectInputWrapper.HasForceFeedback(wheelIndex)); if (forceFeedbackPlaying) { DirectInputWrapper.PlayConstantForce(wheelIndex, constant); } if (DirectInputWrapper.DevicesCount() > 1) { Debug.Log("d1 = " + DirectInputWrapper.GetProductNameManaged(pedalIndex)); Debug.Log("ff1 = " + DirectInputWrapper.HasForceFeedback(pedalIndex)); DeviceState rec2 = DirectInputWrapper.GetStateManaged(pedalIndex); // accelInput = ((32768 + rec2.lZ) - (rec2.lY + 32768f)) / 65535f; x2 = rec2.lX; y2 = rec2.lY; z2 = rec2.lZ; s02 = rec2.rglSlider[0]; s12 = rec2.rglSlider[1]; } }
public override void OnUpdate() { if (inited != this) { return; } //check for SelectLeft/right actions if (currentSelectState == SelectState.REST && GetSteerInput() < -selectThreshold) { currentSelectState = SelectState.LEFT; TriggerEvent(EventType.SELECT_CHOICE_LEFT); } else if (currentSelectState == SelectState.LEFT && GetSteerInput() > -selectThreshold) { currentSelectState = SelectState.REST; } else if (currentSelectState == SelectState.REST && GetSteerInput() > selectThreshold) { currentSelectState = SelectState.RIGHT; TriggerEvent(EventType.SELECT_CHOICE_RIGHT); } else if (currentSelectState == SelectState.RIGHT && GetSteerInput() < selectThreshold) { currentSelectState = SelectState.REST; } //Check for Throttle confirm if (isConfirmDown && GetAccelBrakeInput() < selectThreshold) { isConfirmDown = false; } else if (!isConfirmDown && GetAccelBrakeInput() > selectThreshold) { isConfirmDown = true; if (Time.timeSinceLevelLoad > confirmTimeout) { TriggerEvent(EventType.SELECT_CHOICE_CONFIRM); } } DirectInputWrapper.Update(); { DeviceState state = DirectInputWrapper.GetStateManaged(wheelIndex); if (state.lX == 0 && state.lY == 0 && state.lRz == 0) { return; } //steerInput = state.lX / 32768f; steerInput = Mathf.Clamp(state.lX / 32200f, -1f, 1f); //accelInput = state.rglSlider[0] / -32768f; //ly accel, lrz freno //float gas = (float) state.lY / 32768; //float indiceGas = (float(state.lY); float gas = ((float)state.lY - 32767) / -64378f; float brake = ((float)state.lRz - 32767) / 65403f; //float brake = (float) state.lRz / 32768; accelInput = gas + brake; /*float totalGas = (maxGas - minGas); * float totalBrake = (maxBrake - minBrake); * * accelInput = (gas - minGas) / totalGas - (brake - minBrake) / totalBrake;*/ /* x = state.lX; * y = state.lY; * z = state.lZ; * s0 = state.rglSlider[0]; * s1 = state.rglSlider[1];*/ /*if (forceFeedbackPlaying) * {*/ if (!guidaAutomatica) { DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.RoundToInt(constant * FFBGain)); DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.RoundToInt(damper * FFBGain)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(springSaturation * FFBGain), springCoefficient); } //DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.RoundToInt(constant * FFBGain)); /*DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.RoundToInt(damper * FFBGain)); * DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(springSaturation * FFBGain), springCoefficient);*/ //} /*if(DirectInputWrapper.DevicesCount() > 1) * { * DeviceState state2 = DirectInputWrapper.GetStateManaged(pedalIndex); * int gas = 0; * int brake = 0; * * /* x2 = state2.lX; * y2 = state2.lY; * z2 = state2.lZ; * s02 = state2.rglSlider[0]; * s12 = state2.rglSlider[1];*//* * * switch (gasAxis) { * case "X": * gas = state2.lX; * break; * case "Y": * gas = state2.lY; * break; * case "Z": * gas = state2.lZ; * break; * } * * switch (brakeAxis) * { * case "X": * brake = state2.lX; * break; * case "Y": * brake = state2.lY; * break; * case "Z": * brake = state2.lZ; * break; * } * * * float totalGas = (maxGas - minGas); * float totalBrake = (maxBrake - minBrake); * * accelInput = (gas - minGas) / totalGas - (brake - minBrake) / totalBrake; * }/*/ } }
public void StopSpringForce() { Debug.Log("stopping spring" + DirectInputWrapper.StopSpringForce(wheelIndex)); }
public override void OnUpdate() { if (inited != this) { return; } //check for SelectLeft/right actions if (currentSelectState == SelectState.REST && GetSteerInput() < -selectThreshold) { currentSelectState = SelectState.LEFT; TriggerEvent(EventType.SELECT_CHOICE_LEFT); } else if (currentSelectState == SelectState.LEFT && GetSteerInput() > -selectThreshold) { currentSelectState = SelectState.REST; } else if (currentSelectState == SelectState.REST && GetSteerInput() > selectThreshold) { currentSelectState = SelectState.RIGHT; TriggerEvent(EventType.SELECT_CHOICE_RIGHT); } else if (currentSelectState == SelectState.RIGHT && GetSteerInput() < selectThreshold) { currentSelectState = SelectState.REST; } //Check for Throttle confirm if (isConfirmDown && GetAccelBrakeInput() < selectThreshold) { isConfirmDown = false; } else if (!isConfirmDown && GetAccelBrakeInput() > selectThreshold) { isConfirmDown = true; if (Time.timeSinceLevelLoad > confirmTimeout) { TriggerEvent(EventType.SELECT_CHOICE_CONFIRM); } } DirectInputWrapper.Update(); { DeviceState state = DirectInputWrapper.GetStateManaged(wheelIndex); steerInput = state.lX / 32768f; accelInput = state.rglSlider[0] / -32768f; /* x = state.lX; * y = state.lY; * z = state.lZ; * s0 = state.rglSlider[0]; * s1 = state.rglSlider[1];*/ if (forceFeedbackPlaying) { DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.RoundToInt(constant * FFBGain)); DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.RoundToInt(damper * FFBGain)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(springSaturation * FFBGain), springCoefficient); } if (DirectInputWrapper.DevicesCount() > 1) { DeviceState state2 = DirectInputWrapper.GetStateManaged(pedalIndex); int gas = 0; int brake = 0; /* x2 = state2.lX; * y2 = state2.lY; * z2 = state2.lZ; * s02 = state2.rglSlider[0]; * s12 = state2.rglSlider[1];*/ switch (gasAxis) { case "X": gas = state2.lX; break; case "Y": gas = state2.lY; break; case "Z": gas = state2.lZ; break; } switch (brakeAxis) { case "X": brake = state2.lX; break; case "Y": brake = state2.lY; break; case "Z": brake = state2.lZ; break; } float totalGas = (maxGas - minGas); float totalBrake = (maxBrake - minBrake); accelInput = (gas - minGas) / totalGas - (brake - minBrake) / totalBrake; } } }
public static ObservableCollection <IHOTASDevice> GetDeviceList() { Guid.TryParse("b0350ff4-8f66-4cdd-ab69-bca2ee7f3907", out var productGuid); Guid.TryParse("f0c05a72-8f66-4cdd-ab69-bca2ee7f3907", out var throttleGuid); Guid.TryParse("d67c807f-98fd-4443-94ab-b2724e44f805", out var stickGuid); var di = new DirectInputWrapper(new DirectInput()); var devices = new ObservableCollection <IHOTASDevice>() { new HOTASDevice(di, new JoystickFactory(), productGuid, throttleGuid, "Joe's Test Throttle", new HOTASQueue(new KeyboardWrapper())), new HOTASDevice(di, new JoystickFactory(), productGuid, stickGuid, "Joe's Test Stick", new HOTASQueue(new KeyboardWrapper())) }; devices[0].ApplyButtonMap(new ObservableCollection <IHotasBaseMap>() { new HOTASButton() { MapName = "Button 1", Type = HOTASButton.ButtonType.Button, MapId = 54, ActionCatalogItem = new ActionCatalogItem() { ActionName = "test button 54", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.SPACE, TimeInMilliseconds = 0 }, new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.SPACE, TimeInMilliseconds = 0, IsKeyUp = true } } } }, new HOTASAxis() { MapName = "Axis 2", Type = HOTASButton.ButtonType.AxisRadial, MapId = 55, IsDirectional = true } }); devices[1].ApplyButtonMap(new ObservableCollection <IHotasBaseMap>() { new HOTASAxis() { MapName = "Axis 1", Type = HOTASButton.ButtonType.AxisLinear, MapId = 42, IsDirectional = true }, new HOTASAxis() { MapName = "Axis 2", Type = HOTASButton.ButtonType.AxisRadial, MapId = 43, IsDirectional = false }, new HOTASButton() { MapName = "Button 0", Type = HOTASButton.ButtonType.Button, MapId = 48 }, new HOTASButton() { MapName = "Button 1", Type = HOTASButton.ButtonType.Button, MapId = 55, ActionCatalogItem = new ActionCatalogItem() { ActionName = "test button 55", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.LMENU, TimeInMilliseconds = 0, IsExtended = true }, new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.LMENU, TimeInMilliseconds = 0, IsExtended = true, IsKeyUp = true } } } }, new HOTASButton() { MapName = "Button 2", Type = HOTASButton.ButtonType.Button, MapId = 56, ActionCatalogItem = new ActionCatalogItem() { ActionName = "test button 56", Actions = new ObservableCollection <ButtonAction>() { new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.RSHIFT, TimeInMilliseconds = 0, IsExtended = true }, new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.KEY_B, TimeInMilliseconds = 0 }, new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.KEY_B, TimeInMilliseconds = 0, IsKeyUp = true }, new ButtonAction() { ScanCode = (int)Win32Structures.ScanCodeShort.RSHIFT, TimeInMilliseconds = 0, IsKeyUp = true, IsExtended = true } } } } }); return(devices); }
public static string GetEffectNameManaged(int device, int index) { var pName = DirectInputWrapper.GetEffectName(device, index); return(Marshal.PtrToStringUni(pName)); }
public static string GetProductNameManaged(int device) { var pName = DirectInputWrapper.GetProductName(device); return(Marshal.PtrToStringUni(pName)); }
public override void OnUpdate() { if (inited != this) { return; } //check for SelectLeft/right actions if (currentSelectState == SelectState.REST && GetSteerInput() < -selectThreshold) { currentSelectState = SelectState.LEFT; TriggerEvent(EventType.SELECT_CHOICE_LEFT); } else if (currentSelectState == SelectState.LEFT && GetSteerInput() > -selectThreshold) { currentSelectState = SelectState.REST; } else if (currentSelectState == SelectState.REST && GetSteerInput() > selectThreshold) { currentSelectState = SelectState.RIGHT; TriggerEvent(EventType.SELECT_CHOICE_RIGHT); } else if (currentSelectState == SelectState.RIGHT && GetSteerInput() < selectThreshold) { currentSelectState = SelectState.REST; } //Check for Throttle confirm if (isConfirmDown && GetAccelBrakeInput() < selectThreshold) { isConfirmDown = false; } else if (!isConfirmDown && GetAccelBrakeInput() > selectThreshold) { isConfirmDown = true; if (Time.timeSinceLevelLoad > confirmTimeout) { TriggerEvent(EventType.SELECT_CHOICE_CONFIRM); } } if (Application.platform != RuntimePlatform.OSXEditor) { DirectInputWrapper.Update(); { DeviceState state; DeviceState slaveState; if (MasterSteeringWheel) { state = DirectInputWrapper.GetStateManaged(masterIndex); slaveState = DirectInputWrapper.GetStateManaged(wheelIndex); slaveSteering = slaveState.lX / 32768f; } else { state = DirectInputWrapper.GetStateManaged(wheelIndex); } steerInput = state.lX / 32768f; accelInput = state.rglSlider [0] / -32768f; // Debug.Log("Device One: \tlRx: " + state.lRx + "\tlRy: " + state.lRy + "\tlRz: " + state.lRz + "\tlX: " + state.lX + "\tlY: " + state.lY + "\tlZ: " + state.lZ); /* x = state.lX; * y = state.lY; * z = state.lZ; * s0 = state.rglSlider[0]; * s1 = state.rglSlider[1];*/ if (forceFeedbackPlaying) { if (MasterSteeringWheel) { DirectInputWrapper.PlayConstantForce(masterIndex, Mathf.RoundToInt(constant * FFBGain)); DirectInputWrapper.PlayDamperForce(masterIndex, Mathf.RoundToInt(damper * FFBGain)); DirectInputWrapper.PlaySpringForce(masterIndex, 0, Mathf.RoundToInt(springSaturation * FFBGain), springCoefficient); DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.RoundToInt(slaveConstant * FFBGain)); DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.RoundToInt(slaveDamper * FFBGain)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(slaveSpringSaturation * FFBGain), slaveSpringCoefficient); } else { DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.RoundToInt(constant * FFBGain)); DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.RoundToInt(damper * FFBGain)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.RoundToInt(springSaturation * FFBGain), springCoefficient); } } if (DirectInputWrapper.DevicesCount() > 1 || MasterSteeringWheel) { int gas = 0; int brake = 0; if (DirectInputWrapper.DevicesCount() > 1 && !MasterSteeringWheel) { DeviceState state2 = DirectInputWrapper.GetStateManaged(pedalIndex); /* x2 = state2.lX; * y2 = state2.lY; * z2 = state2.lZ; * s02 = state2.rglSlider[0]; * s12 = state2.rglSlider[1];*/ switch (gasAxis) { case "X": gas = state2.lX; break; case "Y": gas = state2.lY; break; case "Z": gas = state2.lZ; break; } switch (brakeAxis) { case "X": brake = state2.lX; break; case "Y": brake = state2.lY; break; case "Z": brake = state2.lZ; break; } } if (MasterSteeringWheel) { brake = state.lRz; gas = state.lY; } //Debug.Log(brake.ToString() + " break and gas" + gas.ToString()); float totalGas = (maxGas - minGas); float totalBrake = (maxBrake - minBrake); accelInput = (gas - minGas) / totalGas - (brake - minBrake) / totalBrake; } } } }
protected override void Start() { base.Start(); debugStyle = new GUIStyle(); debugStyle.fontSize = 45; debugStyle.normal.textColor = Color.white; if (inited == null) { inited = this; } else { return; } DirectInputWrapper.Init(); MasterSteeringWheel = false; masterIndex = reportMasterWheel("FANATEC CSL Elite Wheel Base"); if (masterIndex > -1) { MasterSteeringWheel = true; } bool ff0 = DirectInputWrapper.HasForceFeedback(0); /// Thios part mworks for now as the main inputs are always 0 or 1 we need code here though tat jumps over the master wheel shpould it be present if (DirectInputWrapper.DevicesCount() > 1) // steering one and two should be padles and participant steering wheel { bool ff1 = DirectInputWrapper.HasForceFeedback(1); if (ff1 && !ff0) { wheelIndex = 1; pedalIndex = 0; } else if (ff0 && !ff1) { wheelIndex = 0; pedalIndex = 1; } else { Debug.Log("STEERINGWHEEL: Multiple devices and couldn't find steering wheel device index"); } } if (MasterSteeringWheel) { minBrake = AppController.Instance.appSettings.minBrakeFanatec; maxBrake = AppController.Instance.appSettings.maxBrakeFanatec; minGas = AppController.Instance.appSettings.minGasFanatec; maxGas = AppController.Instance.appSettings.maxGasFanatec; } else { minBrake = AppController.Instance.appSettings.minBrake; maxBrake = AppController.Instance.appSettings.maxBrake; minGas = AppController.Instance.appSettings.minGas; maxGas = AppController.Instance.appSettings.maxGas; } gasAxis = AppController.Instance.appSettings.gasAxis; brakeAxis = AppController.Instance.appSettings.brakeAxis; // FWheel = AppController.Instance.appSettings.FantacWheel; FFBGain = AppController.Instance.appSettings.FFBMultiplier; }
void OnDestroy() { DirectInputWrapper.Close(); }
public void OnUpdate() { if (workingInstance != this || !available || !enable) { return; } float accelInput; uint pov; byte[] buttons; if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) { if (DirectInputWrapper.DevicesCount() == 0) { timeAccumulator += UnityEngine.Time.deltaTime; if (timeAccumulator >= 1.0f) { Init(); timeAccumulator = 0.0f; } } DirectInputWrapper.Update(); DeviceState state; if (!DirectInputWrapper.GetStateManaged(wheelIndex, out state)) { var error = $"Can not get valid device state for steering wheel {wheelIndex}, try reconnect and restart game to fix"; Debug.Log(error); stateFail = error; available = false; return; } SteerInput = state.lX / 32768f; accelInput = (state.lY - state.lRz) / -32768f; if (!useFeedback || !useGroundFeedbackForce) { DirectInputWrapper.PlayConstantForce(wheelIndex, 0); DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.Clamp(Mathf.RoundToInt(damper * forceFeedbackGain), -10000, 10000)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, 0, springCoefficient); } if (useFeedback && (useGroundFeedbackForce || (autonomousBehavior != SteerWheelAutonomousFeedbackBehavior.None))) { float totalConstForce = 0.0f; if (useGroundFeedbackForce) { totalConstForce += constant * forceFeedbackGain; } if (autonomousBehavior != SteerWheelAutonomousFeedbackBehavior.None) { totalConstForce += autoforce * autoForceGain; } //applying effects to steering wheel var value = Mathf.RoundToInt(totalConstForce); if (value < -100) { value = Mathf.Clamp(value, -10000, -800); } if (value > 100) { value = Mathf.Clamp(value, 800, 10000); } DirectInputWrapper.PlayConstantForce(wheelIndex, Mathf.Clamp(value, -10000, 10000)); if (useGroundFeedbackForce) { DirectInputWrapper.PlayDamperForce(wheelIndex, Mathf.Clamp(Mathf.RoundToInt(damper * forceFeedbackGain), -10000, 10000)); DirectInputWrapper.PlaySpringForce(wheelIndex, 0, Mathf.Clamp(Mathf.RoundToInt(springSaturation * forceFeedbackGain), 0, 10000), springCoefficient); } } pov = state.rgdwPOV[0]; buttons = state.rgbButtons; } else { SteerInput = Input.GetAxis("Steering"); // pedal range is -1 (not pressed) to +1 (pressed) // but by default when user has not pressed pedal the Unity reports value 0 float accel = Input.GetAxis("Acceleration"); float brake = Input.GetAxis("Braking"); if (accel != 0.0f) { accelPressedOnce = true; } if (brake != 0.0f) { brakePressedOnce = true; } if (!accelPressedOnce) { accel = -1.0f; } if (!brakePressedOnce) { brake = -1.0f; } accelInput = (accel - brake) / 2.0f; pov = 0; // TODO // if (Input.GetButton("SelectUp")) pov = 0; // else if (Input.GetButton("SelectRight")) pov = 9000; // else if (Input.GetButton("SelectDown")) pov = 18000; // else if (Input.GetButton("SelectLeft")) pov = 27000; buttons = new byte [32]; // TODO: here fill buttons according to buttonMapping array above buttons[0] = (byte)(Input.GetButton("TurnOffAutonomousMode") ? 1 : 0); buttons[1] = (byte)(Input.GetButton("ToggleMainCamera") ? 1 : 0); buttons[8] = (byte)(Input.GetButton("ShiftUp") ? 1 : 0); buttons[9] = (byte)(Input.GetButton("ShiftDown") ? 1 : 0); buttons[10] = (byte)(Input.GetButton("EngineStartStop") ? 1 : 0); } if (accelInput >= 0) { AccelBrakeInput = pedalInput == null ? accelInput : pedalInput.throttleInputCurve.Evaluate(accelInput); } else { AccelBrakeInput = pedalInput == null ? accelInput: -pedalInput.brakeInputCurve.Evaluate(-accelInput); } foreach (var m in buttonMapping) { if (buttons[m.Key] != 0) { TriggerDown(m.Value); } if (oldButtons[m.Key] == 0 && buttons[m.Key] != 0) { TriggerPress(m.Value); } else if (oldButtons[m.Key] != 0 && buttons[m.Key] == 0) { TriggerRelease(m.Value); } } System.Array.Copy(buttons, oldButtons, oldButtons.Length); Action <uint, Action <InputEvent> > povAction = (uint value, Action <InputEvent> action) => { switch (value) { case 0: action(InputEvent.SELECT_UP); break; case 9000: action(InputEvent.SELECT_RIGHT); break; case 18000: action(InputEvent.SELECT_DOWN); break; case 27000: action(InputEvent.SELECT_LEFT); break; default: break; } }; povAction(pov, x => TriggerDown(x)); if (pov != oldPov) { povAction(oldPov, x => TriggerRelease(x)); povAction(pov, x => TriggerPress(x)); } oldPov = pov; }
// Update is called once per frame void Update() { state = DirectInputWrapper.GetStateManaged(0); if (Input.GetKeyDown(KeyCode.F5) || state.rgbButtons[9] == 128) //tasto Y { if (posizioneAnterioreSinistra != null) { Transform t = leggiFileDisco(); if (t != null && Vector3.Distance(transform.localPosition, t.position) < 10f) { //Vector3.Distance(transform.position, t.position) < 10f controlla che la posizione salvata non sia troppo distante da quella attuale, in tal caso significa che รจ una posizione memorizzata ma non corretta transform.localPosition = t.position; transform.localRotation = t.rotation; ultimaPosizione = t.position; ultimaRotazione = t.rotation.eulerAngles; Debug.Log("Ripristinata ultima posizione salvata"); return; } ResetPosizioneVisore(CenterEyeAnchor, posizioneAnterioreSinistra); ultimaPosizione = transform.localPosition; ultimaRotazione = transform.localRotation.eulerAngles; interventoAllaGuidaConsentito = true; Debug.Log("Reset posizione tramite posizione visore"); gambe.transform.localPosition = new Vector3(-0.407f, -0.296f, 0.469f); } else { Debug.Log("Errore! Assegna la posizione target del visore"); } return; } if (Input.GetKeyDown(KeyCode.F10) || state.rgbButtons[7] == 128) //tasto LT { if (ultimaPosizione != Vector3.zero) { salvaPosizioneSuDisco(); } } if (Input.GetKeyDown(KeyCode.F9) || state.rgbButtons[2] == 128) //tasto RT { if (posizioneAnterioreSinistra != null) { ResetPosizioneVisoreGuidatore(); ultimaPosizione = transform.localPosition; ultimaRotazione = transform.localRotation.eulerAngles; interventoAllaGuidaConsentito = true; gambe.transform.localPosition = new Vector3(-0.407f, -0.296f, 0.469f); } return; } if (Input.GetKeyDown(KeyCode.KeypadPlus) || state.rgbButtons[4] == 128) //tasto + sulla tastiera oppure paletta cambio marcia su { transform.Rotate(0f, 0.1f, 0f); } if (Input.GetKeyDown(KeyCode.KeypadMinus) || state.rgbButtons[5] == 128) //tasto - sulla tastiera oppure paletta cambio marcia giu { transform.Rotate(0f, -0.1f, 0f); } if (Input.GetKeyDown(KeyCode.Keypad8) || (state.rgdwPOV[0] == 0 && state.rgdwPOV[1] != 0)) //tasto 8 sulla tastiera oppure freccia sopra sul volante { transform.Translate(0, 0, 0.001f); //transform.Translate(0.001f, 0, 0); } if (Input.GetKeyDown(KeyCode.Keypad2) || state.rgdwPOV[0] == 18000) //tasto 2 sulla tastiera oppure freccia sotto sul volante { transform.Translate(0, 0, -0.001f); //transform.Translate(-0.001f, 0, 0); } if (Input.GetKeyDown(KeyCode.Keypad6) || state.rgdwPOV[0] == 9000) //tasto * sulla tastiera oppure freccia destra sul volante { transform.Translate(0.001f, 0, 0); //transform.Translate(0, 0, -0.001f); } if (Input.GetKeyDown(KeyCode.Keypad4) || state.rgdwPOV[0] == 27000) //tasto / sulla tastiera oppure freccia sinistra sul volante { transform.Translate(-0.001f, 0, 0); //transform.Translate(0, 0, 0.001f); } if (Input.GetKeyDown(KeyCode.Keypad9)) //tasto 9 sulla tastiera { transform.Translate(0, 0.01f, 0); //transform.Translate(0, 0, 0.001f); } if (Input.GetKeyDown(KeyCode.Keypad3)) //tasto 3 sulla tastiera oppure freccia sinistra sul volante { transform.Translate(0, -0.01f, 0); //transform.Translate(0, 0, 0.001f); } if (Input.GetKeyDown(KeyCode.F6) || state.rgbButtons[25] == 128) //tasto B { if (posizioneAnterioreSinistra != null) { ResetPosizioneVisore(CenterEyeAnchor, posizioneAnterioreDestra); interventoAllaGuidaConsentito = false; gambe.transform.localPosition = new Vector3(0.407f, -0.296f, 0.469f); } return; } if (Input.GetKeyDown(KeyCode.F7) || state.rgbButtons[21] == 128) //tasto X { if (posizioneAnterioreSinistra != null) { ResetPosizioneVisore(CenterEyeAnchor, posizionePosterioreSinistra); interventoAllaGuidaConsentito = false; } return; } if (Input.GetKeyDown(KeyCode.F8) || state.rgbButtons[1] == 128) //tasto A { if (posizioneAnterioreSinistra != null) { ResetPosizioneVisore(CenterEyeAnchor, posizionePosterioreDestra); interventoAllaGuidaConsentito = false; } return; } }