Skip to content

Commit b60bcc3

Browse files
author
Stevan M
committed
Multiple changes:
Hide Button, Bounces counting, Color changes, G value calculation
1 parent fb74f8e commit b60bcc3

File tree

13 files changed

+222
-99
lines changed

13 files changed

+222
-99
lines changed

GeesWPF/GeesWPF.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@
227227
<ItemGroup>
228228
<None Include="Resources\icon.ico" />
229229
</ItemGroup>
230+
<ItemGroup>
231+
<Resource Include="Images\bounce.png" />
232+
</ItemGroup>
230233
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
231234
<Import Project="..\packages\CTrue.FsConnect.1.0.2\build\CTrue.FsConnect.targets" Condition="Exists('..\packages\CTrue.FsConnect.1.0.2\build\CTrue.FsConnect.targets')" />
232235
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

GeesWPF/Images/bounce.png

591 Bytes
Loading

GeesWPF/Images/chevron.png

26 Bytes
Loading

GeesWPF/LRMDisplay.xaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:local="clr-namespace:GeesWPF"
88
mc:Ignorable="d"
9-
Title="LRMDisplay" Height="220" Width="2" Topmost="True" WindowStyle="None" Background="#FF1D3557" ResizeMode="NoResize" Left="-1" Top="40" ShowInTaskbar="False">
9+
Title="LRMDisplay" Height="260" Width="1" Topmost="True" WindowStyle="None" Background="#FF1D3557" ResizeMode="NoResize" Left="-1" Top="40" ShowInTaskbar="False">
1010
<Window.Resources>
1111
<Storyboard x:Key="show" TargetProperty="Margin">
1212
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty="Width" From="2" To="350" AccelerationRatio=".5">
@@ -61,8 +61,10 @@
6161
</Image.RenderTransform>
6262
</Image>
6363
<Image x:Name="image_Copy3" HorizontalAlignment="Left" Height="32" Margin="31,168,0,0" VerticalAlignment="Top" Width="32" Source="Images/slidew.png" RenderTransformOrigin="0.5,0.5"/>
64-
<Image x:Name="image1" HorizontalAlignment="Left" Height="220" Margin="311,0,-0.6,0" VerticalAlignment="Top" Width="40" Source="Images/chevron.png" Stretch="None" Cursor="Hand" MouseDown="image1_MouseDown"/>
65-
<Button x:Name="button" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Width="5" Height="220" Background="#FFE63946" BorderBrush="{x:Null}" Cursor="SizeWE" Click="button_Click"/>
64+
<Image x:Name="image1" HorizontalAlignment="Left" Height="260" Margin="311,0,-0.6,0" Width="40" Source="Images/chevron.png" Cursor="Hand" MouseDown="image1_MouseDown" Stretch="None"/>
65+
<Button x:Name="button" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" Width="5" Height="260" Background="#FFA8DADC" BorderBrush="{x:Null}" Cursor="SizeWE" Click="button_Click"/>
66+
<Label x:Name="labelBounces" Content="{Binding BouncesText}" HorizontalAlignment="Left" Margin="68,208,0,0" VerticalAlignment="Top" Foreground="#FFF1FAEE" FontSize="18"/>
67+
<Image x:Name="image_Copy2" HorizontalAlignment="Left" Height="32" Margin="31,210,0,0" VerticalAlignment="Top" Width="32" Source="Images/bounce.png" RenderTransformOrigin="0.5,0.5"/>
6668

6769
</Grid>
6870

GeesWPF/LandingLogger.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ public class LogEntry
3434
public double CrossV { get; set; }
3535
[Name("Sideslip (deg)")]
3636
public double Sideslip { get; set; }
37+
[Name("Bounces")]
38+
public double Bounces { get; set; }
3739
}
3840

3941
public string MakeLogIfEmpty()
4042
{
4143
//const string header = "Time,Plane,FPM,Impact (G),Air Speed (kt),Ground Speed (kt),Headwind (kt),Crosswind (kt),Sideslip (deg)";
4244
string myDocs = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
4345
Directory.CreateDirectory(myDocs + @"\MyMSFS2020Landings-Gees"); //create if doesn't exist
44-
string path = myDocs + @"\MyMSFS2020Landings-Gees\Landings.v2.csv";
46+
string path = myDocs + @"\MyMSFS2020Landings-Gees\Landings.v3.csv";
4547
if (!File.Exists(path))
4648
{
4749
using (var writer = new StreamWriter(path))

GeesWPF/MainWindow.xaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
<GroupBox x:Name="groupBox_Copy" Header="Slider Settings" HorizontalAlignment="Left" Height="80" Margin="10,230,0,0" VerticalAlignment="Top" Width="323" Foreground="#FFF1FAEE">
4646
<Grid HorizontalAlignment="Left" Height="40" Margin="10,10,-1.8,0" Width="290" VerticalAlignment="Top">
4747
<Button x:Name="buttonTest" Content="Test" HorizontalAlignment="Left" VerticalAlignment="Top" Width="51" Height="32" Background="#FFA8DADC" Foreground="#FF1D3557" Click="buttonTest_Click" Margin="242,2,-3,0"/>
48-
<CheckBox x:Name="checkBox" Content="Auto close after (seconds):" Margin="1,13,126,0" VerticalAlignment="Top" Foreground="#FFF1FAEE" IsChecked="{Binding AutoCloseLanding, Mode=TwoWay, Source={x:Static properties:Settings.Default}}" Checked="checkBox_Checked"/>
49-
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="19" Margin="169,11,0,0" TextWrapping="Wrap" Text="{Binding CloseAfterLanding, Mode=TwoWay, Source={x:Static properties:Settings.Default}}" VerticalAlignment="Top" Width="30" RenderTransformOrigin="-1.284,0.719" TextAlignment="Right" TextChanged="textBox_TextChanged" PreviewTextInput="textBox_PreviewTextInput"/>
48+
<CheckBox x:Name="checkBox" Content="Auto close - Bounce timer (s):" Margin="1,13,106,0" VerticalAlignment="Top" Foreground="#FFF1FAEE" IsChecked="{Binding AutoCloseLanding, Mode=TwoWay, Source={x:Static properties:Settings.Default}}" Checked="checkBox_Checked"/>
49+
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="19" Margin="184,11,0,0" TextWrapping="Wrap" Text="{Binding CloseAfterLanding, Mode=TwoWay, Source={x:Static properties:Settings.Default}}" VerticalAlignment="Top" Width="30" RenderTransformOrigin="-1.284,0.719" TextAlignment="Right" TextChanged="textBox_TextChanged" PreviewTextInput="textBox_PreviewTextInput"/>
5050
</Grid>
5151
</GroupBox>
5252
<GroupBox x:Name="groupBox_Copy1" Header="Landings" HorizontalAlignment="Left" Height="80" Margin="10,315,0,0" VerticalAlignment="Top" Width="323" Foreground="#FFF1FAEE">
@@ -61,5 +61,6 @@
6161
<Button x:Name="buttonUpdate" Content="Updates Available" HorizontalAlignment="Left" Margin="185,0,0,0" VerticalAlignment="Top" Width="105" Foreground="#FFF1FAEE" Height="37" Click="buttonUpdate_Click" Visibility="{Binding Updatable, Converter={StaticResource BoolToVis}}" Style="{DynamicResource DarkButton}"/>
6262
</Grid>
6363
</GroupBox>
64+
<Button x:Name="button_Hide" Content="Hide" HorizontalAlignment="Left" Margin="178,13,0,0" VerticalAlignment="Top" Width="75" Foreground="#FF1D3557" Height="37" Style="{DynamicResource DarkButton}" Background="#FFA8DADC" Click="button_Hide_Click"/>
6465
</Grid>
6566
</Window>

GeesWPF/MainWindow.xaml.cs

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public partial class MainWindow : Window
6767
static public string version;
6868
int lastDeactivateTick;
6969
bool lastDeactivateValid;
70+
int bounces = 0;
7071

7172
const int SAMPLE_RATE = 20; //ms
72-
const int WAIT_AFTER_LANDING = 100;
73-
const int BUFFER_SIZE = 10;
73+
const int BUFFER_SIZE = 2;
7474

7575
DispatcherTimer timerRead = new DispatcherTimer();
76-
DispatcherTimer timerWait = new DispatcherTimer();
76+
DispatcherTimer timerBounce = new DispatcherTimer();
7777
DispatcherTimer timerConnection = new DispatcherTimer();
7878
BackgroundWorker backgroundConnector = new BackgroundWorker();
7979
BackgroundWorker backgroundWorkerUpdate = new BackgroundWorker();
@@ -117,8 +117,7 @@ public MainWindow()
117117
//SIMCONREADER
118118
timerRead.Interval = new TimeSpan(0, 0, 0, 0, SAMPLE_RATE);
119119
timerRead.Tick += timerRead_Tick;
120-
timerWait.Interval = new TimeSpan(0, 0, 0, 0, WAIT_AFTER_LANDING);
121-
timerWait.Tick += timerWait_Tick;
120+
timerBounce.Tick += timerBounce_Tick;
122121
fsConnect.FsDataReceived += HandleReceivedFsData;
123122
definition.Add(new SimProperty("TITLE", null, SIMCONNECT_DATATYPE.STRING256));
124123
definition.Add(new SimProperty("SIM ON GROUND", "Bool", SIMCONNECT_DATATYPE.INT32));
@@ -150,7 +149,10 @@ private void timerRead_Tick(object sender, EventArgs e)
150149
}
151150
else
152151
{
153-
timerWait.Start();
152+
calculateLanding();
153+
int BOUNCE_TIMER = Properties.Settings.Default.CloseAfterLanding * 1000;
154+
timerBounce.Interval = new TimeSpan(0, 0, 0, 0, BOUNCE_TIMER);
155+
timerBounce.Start();
154156
}
155157
}
156158

@@ -213,54 +215,73 @@ private static void HandleReceivedFsData(object sender, FsDataReceivedEventArgs
213215
SafeToRead = true;
214216
}
215217

216-
private void timerWait_Tick(object sender, EventArgs e)
218+
private void calculateLanding()
217219
{
218220
//impact calculation
219221
try
220222
{
221-
double sample_time = Convert.ToDouble(SAMPLE_RATE) * 0.001; //ms
222223
double fpm = 60 * Onground.ElementAt(0).LandingRate;
223224
Int32 FPM = Convert.ToInt32(-fpm);
224225

225226
double gees = 0;
226-
int Gforcemeterlen = 100 / SAMPLE_RATE; // take 100ms average for G force
227-
for (int i = 0; i < Gforcemeterlen; i++)
227+
//int Gforcemeterlen = 100 / SAMPLE_RATE; // take 100ms average for G force
228+
for (int i = 0; i < BUFFER_SIZE; i++)
228229
{
229-
gees += Onground.ElementAt(i).Gforce;
230-
Console.WriteLine(Onground.ElementAt(i).Gforce);
230+
if (Onground.ElementAt(i).Gforce > gees)
231+
{
232+
gees = Onground.ElementAt(i).Gforce;
233+
}
234+
/*gees += Onground.ElementAt(i).Gforce;
235+
Console.WriteLine(Onground.ElementAt(i).Gforce);*/
231236
}
232-
gees /= Gforcemeterlen;
237+
// gees /= BUFFER_SIZE;*/
238+
// gees += Onground.ElementAt(0).Gforce;
239+
233240

234241
double incAngle = Math.Atan(Inair.Last().LateralSpeed / Inair.Last().ForwardSpeed) * 180 / Math.PI;
235-
236-
// EnterLog(Inair.First().Type, FPM, gees, Inair.Last().AirspeedInd, Inair.Last().GroundSpeed, Inair.Last().WindHead, Inair.Last().WindLat, incAngle);
237-
viewModel.LastLandingParameters = new ViewModel.Parameters
242+
243+
if (bounces == 0)
238244
{
239-
Name = Inair.First().Type,
240-
FPM = FPM,
241-
Gees = Math.Round(gees, 2),
242-
Airspeed = Math.Round(Inair.Last().AirspeedInd, 2),
243-
Groundspeed = Math.Round(Inair.Last().GroundSpeed, 2),
244-
Crosswind = Math.Round(Inair.Last().WindLat, 2),
245-
Headwind = Math.Round(Inair.Last().WindHead, 2),
246-
Slip = Math.Round(incAngle, 2)
247-
};
248-
winLRM.SlideLeft();
249-
// viewModel.UpdateTable();
245+
// EnterLog(Inair.First().Type, FPM, gees, Inair.Last().AirspeedInd, Inair.Last().GroundSpeed, Inair.Last().WindHead, Inair.Last().WindLat, incAngle);
246+
viewModel.SetParams(new ViewModel.Parameters
247+
{
248+
Name = Inair.First().Type,
249+
FPM = FPM,
250+
Gees = Math.Round(gees, 2),
251+
Airspeed = Math.Round(Inair.Last().AirspeedInd, 2),
252+
Groundspeed = Math.Round(Inair.Last().GroundSpeed, 2),
253+
Crosswind = Math.Round(Inair.Last().WindLat, 2),
254+
Headwind = Math.Round(Inair.Last().WindHead, 2),
255+
Slip = Math.Round(incAngle, 2),
256+
Bounces = 0
257+
});
258+
winLRM.SlideLeft();
259+
bounces++;
260+
}
261+
else
262+
{
263+
viewModel.BounceParams();
264+
}
265+
// viewModel.UpdateTable();
250266
//LRMDisplay form = new LRMDisplay(FPM, gees, Inair.Last().AirspeedInd, Inair.Last().GroundSpeed, Inair.Last().WindHead, Inair.Last().WindLat, incAngle);
251267
//form.Show();
252-
timerWait.Stop();
253268
Inair.Clear();
254269
Onground.Clear();
255270
ShowLanding = false;
256-
viewModel.UpdateTable();
257271
}
258272
catch (Exception ex)
259273
{
260274
Console.WriteLine(ex.Message);
261275
//some params are missing. likely the user is in the main menu. ignore
262276
}
263277
}
278+
private void timerBounce_Tick(object sender, EventArgs e)
279+
{
280+
bounces = 0;
281+
viewModel.LogParams();
282+
timerBounce.Stop();
283+
}
284+
264285
#endregion
265286

266287
#region Sim Connection
@@ -304,6 +325,10 @@ private void button_Click(object sender, RoutedEventArgs e)
304325
notifyIcon.Visible = false;
305326
Environment.Exit(1);
306327
}
328+
private void button_Hide_Click(object sender, RoutedEventArgs e)
329+
{
330+
this.Hide();
331+
}
307332
private void redditLink_MouseDown(object sender, MouseButtonEventArgs e)
308333
{
309334
Process.Start("https://www.reddit.com/r/MSFS2020LandingRate/");
@@ -425,8 +450,8 @@ private void backgroundWorkerUpdate_DoWork(object sender, System.ComponentModel.
425450
viewModel.Updatable = viewModel.Version != latest.TagName;
426451
updateUri = latest.HtmlUrl;
427452
}
428-
#endregion
429453

454+
#endregion
430455

431456
}
432457
}

GeesWPF/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.0.0")]
55-
[assembly: AssemblyFileVersion("1.0.0")]
54+
[assembly: AssemblyVersion("1.1.0")]
55+
[assembly: AssemblyFileVersion("1.1.0")]

GeesWPF/ViewModel.cs

Lines changed: 46 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -134,40 +134,7 @@ public void UpdateTable()
134134
LandingLogger logger = new LandingLogger();
135135
logTable = logger.LandingLog;
136136
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LandingTable"));
137-
138-
/*string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
139-
BindData(path + @"\MyMSFS2020Landings-Gees\Landings.v1.csv");*/
140137
}
141-
/* private void BindData(string filePath)
142-
{
143-
MakeLogIfEmpty();
144-
logTable.Columns.Clear();
145-
logTable.Rows.Clear();
146-
string[] lines = System.IO.File.ReadAllLines(filePath);
147-
if (lines.Length > 0)
148-
{
149-
//first line to create header
150-
string firstLine = lines[0];
151-
string[] headerLabels = firstLine.Split(',');
152-
foreach (string headerWord in headerLabels)
153-
{
154-
logTable.Columns.Add(new DataColumn(headerWord));
155-
}
156-
//For Data
157-
for (int i = lines.Length - 1; i > 0; i--)
158-
{
159-
string[] dataWords = lines[i].Split(',');
160-
DataRow dr = logTable.NewRow();
161-
int columnIndex = 0;
162-
foreach (string headerWord in headerLabels)
163-
{
164-
dr[headerWord] = dataWords[columnIndex++];
165-
}
166-
logTable.Rows.Add(dr);
167-
}
168-
}
169-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LandingTable"));
170-
}*/
171138
#endregion
172139

173140
#region Landing Rate Data
@@ -181,8 +148,10 @@ public class Parameters
181148
public double Headwind { get; set; }
182149
public double Slip { get; set; }
183150
public double Crosswind { get; set; }
151+
public int Bounces { get; set; }
184152
}
185153

154+
186155
private Parameters _lastLandingParams = new Parameters
187156
{
188157
Name = null,
@@ -192,37 +161,47 @@ public class Parameters
192161
Groundspeed = 63,
193162
Headwind = -7,
194163
Crosswind = 3,
195-
Slip = 1.53
164+
Slip = 1.53,
165+
Bounces = 0
196166
};
197-
public Parameters LastLandingParameters
167+
public void SetParams (Parameters value)
198168
{
199-
get { return LastLandingParameters; }
200-
set
169+
_lastLandingParams = value;
170+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(""));
171+
}
172+
173+
public void BounceParams()
174+
{
175+
_lastLandingParams.Bounces += 1;
176+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(""));
177+
}
178+
public void LogParams()
179+
{
180+
LandingLogger logger = new LandingLogger();
181+
logger.EnterLog(new LandingLogger.LogEntry
201182
{
202-
_lastLandingParams = value;
203-
LandingLogger logger = new LandingLogger();
204-
logger.EnterLog(new LandingLogger.LogEntry
205-
{
206-
Time = DateTime.Now,
207-
Plane = value.Name,
208-
Fpm = value.FPM,
209-
G = value.Gees,
210-
AirV = value.Airspeed,
211-
GroundV = value.Groundspeed,
212-
HeadV = value.Headwind,
213-
CrossV = value.Crosswind,
214-
Sideslip = value.Slip
215-
});
216-
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(""));
217-
}
183+
Time = DateTime.Now,
184+
Plane = _lastLandingParams.Name,
185+
Fpm = _lastLandingParams.FPM,
186+
G = _lastLandingParams.Gees,
187+
AirV = _lastLandingParams.Airspeed,
188+
GroundV = _lastLandingParams.Groundspeed,
189+
HeadV = _lastLandingParams.Headwind,
190+
CrossV = _lastLandingParams.Crosswind,
191+
Sideslip = _lastLandingParams.Slip,
192+
Bounces = _lastLandingParams.Bounces
193+
});
194+
UpdateTable();
195+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(""));
218196
}
197+
219198
public string FPMText
220199
{
221200
get { return _lastLandingParams.FPM.ToString("0 fpm"); }
222201
}
223202
public string GeesText
224203
{
225-
get { return _lastLandingParams.Gees.ToString("0.##G"); }
204+
get { return _lastLandingParams.Gees.ToString("0.## G"); }
226205
}
227206
public string GeesImage
228207
{
@@ -274,6 +253,19 @@ public string AlphaText
274253
{
275254
get { return _lastLandingParams.Slip.ToString("0.##º Left Sideslip; 0.##º Right Sideslip;"); }
276255
}
256+
257+
public string BouncesText
258+
{
259+
get {
260+
string unit = " bounces";
261+
if (_lastLandingParams.Bounces == 1)
262+
{
263+
unit = " bounce";
264+
}
265+
return _lastLandingParams.Bounces.ToString() + unit;
266+
}
267+
}
268+
277269
#endregion
278270

279271
protected void OnPropertyChanged([CallerMemberName] String propertyName = "")

Icons/chevron.png

26 Bytes
Loading

0 commit comments

Comments
 (0)