Skip to content

Commit

Permalink
copy of simvar watcher for example
Browse files Browse the repository at this point in the history
  • Loading branch information
rmroc451 committed Dec 29, 2020
0 parents commit 4809e7a
Show file tree
Hide file tree
Showing 34 changed files with 4,046 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/bin/x64
/.vs/Simvars/v16
/obj/x64/Debug
6 changes: 6 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
9 changes: 9 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Simvars.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Simvars"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Simvars
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
130 changes: 130 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<Window x:Class="Simvars.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Simvars"
xmlns:simco="clr-namespace:Microsoft.FlightSimulator.SimConnect;assembly=Microsoft.FlightSimulator.SimConnect"
xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="700" Width="800" MinWidth="800" MinHeight="700">

<Window.Resources>
<ObjectDataProvider x:Key="SimObjectTypeFromEnum" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="simco:SIMCONNECT_SIMOBJECT_TYPE"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
<CollectionViewSource x:Key="AlphaSortedSimvarNames" Source="{Binding aSimvarNames}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
<CollectionViewSource x:Key="AlphaSortedUnitNames" Source="{Binding aUnitNames}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription />
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Window.Resources>

<Grid>
<TextBlock Width="236" Margin="10,11,546,-11" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top">
<Hyperlink x:Name="hl_SimConnect" NavigateUri="https://msdn.microsoft.com/en-us/library/cc526983.aspx" RequestNavigate="LinkOnRequestNavigate">
SimConnect Reference
</Hyperlink>
</TextBlock>
<TextBlock Margin="10,33,546,613" Width="236" VerticalAlignment="Top" HorizontalAlignment="Left" Height="23">
<Hyperlink x:Name="hl_SimVariables" NavigateUri="https://msdn.microsoft.com/en-us/library/cc526981.aspx" RequestNavigate="LinkOnRequestNavigate" >
Simulation Variables Reference
</Hyperlink>
</TextBlock>

<Button x:Name="btn_Connection" Content="{Binding sConnectButtonLabel}" Command="{Binding cmdToggleConnect}" HorizontalAlignment="Left" Margin="29,68,0,0" VerticalAlignment="Top" Width="146" Height="48"/>
<Button x:Name="btn_LoadFile" Content="Load File" Command="{Binding cmdLoadFiles}" HorizontalAlignment="Left" Margin="29,156,0,0" VerticalAlignment="Top" Width="100" Height="23" RenderTransformOrigin="0.423,0.841"/>
<Button x:Name="btn_SaveFile" Content="Save File" Command="{Binding cmdSaveFile}" HorizontalAlignment="Left" Margin="148,156,0,0" VerticalAlignment="Top" Width="100" Height="23"/>
<CheckBox Content="Save values" IsChecked="{Binding bSaveValues, Mode=TwoWay}" HorizontalAlignment="Left" Margin="167,184,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.597,0.489"/>

<ListView x:Name="lv_Simvars" ItemsSource="{Binding lSimvarRequests}" SelectedItem="{Binding oSelectedSimvarRequest, Mode=OneWayToSource}" Margin="270,10,10,10">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<DataTrigger Binding="{Binding bStillPending}" Value="True">
<Setter Property="Background" Value="#55D3D373" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.ContextMenu>
<ContextMenu>
<MenuItem Header="Remove" Command="{Binding cmdRemoveSelectedRequest}" />
</ContextMenu>
</ListView.ContextMenu>
<ListView.View>
<GridView>
<GridViewColumn Header="Simvar" Width="200" DisplayMemberBinding="{Binding sName}"/>
<GridViewColumn Header="Value" Width="150" DisplayMemberBinding="{Binding dValue, StringFormat=\{0:F9\}}"/>
<GridViewColumn Header="Units" Width="150" DisplayMemberBinding="{Binding sUnits}"/>
</GridView>
</ListView.View>
</ListView>

<Label Content="SimObject" HorizontalAlignment="Left" Margin="10,208,0,0" VerticalAlignment="Top" Height="23" Width="83"/>
<ComboBox x:Name="cbb_SimObjectType" ItemsSource="{Binding Source={StaticResource SimObjectTypeFromEnum}}" SelectedValue="{Binding eSimObjectType, Mode=OneWayToSource}" SelectedIndex="0" HorizontalAlignment="Left" Margin="11,231,0,0" VerticalAlignment="Top" Width="119" Height="23"/>
<Label Content="ObjectID" HorizontalAlignment="Left" Margin="165,208,0,0" VerticalAlignment="Top" Height="23" Width="71"/>
<ComboBox x:Name="cbb_ObjectIds" ItemsSource="{Binding lObjectIDs}" SelectedValue="{Binding iObjectIdRequest, Mode=OneWayToSource}" IsEnabled="{Binding bObjectIDSelectionEnabled}" SelectedIndex="0" HorizontalAlignment="Left" Margin="165,231,0,0" VerticalAlignment="Top" Width="48" Height="23"/>

<Label Content="Simvar Name" HorizontalAlignment="Left" Margin="10,259,0,0" VerticalAlignment="Top" Height="23" Width="83"/>
<ComboBox x:Name="cbb_SimvarNames" ItemsSource="{Binding Source={StaticResource AlphaSortedSimvarNames}}" SelectedValue="{Binding sSimvarRequest, Mode=OneWayToSource}" SelectedIndex="0" HorizontalAlignment="Left" Margin="10,282,0,0" VerticalAlignment="Top" Width="238" Height="23"/>
<Label Content="Index" HorizontalAlignment="Left" Margin="10,310,0,0" VerticalAlignment="Top" Height="23" Width="71"/>
<ComboBox x:Name="cbb_Indices" ItemsSource="{Binding aIndices}" SelectedValue="{Binding iIndexRequest, Mode=OneWayToSource}" SelectedIndex="0" HorizontalAlignment="Left" Margin="10,333,0,0" VerticalAlignment="Top" Width="45" Height="23"/>
<Label Content="Units" HorizontalAlignment="Left" Margin="70,310,0,0" VerticalAlignment="Top" Height="23" Width="83"/>
<ComboBox x:Name="cbb_UnitNames" ItemsSource="{Binding Source={StaticResource AlphaSortedUnitNames}}" SelectedValue="{Binding sUnitRequest, Mode=OneWayToSource}" SelectedIndex="0" HorizontalAlignment="Left" Margin="70,333,0,0" VerticalAlignment="Top" Width="178" Height="23"/>
<Button x:Name="btn_Request" Content="Add request &gt;" Command="{Binding cmdAddRequest}" HorizontalAlignment="Left" Margin="158,370,0,0" VerticalAlignment="Top" Width="90" Height="23
"/>

<Label Content="Value" HorizontalAlignment="Left" Margin="10,396,0,0" VerticalAlignment="Top" Height="23" Width="83"/>
<TextBox x:Name="tb_SetValue" PreviewTextInput="NumberValidationTextBox" Text="{Binding sSetValue, Mode=OneWayToSource}" HorizontalAlignment="Left" Height="23" Margin="10,419,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
<Button x:Name="btn_TrySetValue" Content="Try set value &gt;" Command="{Binding cmdTrySetValue}" IsEnabled="{Binding bConnected}" HorizontalAlignment="Left" Margin="158,419,0,0" VerticalAlignment="Top" Width="90" Height="23"/>

<Ellipse HorizontalAlignment="Left" Height="14" Margin="251,10,0,0" Stroke="Black" VerticalAlignment="Top" Width="14">
<Ellipse.Style>
<Style TargetType="Ellipse">
<Style.Triggers>
<DataTrigger Binding="{Binding bConnected}" Value="false">
<Setter Property="Fill" Value="#FFFF5030" />
</DataTrigger>
<DataTrigger Binding="{Binding bConnected}" Value="true">
<Setter Property="Fill" Value="#FF50FF30" />
</DataTrigger>
<DataTrigger Binding="{Binding bOddTick}" Value="true">
<!-- Assume bOddTick is true only when bConnected is true-->
<Setter Property="Fill" Value="#FF45E2F4" />
</DataTrigger>
</Style.Triggers>
</Style>
</Ellipse.Style>
</Ellipse>

<Label Content="Errors" HorizontalAlignment="Left" Margin="10,454,0,0" VerticalAlignment="Top" Height="23" Width="83"/>

<ListBox ItemsSource="{Binding lErrorMessages}" RenderTransformOrigin="0.5,0.5" Width="236" HorizontalAlignment="Left" Margin="10,482,0,10">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Foreground" Value="Red"/>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VerticalAlignment="Bottom"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>

<Label Content="Frequency" HorizontalAlignment="Left" Margin="183,61,0,0" VerticalAlignment="Top" Height="25"/>
<Slider x:Name="sl_Tick" Value="1000" Thumb.DragCompleted="Slider_DragCompleted" HorizontalAlignment="Left" Margin="183,86,0,0" VerticalAlignment="Top" Width="63" Minimum="100" Maximum="3000" LargeChange="100" SmallChange="10" IsDirectionReversed="True" />
<CheckBox Content="Use FSX-compatible configuration" IsChecked="{Binding bFSXcompatible, Mode=TwoWay}" HorizontalAlignment="Left" Margin="29,121,0,0" VerticalAlignment="Top" Width="217"/>

</Grid>

</Window>
88 changes: 88 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Navigation;

namespace Simvars
{
interface IBaseSimConnectWrapper
{
int GetUserSimConnectWinEvent();
void ReceiveSimConnectMessage();
void SetWindowHandle(IntPtr _hWnd);
void Disconnect();
}
public partial class MainWindow : Window
{
public MainWindow()
{
this.DataContext = new SimvarsViewModel();

InitializeComponent();
}

protected HwndSource GetHWinSource()
{
return PresentationSource.FromVisual(this) as HwndSource;
}

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
GetHWinSource().AddHook(WndProc);
if (this.DataContext is IBaseSimConnectWrapper oBaseSimConnectWrapper)
{
oBaseSimConnectWrapper.SetWindowHandle(GetHWinSource().Handle);
}
}

private IntPtr WndProc(IntPtr hWnd, int iMsg, IntPtr hWParam, IntPtr hLParam, ref bool bHandled)
{
if (this.DataContext is IBaseSimConnectWrapper oBaseSimConnectWrapper)
{
try
{
if (iMsg == oBaseSimConnectWrapper.GetUserSimConnectWinEvent())
{
oBaseSimConnectWrapper.ReceiveSimConnectMessage();
}
}
catch
{
oBaseSimConnectWrapper.Disconnect();
}
}

return IntPtr.Zero;
}

private void LinkOnRequestNavigate(object sender, RequestNavigateEventArgs e)
{
System.Diagnostics.Process.Start(e.Uri.ToString());
}

private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
string sText = e.Text;
foreach (char c in sText)
{
if ( ! (('0' <= c && c <= '9') || c == '+' || c == '-' || c == ',') )
{
e.Handled = true;
break;
}
}
}

private void Slider_DragCompleted(object sender, DragCompletedEventArgs e)
{
if (sender is Slider oSlider && this.DataContext is SimvarsViewModel oContext)
{
oContext.SetTickSliderValue((int)oSlider.Value);
}
}
}
}
55 changes: 55 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Simvars")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Simvars")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
71 changes: 71 additions & 0 deletions Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4809e7a

Please sign in to comment.