Skip to content

Commit 28cf069

Browse files
committed
Split crash protection into longitudinal and lateral G forces
1 parent c4b7012 commit 28cf069

5 files changed

Lines changed: 151 additions & 42 deletions

File tree

App.xaml.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,25 +858,47 @@ private void OnInput( string deviceProductName, Guid deviceInstanceGuid, int but
858858
}
859859
}
860860

861-
// racing wheel crash protection g force knob
861+
// racing wheel crash protection longitudal g force knob
862862

863-
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionGForcePlusButtonMappings, deviceInstanceGuid, buttonNumber ) )
863+
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionLongitudalGForcePlusButtonMappings, deviceInstanceGuid, buttonNumber ) )
864864
{
865-
settings.RacingWheelCrashProtectionGForce += 0.5f;
865+
settings.RacingWheelCrashProtectionLongitudalGForce += 0.5f;
866866

867867
if ( settings.RacingWheelInputMappedSettingUpdateEnabled )
868868
{
869-
RacingWheel.SendChatMessage( "GForce", settings.RacingWheelCrashProtectionGForceString );
869+
RacingWheel.SendChatMessage( "LongitudalGForce", settings.RacingWheelCrashProtectionLongitudalGForceString );
870870
}
871871
}
872872

873-
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionGForceMinusButtonMappings, deviceInstanceGuid, buttonNumber ) )
873+
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionLongitudalGForceMinusButtonMappings, deviceInstanceGuid, buttonNumber ) )
874874
{
875-
settings.RacingWheelCrashProtectionGForce -= 0.5f;
875+
settings.RacingWheelCrashProtectionLongitudalGForce -= 0.5f;
876876

877877
if ( settings.RacingWheelInputMappedSettingUpdateEnabled )
878878
{
879-
RacingWheel.SendChatMessage( "GForce", settings.RacingWheelCrashProtectionGForceString );
879+
RacingWheel.SendChatMessage( "LongitudalGForce", settings.RacingWheelCrashProtectionLongitudalGForceString );
880+
}
881+
}
882+
883+
// racing wheel crash protection lateral g force knob
884+
885+
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionLateralGForcePlusButtonMappings, deviceInstanceGuid, buttonNumber ) )
886+
{
887+
settings.RacingWheelCrashProtectionLateralGForce += 0.5f;
888+
889+
if ( settings.RacingWheelInputMappedSettingUpdateEnabled )
890+
{
891+
RacingWheel.SendChatMessage( "LateralGForce", settings.RacingWheelCrashProtectionLateralGForceString );
892+
}
893+
}
894+
895+
if ( CheckMappedButtons( settings.RacingWheelCrashProtectionLateralGForceMinusButtonMappings, deviceInstanceGuid, buttonNumber ) )
896+
{
897+
settings.RacingWheelCrashProtectionLateralGForce -= 0.5f;
898+
899+
if ( settings.RacingWheelInputMappedSettingUpdateEnabled )
900+
{
901+
RacingWheel.SendChatMessage( "LateralGForce", settings.RacingWheelCrashProtectionLateralGForceString );
880902
}
881903
}
882904

Components/Simulator.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public partial class Simulator
3636
public string CurrentTireCompoundType { get; private set; } = string.Empty;
3737
public int DisplayUnits { get; private set; } = 0;
3838
public int Gear { get; private set; } = 0;
39-
public float GForce { get; private set; } = 0f;
39+
public float LongitudalGForce { get; private set; } = 0f;
40+
public float LateralGForce { get; private set; } = 0f;
4041
public bool IsConnected { get => _irsdk.IsConnected; }
4142
public bool IsOnTrack { get; private set; } = false;
4243
public bool IsReplayPlaying { get; private set; } = false;
@@ -251,7 +252,8 @@ private void OnDisconnected()
251252
CurrentTireCompoundType = string.Empty;
252253
DisplayUnits = 0;
253254
Gear = 0;
254-
GForce = 0f;
255+
LongitudalGForce = 0f;
256+
LateralGForce = 0f;
255257
IsOnTrack = false;
256258
IsReplayPlaying = false;
257259
LapDistPct = 0f;
@@ -651,19 +653,31 @@ private void OnTelemetryData()
651653
YawNorth = _irsdk.Data.GetFloat( _yawNorthDatum );
652654
YawRate = _irsdk.Data.GetFloat( _yawRateDatum );
653655

654-
// calculate g force
656+
// calculate g forces
655657

656-
GForce = MathF.Sqrt( LatAccel * LatAccel + LongAccel * LongAccel ) * MathZ.OneOverG;
658+
LongitudalGForce = MathF.Sqrt( LongAccel * LongAccel ) * MathZ.OneOverG;
659+
LateralGForce = MathF.Sqrt( LatAccel * LatAccel ) * MathZ.OneOverG;
657660

658661
// crash protection processing
659662

660663
if ( IsOnTrack )
661664
{
662-
if ( ( settings.RacingWheelCrashProtectionGForce < 20f ) && ( settings.RacingWheelCrashProtectionDuration > 0f ) && ( settings.RacingWheelCrashProtectionForceReduction > 0f ) )
665+
if ( ( settings.RacingWheelCrashProtectionDuration > 0f ) && ( settings.RacingWheelCrashProtectionForceReduction > 0f ) )
663666
{
664-
if ( MathF.Abs( GForce ) >= settings.RacingWheelCrashProtectionGForce )
667+
if ( settings.RacingWheelCrashProtectionLongitudalGForce < 20f )
665668
{
666-
app.RacingWheel.ActivateCrashProtection = true;
669+
if ( MathF.Abs( LongitudalGForce ) >= settings.RacingWheelCrashProtectionLongitudalGForce )
670+
{
671+
app.RacingWheel.ActivateCrashProtection = true;
672+
}
673+
}
674+
675+
if ( settings.RacingWheelCrashProtectionLateralGForce < 20f )
676+
{
677+
if ( MathF.Abs( LateralGForce ) >= settings.RacingWheelCrashProtectionLateralGForce )
678+
{
679+
app.RacingWheel.ActivateCrashProtection = true;
680+
}
667681
}
668682
}
669683
}

DataContext/ContextSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public class ContextSettings
2929
public float RacingWheelOutputMaximum { get; set; }
3030
public float RacingWheelOutputCurve { get; set; }
3131
public float RacingWheelLFEStrength { get; set; }
32-
public float RacingWheelCrashProtectionGForce { get; set; }
32+
public float RacingWheelCrashProtectionLongitudalGForce { get; set; }
33+
public float RacingWheelCrashProtectionLateralGForce { get; set; }
3334
public float RacingWheelCrashProtectionDuration { get; set; }
3435
public float RacingWheelCrashProtectionForceReduction { get; set; }
3536
public float RacingWheelCurbProtectionShockVelocity { get; set; }

DataContext/Settings.cs

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,57 +1451,111 @@ public string RacingWheelLFEStrengthString
14511451

14521452
#endregion
14531453

1454-
#region Racing wheel - Crash protection g-force
1454+
#region Racing wheel - Crash protection longitudal g-force
14551455

1456-
private float _racingWheelCrashProtectionGForce = 8f;
1456+
private float _racingWheelCrashProtectionLongitudalGForce = 8f;
14571457

1458-
public float RacingWheelCrashProtectionGForce
1458+
public float RacingWheelCrashProtectionLongitudalGForce
14591459
{
1460-
get => _racingWheelCrashProtectionGForce;
1460+
get => _racingWheelCrashProtectionLongitudalGForce;
14611461

14621462
set
14631463
{
14641464
value = Math.Clamp( value, 2f, 20f );
14651465

1466-
if ( value != _racingWheelCrashProtectionGForce )
1466+
if ( value != _racingWheelCrashProtectionLongitudalGForce )
14671467
{
1468-
_racingWheelCrashProtectionGForce = value;
1468+
_racingWheelCrashProtectionLongitudalGForce = value;
14691469

14701470
OnPropertyChanged();
14711471
}
14721472

1473-
if ( _racingWheelCrashProtectionGForce == 20f )
1473+
if ( _racingWheelCrashProtectionLongitudalGForce == 20f )
14741474
{
1475-
RacingWheelCrashProtectionGForceString = DataContext.Instance.Localization[ "OFF" ];
1475+
RacingWheelCrashProtectionLongitudalGForceString = DataContext.Instance.Localization[ "OFF" ];
14761476
}
14771477
else
14781478
{
1479-
RacingWheelCrashProtectionGForceString = $"{_racingWheelCrashProtectionGForce:F1} {DataContext.Instance.Localization[ "GForceUnits" ]}";
1479+
RacingWheelCrashProtectionLongitudalGForceString = $"{_racingWheelCrashProtectionLongitudalGForce:F1} {DataContext.Instance.Localization[ "GForceUnits" ]}";
14801480
}
14811481
}
14821482
}
14831483

1484-
private string _racingWheelCrashProtectionGForceString = string.Empty;
1484+
private string _racingWheelCrashProtectionLongitudalGForceString = string.Empty;
14851485

14861486
[XmlIgnore]
1487-
public string RacingWheelCrashProtectionGForceString
1487+
public string RacingWheelCrashProtectionLongitudalGForceString
14881488
{
1489-
get => _racingWheelCrashProtectionGForceString;
1489+
get => _racingWheelCrashProtectionLongitudalGForceString;
14901490

14911491
set
14921492
{
1493-
if ( value != _racingWheelCrashProtectionGForceString )
1493+
if ( value != _racingWheelCrashProtectionLongitudalGForceString )
14941494
{
1495-
_racingWheelCrashProtectionGForceString = value;
1495+
_racingWheelCrashProtectionLongitudalGForceString = value;
14961496

14971497
OnPropertyChanged();
14981498
}
14991499
}
15001500
}
15011501

1502-
public ContextSwitches RacingWheelCrashProtectionGForceContextSwitches { get; set; } = new( false, false, false, false, false );
1503-
public ButtonMappings RacingWheelCrashProtectionGForcePlusButtonMappings { get; set; } = new();
1504-
public ButtonMappings RacingWheelCrashProtectionGForceMinusButtonMappings { get; set; } = new();
1502+
public ContextSwitches RacingWheelCrashProtectionLongitudalGForceContextSwitches { get; set; } = new( false, false, false, false, false );
1503+
public ButtonMappings RacingWheelCrashProtectionLongitudalGForcePlusButtonMappings { get; set; } = new();
1504+
public ButtonMappings RacingWheelCrashProtectionLongitudalGForceMinusButtonMappings { get; set; } = new();
1505+
1506+
#endregion
1507+
1508+
#region Racing wheel - Crash protection lateral g-force
1509+
1510+
private float _racingWheelCrashProtectionLateralGForce = 6f;
1511+
1512+
public float RacingWheelCrashProtectionLateralGForce
1513+
{
1514+
get => _racingWheelCrashProtectionLateralGForce;
1515+
1516+
set
1517+
{
1518+
value = Math.Clamp( value, 2f, 20f );
1519+
1520+
if ( value != _racingWheelCrashProtectionLateralGForce )
1521+
{
1522+
_racingWheelCrashProtectionLateralGForce = value;
1523+
1524+
OnPropertyChanged();
1525+
}
1526+
1527+
if ( _racingWheelCrashProtectionLateralGForce == 20f )
1528+
{
1529+
RacingWheelCrashProtectionLateralGForceString = DataContext.Instance.Localization[ "OFF" ];
1530+
}
1531+
else
1532+
{
1533+
RacingWheelCrashProtectionLateralGForceString = $"{_racingWheelCrashProtectionLateralGForce:F1} {DataContext.Instance.Localization[ "GForceUnits" ]}";
1534+
}
1535+
}
1536+
}
1537+
1538+
private string _racingWheelCrashProtectionLateralGForceString = string.Empty;
1539+
1540+
[XmlIgnore]
1541+
public string RacingWheelCrashProtectionLateralGForceString
1542+
{
1543+
get => _racingWheelCrashProtectionLateralGForceString;
1544+
1545+
set
1546+
{
1547+
if ( value != _racingWheelCrashProtectionLateralGForceString )
1548+
{
1549+
_racingWheelCrashProtectionLateralGForceString = value;
1550+
1551+
OnPropertyChanged();
1552+
}
1553+
}
1554+
}
1555+
1556+
public ContextSwitches RacingWheelCrashProtectionLateralGForceContextSwitches { get; set; } = new( false, false, false, false, false );
1557+
public ButtonMappings RacingWheelCrashProtectionLateralGForcePlusButtonMappings { get; set; } = new();
1558+
public ButtonMappings RacingWheelCrashProtectionLateralGForceMinusButtonMappings { get; set; } = new();
15051559

15061560
#endregion
15071561

Pages/RacingWheelPage.xaml

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,12 @@
586586

587587
<Grid>
588588

589+
<Grid.RowDefinitions>
590+
<RowDefinition Height="Auto" />
591+
<RowDefinition Height="10" />
592+
<RowDefinition Height="Auto" />
593+
</Grid.RowDefinitions>
594+
589595
<Grid.ColumnDefinitions>
590596
<ColumnDefinition Width="*" />
591597
<ColumnDefinition Width="40" />
@@ -594,16 +600,18 @@
594600
<ColumnDefinition Width="*" />
595601
</Grid.ColumnDefinitions>
596602

597-
<controls:MairaKnob Grid.Column="0"
598-
Label="{Binding Localization[GForce]}"
599-
Value="{Binding Settings.RacingWheelCrashProtectionGForce, Mode=TwoWay}"
600-
ValueString="{Binding Settings.RacingWheelCrashProtectionGForceString}"
603+
<controls:MairaKnob Grid.Row="0"
604+
Grid.Column="0"
605+
Label="{Binding Localization[LongitudalGForce]}"
606+
Value="{Binding Settings.RacingWheelCrashProtectionLongitudalGForce, Mode=TwoWay}"
607+
ValueString="{Binding Settings.RacingWheelCrashProtectionLongitudalGForceString}"
601608
StepSize="0.5"
602-
ContextSwitches="{Binding Settings.RacingWheelCrashProtectionGForceContextSwitches}"
603-
PlusButtonMappings="{Binding Settings.RacingWheelCrashProtectionGForcePlusButtonMappings}"
604-
MinusButtonMappings="{Binding Settings.RacingWheelCrashProtectionGForceMinusButtonMappings}"
609+
ContextSwitches="{Binding Settings.RacingWheelCrashProtectionLongitudalGForceContextSwitches}"
610+
PlusButtonMappings="{Binding Settings.RacingWheelCrashProtectionLongitudalGForcePlusButtonMappings}"
611+
MinusButtonMappings="{Binding Settings.RacingWheelCrashProtectionLongitudalGForceMinusButtonMappings}"
605612
DefaultValue="8" />
606-
<controls:MairaKnob Grid.Column="2"
613+
<controls:MairaKnob Grid.Row="0"
614+
Grid.Column="2"
607615
Label="{Binding Localization[Duration]}"
608616
Value="{Binding Settings.RacingWheelCrashProtectionDuration, Mode=TwoWay}"
609617
ValueString="{Binding Settings.RacingWheelCrashProtectionDurationString}"
@@ -612,7 +620,8 @@
612620
PlusButtonMappings="{Binding Settings.RacingWheelCrashProtectionDurationPlusButtonMappings}"
613621
MinusButtonMappings="{Binding Settings.RacingWheelCrashProtectionDurationMinusButtonMappings}"
614622
DefaultValue="1" />
615-
<controls:MairaKnob Grid.Column="4"
623+
<controls:MairaKnob Grid.Row="0"
624+
Grid.Column="4"
616625
Label="{Binding Localization[ForceReduction]}"
617626
Value="{Binding Settings.RacingWheelCrashProtectionForceReduction, Mode=TwoWay}"
618627
ValueString="{Binding Settings.RacingWheelCrashProtectionForceReductionString}"
@@ -621,7 +630,16 @@
621630
PlusButtonMappings="{Binding Settings.RacingWheelCrashProtectionForceReductionPlusButtonMappings}"
622631
MinusButtonMappings="{Binding Settings.RacingWheelCrashProtectionForceReductionMinusButtonMappings}"
623632
DefaultValue="0.95" />
624-
633+
<controls:MairaKnob Grid.Row="2"
634+
Grid.Column="0"
635+
Label="{Binding Localization[LateralGForce]}"
636+
Value="{Binding Settings.RacingWheelCrashProtectionLateralGForce, Mode=TwoWay}"
637+
ValueString="{Binding Settings.RacingWheelCrashProtectionLateralGForceString}"
638+
StepSize="0.5"
639+
ContextSwitches="{Binding Settings.RacingWheelCrashProtectionLateralGForceContextSwitches}"
640+
PlusButtonMappings="{Binding Settings.RacingWheelCrashProtectionLateralGForcePlusButtonMappings}"
641+
MinusButtonMappings="{Binding Settings.RacingWheelCrashProtectionLateralGForceMinusButtonMappings}"
642+
DefaultValue="6" />
625643
</Grid>
626644

627645
</controls:MairaGroupBox>

0 commit comments

Comments
 (0)