-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApp.Telemetry.cs
More file actions
164 lines (130 loc) · 5.46 KB
/
Copy pathApp.Telemetry.cs
File metadata and controls
164 lines (130 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
using System.Windows;
namespace MarvinsAIRA
{
[StructLayout( LayoutKind.Sequential, Pack = 4 )]
public struct TelemetryData
{
public int tickCount;
public float wheelMax;
public float overallScale;
public bool overallScaleAutoReady;
public float overallScaleAutoClipLimit;
public float detailScale;
public float parkedScale;
public float frequency;
public int understeerFxStyle;
public float understeerFxStrength;
public float understeerFxCurve;
public float understeerYRFactorLStart;
public float understeerYRFactorLEnd;
public float understeerYRFactorRStart;
public float understeerYRFactorREnd;
public int oversteerFxStyle;
public float oversteerFxStrength;
public float oversteerFxCurve;
public float oversteerYVelocityStart;
public float oversteerYVelocityEnd;
public float lfeScale;
public float ffbInAmount;
public float ffbOutAmount;
public bool ffbClipping;
public float yawRateFactor;
public float gForce;
public float understeerAmount;
public float oversteerAmount;
public bool crashProtectionEngaged;
public bool forceFeedbackEnabled;
public bool steeringEffectsEnabled;
public bool lfeToFFBEnabled;
public bool windSimulatorEnabled;
public bool spotterEnabled;
public float overallScaleAutoPeak;
public bool curbProtectionEngaged;
public float ffbSteadyState;
public float shockVelocity;
public float lfeInAmount;
public float lfeOutAmount;
public float ffbCurve;
public float ffbMinForce;
public float ffbMaxForce;
}
public partial class App : Application
{
private const string TELEMETRY_MEMORYMAPPEDFILENAME = "Local\\MAIRATelemetry";
private TelemetryData _telemetry_data = new();
private MemoryMappedFile? _telemetry_memoryMappedFile = null;
private MemoryMappedViewAccessor? _telemetry_memoryMappedFileViewAccessor = null;
private void InitializeTelemetry()
{
WriteLine( "InitializeTelemetry called.", true );
try
{
WriteLine( "...creating or opening the memory mapped file..." );
var sizeOfTelemetryData = Marshal.SizeOf( typeof( TelemetryData ) );
_telemetry_memoryMappedFile = MemoryMappedFile.CreateOrOpen( TELEMETRY_MEMORYMAPPEDFILENAME, sizeOfTelemetryData );
WriteLine( "...creating the memory mapped file view accessor..." );
_telemetry_memoryMappedFileViewAccessor = _telemetry_memoryMappedFile.CreateViewAccessor();
WriteLine( "...telemetry is ready to go." );
}
catch
{
}
}
private void StopTelemetry()
{
WriteLine( "StopTelemetry called.", true );
_telemetry_memoryMappedFileViewAccessor = null;
_telemetry_memoryMappedFile = null;
}
public void UpdateTelemetry()
{
_telemetry_data.tickCount++;
_telemetry_data.wheelMax = Settings.WheelMaxForce;
_telemetry_data.overallScale = Settings.OverallScale / 100f;
_telemetry_data.overallScaleAutoReady = FFB_AutoOverallScaleIsReady;
_telemetry_data.overallScaleAutoPeak = _ffb_autoTorqueNM;
_telemetry_data.overallScaleAutoClipLimit = Settings.AutoOverallScaleClipLimit / 100f;
_telemetry_data.detailScale = Settings.DetailScale / 100f;
_telemetry_data.parkedScale = Settings.ParkedScale / 100f;
_telemetry_data.frequency = 1000f / ( 18 - Settings.Frequency );
_telemetry_data.understeerFxStyle = Settings.USEffectStyle;
_telemetry_data.understeerFxStrength = Settings.USEffectStrength / 100f;
_telemetry_data.understeerFxCurve = Settings.USCurve;
_telemetry_data.understeerYRFactorLStart = Settings.USStartYawRateFactorLeft;
_telemetry_data.understeerYRFactorLEnd = Settings.USEndYawRateFactorLeft;
_telemetry_data.understeerYRFactorRStart = Settings.USStartYawRateFactorRight;
_telemetry_data.understeerYRFactorREnd = Settings.USEndYawRateFactorRight;
_telemetry_data.understeerAmount = _ffb_understeerAmount;
_telemetry_data.oversteerFxStyle = Settings.OSEffectStyle;
_telemetry_data.oversteerFxStrength = Settings.OSEffectStrength / 100f;
_telemetry_data.oversteerFxCurve = Settings.OSCurve;
_telemetry_data.oversteerYVelocityStart = Settings.OSStartYVelocity;
_telemetry_data.oversteerYVelocityEnd = Settings.OSEndYVelocity;
_telemetry_data.oversteerAmount = _ffb_oversteerAmount;
_telemetry_data.lfeScale = Settings.LFEScale / 100f;
_telemetry_data.lfeInAmount = _ffb_lfeInMagnitude;
_telemetry_data.lfeOutAmount = _ffb_lfeOutTorqueNM;
_telemetry_data.ffbInAmount = _ffb_inTorqueNM;
_telemetry_data.ffbOutAmount = _ffb_outTorqueNM;
_telemetry_data.ffbCurve = Settings.FFBCurve;
_telemetry_data.ffbMinForce = Settings.MinForce;
_telemetry_data.ffbMaxForce = Settings.MaxForce;
_telemetry_data.ffbSteadyState = _ffb_rawSteadyStateTorqueNM;
_telemetry_data.ffbClipping = _ffb_clippedTimer > 0f;
_telemetry_data.yawRateFactor = _ffb_yawRateFactorInstant;
_telemetry_data.gForce = _irsdk_gForce;
_telemetry_data.shockVelocity = _ffb_maxShockVel;
_telemetry_data.crashProtectionEngaged = _ffb_crashProtectionTimer > 0f;
_telemetry_data.curbProtectionEngaged = _ffb_curbProtectionTimer > 0f;
_telemetry_data.forceFeedbackEnabled = Settings.ForceFeedbackEnabled;
_telemetry_data.steeringEffectsEnabled = Settings.SteeringEffectsEnabled;
_telemetry_data.lfeToFFBEnabled = Settings.LFEToFFBEnabled;
_telemetry_data.windSimulatorEnabled = Settings.WindSimulatorEnabled;
_telemetry_data.spotterEnabled = Settings.SpotterEnabled;
_telemetry_memoryMappedFileViewAccessor?.Write( 0, ref _telemetry_data );
}
}
}