Skip to content

Commit 636e290

Browse files
OATControl V0.9.3.0 Updates
- Improved readability of Chooser dialog. - Fixed name display of discovered Wifi devices. - Fixed a cross-thread bug for discovered Wifi devices - Added Rescan button to Device Chooser dialog.
1 parent 96247d1 commit 636e290

File tree

8 files changed

+100
-14
lines changed

8 files changed

+100
-14
lines changed

Software/OATMobile/OATCommunications/ClientAdapters/UdpClientAdapter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ private void ReceiveCallback(IAsyncResult ar)
4444
IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, _port);
4545
byte[] received = _udpClient.EndReceive(ar, ref remoteIpEndPoint);
4646
string result = Encoding.UTF8.GetString(received);
47-
var parts = result.Split('@');
48-
if (parts.Length == 2)
47+
var parts = result.Split(":@".ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
48+
if ((parts.Length == 3) && parts[0].Equals("skyfi"))
4949
{
50-
OnClientFound(new ClientFoundEventArgs("OAT", IPAddress.Parse(parts[1])));
50+
OnClientFound(new ClientFoundEventArgs(parts[1], IPAddress.Parse(parts[2])));
5151
}
5252
_udpClient.BeginReceive(new AsyncCallback(this.ReceiveCallback), null);
5353
}

Software/OpenAstroTracker ASCOM/OATCommuncations.WPF/CommunicationHandlers/CommunicationHandlerFactory.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using static OATCommunications.ClientAdapters.UdpClientAdapter;
88
using OATCommunications.CommunicationHandlers;
99
using System.Collections.ObjectModel;
10+
using OATCommuncations.WPF;
1011

1112
namespace OATCommunications.WPF.CommunicationHandlers
1213
{
@@ -15,20 +16,24 @@ public static class CommunicationHandlerFactory
1516
static ObservableCollection<string> _available = new ObservableCollection<string>();
1617
public static void DiscoverDevices()
1718
{
19+
_available.Clear();
1820
foreach (var port in SerialPort.GetPortNames())
1921
{
2022
_available.Add("Serial : " + port);
2123
}
2224

23-
var searcher = new UdpClientAdapter("OATerScope", 4031);
25+
var searcher = new UdpClientAdapter("OAT", 4031);
2426
searcher.ClientFound += OnWifiClientFound;
2527
searcher.StartClientSearch();
2628
}
2729

28-
private static void OnWifiClientFound(object sender, ClientFoundEventArgs e)
29-
{
30-
_available.Add($"WiFi : {e.Name} ({e.Address}:4030)");
31-
}
30+
private static void OnWifiClientFound(object sender, ClientFoundEventArgs e) => WpfUtilities.RunOnUiThread(
31+
() =>
32+
{
33+
_available.Insert(0, $"WiFi : {e.Name} ({e.Address}:4030)");
34+
35+
},
36+
System.Windows.Application.Current.Dispatcher);
3237

3338
public static ObservableCollection<String> AvailableDevices { get { return _available; } }
3439

Software/OpenAstroTracker ASCOM/OATCommuncations.WPF/OATCommuncations.WPF.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="PresentationCore" />
35+
<Reference Include="PresentationFramework" />
3436
<Reference Include="System" />
3537
<Reference Include="System.Core" />
3638
<Reference Include="System.Xml.Linq" />
@@ -39,11 +41,13 @@
3941
<Reference Include="System.Data" />
4042
<Reference Include="System.Net.Http" />
4143
<Reference Include="System.Xml" />
44+
<Reference Include="WindowsBase" />
4245
</ItemGroup>
4346
<ItemGroup>
4447
<Compile Include="CommunicationHandlers\CommunicationHandlerFactory.cs" />
4548
<Compile Include="CommunicationHandlers\SerialCommunicationHandler.cs" />
4649
<Compile Include="Properties\AssemblyInfo.cs" />
50+
<Compile Include="WpfUtilities.cs" />
4751
</ItemGroup>
4852
<ItemGroup>
4953
<ProjectReference Include="..\..\OATMobile\OATCommunications\OATCommunications.csproj">
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using System.Windows.Threading;
7+
8+
namespace OATCommuncations.WPF
9+
{
10+
public class WpfUtilities
11+
{
12+
/// <summary>
13+
/// Runs the given action using the given dispatcher to determine the thread to run on.
14+
/// </summary>
15+
/// <param name="action">The action.</param>
16+
public static void RunOnUiThread(Action action, Dispatcher dispatcher)
17+
{
18+
// If we're on another thread, check whether the main thread dispatcher is available
19+
// If the dispatcher is available, do a synchronous update, else asynchronous
20+
if (dispatcher.CheckAccess())
21+
{
22+
// If the dispatcher is available, do a synchronous update
23+
action();
24+
}
25+
else
26+
{
27+
try
28+
{
29+
// If the dispatcher is available, do an asynchronous update
30+
dispatcher.Invoke(action);
31+
}
32+
catch (Exception e)
33+
{
34+
dispatcher.BeginInvoke(action);
35+
}
36+
}
37+
}
38+
}
39+
}

Software/OpenAstroTracker ASCOM/OATControl/DlgChooseOat.xaml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,56 @@
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
xmlns:local="clr-namespace:OATControl"
88
mc:Ignorable="d"
9-
Title="Connect to OpenAstroTracker" Height="225.39" Width="349.862" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow">
9+
Title="Connect to OpenAstroTracker" Height="312.39" Width="359.862" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" WindowStyle="ToolWindow">
10+
<Controls:MetroWindow.Resources>
11+
<Style x:Key="ListItemsStyle" TargetType="ListBoxItem">
12+
<Setter Property="Margin" Value="5,3,5,1" />
13+
<Setter Property="Padding" Value="3" />
14+
<Setter Property="BorderThickness" Value="1" />
15+
<Setter Property="BorderBrush" Value="{StaticResource AccentBaseColorBrush}" />
16+
<Setter Property="Background" Value="{StaticResource AccentColorBrush2}" />
17+
<Setter Property="Foreground" Value="{StaticResource AccentSelectedColorBrush}" />
18+
</Style>
19+
<ItemsPanelTemplate x:Key="ListBoxItemsPanel">
20+
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" VerticalAlignment="Stretch" Background="{StaticResource WhiteBrush}"/>
21+
</ItemsPanelTemplate>
22+
</Controls:MetroWindow.Resources>
1023
<Grid>
1124
<Grid.ColumnDefinitions>
1225
<ColumnDefinition Width="Auto" />
1326
<ColumnDefinition Width="*" />
1427
</Grid.ColumnDefinitions>
1528
<Grid.RowDefinitions>
1629
<RowDefinition Height="Auto" />
17-
<RowDefinition Height="*" />
30+
<RowDefinition Height="129*" />
31+
<RowDefinition Height="61*"/>
1832
<RowDefinition Height="Auto" />
1933
</Grid.RowDefinitions>
20-
<TextBlock Grid.Row="0" Grid.Column="0" Text="Available Connections" Margin="10,24,10,0" Style="{StaticResource MetroTextBlock}" />
21-
<ComboBox Grid.Row="0" Grid.Column="1" Text="--- Choose Connection ---" Margin="0,20,10,0" ItemsSource="{Binding AvailableDevices}" SelectedItem="{Binding SelectedDevice}"/>
22-
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
34+
<TextBlock Grid.Row="0" Grid.Column="0" Text="Available Connections" Margin="10,24,10,0" Foreground="{StaticResource AccentSelectedColorBrush}" />
35+
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Grid.ColumnSpan="2">
36+
<Button Content="Rescan" Command="{Binding RescanCommand}" Margin="10,10,60,10" Width="80" Style="{StaticResource AccentedSquareButtonStyle}" />
2337
<Button Content="OK" Command="{Binding OKCommand}" Margin="10" Width="80" Style="{StaticResource AccentedSquareButtonStyle}" IsDefault="True" />
2438
<Button Content="Cancel" Margin="10" Width="80" Style="{StaticResource AccentedSquareButtonStyle}" IsCancel="True" />
2539
</StackPanel>
40+
<ListBox Grid.Row="1" Grid.ColumnSpan="2"
41+
VerticalAlignment="Top"
42+
ItemsSource="{Binding AvailableDevices,Mode=OneWay}"
43+
ItemsPanel="{StaticResource ListBoxItemsPanel}"
44+
SelectedItem="{Binding SelectedDevice}"
45+
BorderThickness="0"
46+
ItemContainerStyle="{StaticResource ListItemsStyle}"
47+
MinHeight="18"
48+
HorizontalAlignment="Stretch"
49+
MinWidth="20"
50+
Background="Transparent" >
51+
<ListBox.ItemTemplate>
52+
<DataTemplate DataType="string">
53+
<Grid >
54+
<TextBlock Text="{Binding}" Style="{StaticResource MetroTextBlock}"/>
55+
</Grid>
56+
</DataTemplate>
57+
</ListBox.ItemTemplate>
58+
</ListBox>
59+
2660
</Grid>
2761
</Controls:MetroWindow>

Software/OpenAstroTracker ASCOM/OATControl/DlgChooseOat.xaml.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ namespace OATControl
2323
public partial class DlgChooseOat : MetroWindow
2424
{
2525
private DelegateCommand _okCommand;
26+
private DelegateCommand _rescanCommand;
2627
public DlgChooseOat()
2728
{
2829
_okCommand = new DelegateCommand(() => { this.DialogResult = true; Close(); });
30+
_rescanCommand = new DelegateCommand(() => { CommunicationHandlerFactory.DiscoverDevices(); });
2931

3032
this.DataContext = this;
3133
InitializeComponent();
3234

3335
}
3436

3537
public ICommand OKCommand { get { return _okCommand; } }
38+
public ICommand RescanCommand { get { return _rescanCommand; } }
3639

3740
public IList<string> AvailableDevices
3841
{

Software/OpenAstroTracker ASCOM/OATControl/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
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("0.9.2.0")]
54+
[assembly: AssemblyVersion("0.9.3.0")]
5555
[assembly: AssemblyFileVersion("1.0.0.0")]

Software/OpenAstroTracker ASCOM/OATControl/ViewModels/MountVM.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ private async void OnConnectToTelescope()
353353
{
354354
if (MountConnected)
355355
{
356+
MountConnected = false;
356357
_commHandler.Disconnect();
357358
_oatMount = null;
358359
_commHandler = null;

0 commit comments

Comments
 (0)