@@ -39,6 +39,8 @@ public enum SeatOfPantsAlgorithm
3939 public bool IsCalibrating => _calibrationPhase != CalibrationPhase . NotCalibrating ;
4040 public bool RedrawCalibrationGraph { private get ; set ; } = false ;
4141
42+ public string CalibrationFileName { get ; private set ; } = string . Empty ;
43+
4244 private enum CalibrationPhase
4345 {
4446 NotCalibrating ,
@@ -132,11 +134,11 @@ public SteeringEffects()
132134
133135 public void SimulatorDisconnected ( )
134136 {
135- DataContext . DataContext . Instance . Settings . SteeringEffectsCalibrationFileName = string . Empty ;
136-
137137 ClearCalibration ( ) ;
138138
139- MainWindow . _steeringEffectsPage . UpdateCalibrationFileNameOptions ( ) ;
139+ // the car is gone, so this hides the calibration file banners
140+
141+ LoadCalibration ( ) ;
140142 }
141143
142144 public static void SendChatMessage ( string groupKey , string labelKey , string ? value = null )
@@ -971,16 +973,6 @@ private void SaveCalibration()
971973
972974 writer . Close ( ) ;
973975
974- // update the combo box options
975-
976- MainWindow . _steeringEffectsPage . UpdateCalibrationFileNameOptions ( ) ;
977-
978- // update setting to use this calibration file
979-
980- var settings = DataContext . DataContext . Instance . Settings ;
981-
982- settings . SteeringEffectsCalibrationFileName = Path . GetFileNameWithoutExtension ( filePath ) ;
983-
984976 //
985977
986978 app . Logger . WriteLine ( "[SteeringEffects] <<< SaveCalibration" ) ;
@@ -1019,42 +1011,39 @@ public void LoadCalibration()
10191011 }
10201012 else
10211013 {
1022- // figure out which calibration file we need to load
1014+ // clear the current calibration
10231015
1024- var settings = DataContext . DataContext . Instance . Settings ;
1016+ ClearCalibration ( ) ;
10251017
1026- if ( settings . SteeringEffectsCalibrationFileName == null )
1027- {
1028- app . Logger . WriteLine ( $ "[SteeringEffects] Calibration file name property value is null (shouldn't be possible!)" ) ;
1018+ CalibrationFileName = string . Empty ;
10291019
1030- ClearCalibration ( ) ;
1031- }
1032- else if ( settings . SteeringEffectsCalibrationFileName == string . Empty )
1033- {
1034- app . Logger . WriteLine ( $ "[SteeringEffects] No calibration file selected" ) ;
1020+ // keep track of whether a calibration file for the current car is missing, and whether the file load was good or not
1021+
1022+ var calibrationFileIsMissing = false ;
1023+ var calibrationDataSeemsGood = false ;
10351024
1036- ClearCalibration ( ) ;
1025+ if ( app . Simulator . CarScreenName == string . Empty )
1026+ {
1027+ app . Logger . WriteLine ( "[SteeringEffects] The simulator is not running or the car is not known yet" ) ;
10371028 }
10381029 else
10391030 {
1040- // clear the current calibration
1031+ // automatically select the first calibration file found for the current car
10411032
1042- ClearCalibration ( ) ;
1033+ var filePath = Directory . Exists ( CalibrationDirectory ) ? Directory . GetFiles ( CalibrationDirectory , $ " { app . Simulator . CarScreenName } - *.csv" ) . Order ( ) . FirstOrDefault ( ) : null ;
10431034
1044- // keep track of whether the file load was good or not
1045-
1046- var calibrationDataSeemsGood = false ;
1047-
1048- // open file
1049-
1050- var filePath = Path . Combine ( CalibrationDirectory , $ "{ settings . SteeringEffectsCalibrationFileName } .csv" ) ;
1051-
1052- if ( ! File . Exists ( filePath ) )
1035+ if ( filePath == null )
10531036 {
1054- app . Logger . WriteLine ( $ "[SteeringEffects] Calibration file not found: { filePath } " ) ;
1037+ app . Logger . WriteLine ( $ "[SteeringEffects] No calibration file found for this car: { app . Simulator . CarScreenName } " ) ;
1038+
1039+ calibrationFileIsMissing = true ;
10551040 }
10561041 else
10571042 {
1043+ CalibrationFileName = Path . GetFileNameWithoutExtension ( filePath ) ;
1044+
1045+ app . Logger . WriteLine ( $ "[SteeringEffects] Loading calibration file: { filePath } " ) ;
1046+
10581047 using var reader = new StreamReader ( filePath ) ;
10591048
10601049 // skip the first two lines
@@ -1266,8 +1255,13 @@ public void LoadCalibration()
12661255
12671256 app . Dispatcher . Invoke ( ( ) =>
12681257 {
1269- MainWindow . _steeringEffectsPage . InvalidConfigurationFile_Border . Visibility = ( ( settings . SteeringEffectsCalibrationFileName == string . Empty ) || _calibrationIsValid ) ? Visibility . Hidden : Visibility . Visible ;
1258+ MainWindow . _steeringEffectsPage . CalibrationFileNotAvailable_Border . Visibility = calibrationFileIsMissing ? Visibility . Visible : Visibility . Hidden ;
1259+ MainWindow . _steeringEffectsPage . InvalidConfigurationFile_Border . Visibility = ( ( CalibrationFileName == string . Empty ) || _calibrationIsValid ) ? Visibility . Hidden : Visibility . Visible ;
12701260 } ) ;
1261+
1262+ // show the warnings in the understeer and oversteer sections only when a car is active but we don't have a valid calibration
1263+
1264+ MainWindow . _steeringEffectsPage . UpdateCalibrationFileWarnings ( ( app . Simulator . CarScreenName != string . Empty ) && ! _calibrationIsValid ) ;
12711265 }
12721266
12731267 //
@@ -1287,23 +1281,14 @@ public void Tick( App app )
12871281 {
12881282 var localization = DataContext . DataContext . Instance . Localization ;
12891283
1290- if ( app . Simulator . CarSetupName == string . Empty )
1291- {
1292- MainWindow . _steeringEffectsPage . CarSetupName_TextBlock . Visibility = Visibility . Collapsed ;
1293- }
1294- else
1295- {
1296- MainWindow . _steeringEffectsPage . CarSetupName_TextBlock . Text = $ "{ localization [ "CurrentCarSetup" ] } { app . Simulator . CarSetupName . ToUpper ( ) } ";
1297- MainWindow . _steeringEffectsPage . CarSetupName_TextBlock . Visibility = Visibility . Visible ;
1298- }
1299-
13001284 if ( _calibrationPhase == CalibrationPhase . NotCalibrating )
13011285 {
13021286 MainWindow . _steeringEffectsPage . CalibrationProgress_Border . Visibility = Visibility . Collapsed ;
13031287 MainWindow . _steeringEffectsPage . LiveInfo_Border . Visibility = Visibility . Collapsed ;
13041288 }
13051289 else
13061290 {
1291+ MainWindow . _steeringEffectsPage . CalibrationFileNotAvailable_Border . Visibility = Visibility . Hidden ;
13071292 MainWindow . _steeringEffectsPage . InvalidConfigurationFile_Border . Visibility = Visibility . Hidden ;
13081293 MainWindow . _steeringEffectsPage . CalibrationProgress_TextBlock . Text = $ "{ localization [ "Progress:" ] } { _calibrationProgress * 100f : F0} { localization [ "Percent" ] } ";
13091294 MainWindow . _steeringEffectsPage . CalibrationProgress_Border . Visibility = Visibility . Visible ;
0 commit comments