Skip to content

Commit

Permalink
V0.9.9.24 Updates
Browse files Browse the repository at this point in the history
- Added a mini controller that shows RA/DEC and allows manual slewing, homing and park, with keyboard support.
- Site altitude is now persisted across sessions.
- Connections are attempted multiple times if they fail.
- Prevented crashes when the firmware said GPS or Digital Level was attached, but weren't actually connected.
- Window positions are persisted across sessions.
- Moved Settings button down to above Connect button.
  • Loading branch information
ClutchplateDude committed Feb 13, 2021
1 parent c7a2d9f commit 1e56f99
Show file tree
Hide file tree
Showing 13 changed files with 343 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,26 @@ private bool EnsurePortIsOpen()
{
if (!_port.IsOpen)
{
try
{
Log.WriteLine("SERIAL: Port {0} is not open, attempting to open...", _portName);
_port.Open();
Thread.Sleep(750); // Arduino resets on connection. Give it time to start up.
Log.WriteLine("SERIAL: Port is open, sending initial [:I#] command..");
_port.Write(":I#");
return true;
}
catch (Exception ex)
int attempts = 0;
do
{
Log.WriteLine("SERIAL: Failed to open the port. {0}", ex.Message);
return false;
attempts++;
try
{
Log.WriteLine("SERIAL: Port {0} is not open, attempt {1} to open...", _portName, attempts);
_port.Open();
Thread.Sleep(750); // Arduino resets on connection. Give it time to start up.
Log.WriteLine("SERIAL: Port is open, sending initial [:I#] command..");
_port.Write(":I#");
return true;
}
catch (Exception ex)
{
Log.WriteLine("SERIAL: Failed to open the port on attempt {1}. {0}", ex.Message, attempts);
Thread.Sleep(250); // Wait a little before trying again.
}
}
while (attempts < 10);
}
return true;
}
Expand Down
8 changes: 7 additions & 1 deletion OATControl/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@
<setting name="SiteLongitude" serializeAs="String">
<value>-75</value>
</setting>
<setting name="MiniControllerPos" serializeAs="String">
<value>-1, -1</value>
</setting>
<setting name="WindowPos" serializeAs="String">
<value>-1, -1</value>
</setting>
<setting name="SiteAltitude" serializeAs="String">
<value>100</value>
</setting>
</OATControl.Properties.Settings>
</userSettings>
</configuration>
</configuration>
24 changes: 17 additions & 7 deletions OATControl/DlgChooseOat.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ private void AdvanceStateMachine()
Task.Run(() => _mountViewModel.SetSiteLongitude(Longitude)).Wait();
Settings.Default.SiteLatitude = Latitude;
Settings.Default.SiteLongitude = Longitude;
Settings.Default.SiteAltitude = Altitude;
Settings.Default.Save();
CurrentStep = Steps.Completed;
break;
Expand Down Expand Up @@ -403,10 +404,13 @@ private async void ProcessStateMachine(object sender, EventArgs e)
// Get the reference angles from the level.
_sendCommand(":XLGR#,#", (a) =>
{
string referenceAngles = a.Data;
var angles = referenceAngles.Split(",".ToCharArray());
float.TryParse(angles[0], NumberStyles.Float, _oatCulture, out float _pitchReference);
float.TryParse(angles[1], NumberStyles.Float, _oatCulture, out float _rollReference);
if (a.Success)
{
string referenceAngles = a.Data;
var angles = referenceAngles.Split(",".ToCharArray());
float.TryParse(angles[0], NumberStyles.Float, _oatCulture, out float _pitchReference);
float.TryParse(angles[1], NumberStyles.Float, _oatCulture, out float _rollReference);
}
doneEvent.Set();
});
doneEvent.WaitOne();
Expand All @@ -433,7 +437,7 @@ private async void ProcessStateMachine(object sender, EventArgs e)
_sendCommand(":XLGC#,#", (a) =>
{
string currentAngles = a.Data;
if (!currentAngles.Contains("NAN"))
if (a.Success && !currentAngles.Contains("NAN"))
{
var angles = currentAngles.Split(",".ToCharArray());
float.TryParse(angles[0], NumberStyles.Float, _oatCulture, out float currentPitch);
Expand All @@ -455,8 +459,14 @@ private async void ProcessStateMachine(object sender, EventArgs e)
doneEvent.Set();
});
await doneEvent.WaitAsync();
RollOffset = _rollOffsetHistory.Average();
PitchOffset = _pitchOffsetHistory.Average();
if (_rollOffsetHistory.Any())
{
RollOffset = _rollOffsetHistory.Average();
}
if (_pitchOffsetHistory.Any())
{
PitchOffset = _pitchOffsetHistory.Average();
}
}
break;

Expand Down
11 changes: 7 additions & 4 deletions OATControl/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@
</LinearGradientBrush>
</Border.BorderBrush>
</Border>

<Button Grid.Row="7" Grid.Column="12" Grid.ColumnSpan="3" Content="Settings" Margin="2,10,6,10" Padding="0" IsEnabled="{Binding MountConnected}" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowSettingsCommand}"/>
</Grid>

<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1">
Expand Down Expand Up @@ -448,6 +446,8 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -539,8 +539,11 @@
<TextBlock Grid.Column="2" Text="On" FontSize="10" Margin="0,-4,0,0" FontWeight="Bold" />
</Grid>

<Button Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="2" Content="Mini-Control" Margin="2,2,0,2" HorizontalAlignment="Right" Padding="15,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowMiniControllerCommand}"/>
<Button Grid.Row="6" Grid.Column="2" Grid.ColumnSpan="3" Content="Settings" Margin="2,2,0,2" HorizontalAlignment="Right" Padding="15,0" IsEnabled="{Binding MountConnected}" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ShowSettingsCommand}"/>


<Grid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="4" >
<Grid Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="4" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Expand All @@ -549,7 +552,7 @@
<TextBlock Grid.Row="0" Grid.Column="1" Text="Mount" Style="{StaticResource TextBlockHeading}" Margin="0,10,0,0" HorizontalAlignment="Right"/>
<Button Grid.Column="2" Margin="10,12,0,0" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ConnectScopeCommand}" Content="{Binding ConnectCommandString}"/>
</Grid>
<TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding ScopeName}" Style="{StaticResource TextBlockLabel}" Margin="0,2,0,0" HorizontalAlignment="Right" />
<TextBlock Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="3" Text="{Binding ScopeName}" Style="{StaticResource TextBlockLabel}" Margin="0,2,0,0" HorizontalAlignment="Right" />
</Grid>

</Grid>
Expand Down
12 changes: 12 additions & 0 deletions OATControl/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MahApps.Metro.Controls;
using OATControl.Properties;
using OATControl.ViewModels;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -31,10 +32,21 @@ public MainWindow()
this.DataContext = mountVm;
}

protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
if (Settings.Default.WindowPos.X != -1)
{
this.Left = Math.Max(0, Math.Min(Settings.Default.WindowPos.X, System.Windows.SystemParameters.VirtualScreenWidth - 100));
this.Top = Math.Max(0, Math.Min(Settings.Default.WindowPos.Y, System.Windows.SystemParameters.VirtualScreenHeight- 100));
}
}
protected override void OnClosing(CancelEventArgs e)
{
mountVm.Disconnect();
base.OnClosing(e);
Settings.Default.WindowPos = new System.Drawing.Point((int)Math.Max(0, this.Left), (int)Math.Max(0, this.Top));
Settings.Default.Save();
}

private void TextBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
Expand Down
63 changes: 63 additions & 0 deletions OATControl/MiniController.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Window x:Class="OATControl.MiniController"
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:OATControl" xmlns:controls="clr-namespace:OATControl.Controls"
mc:Ignorable="d"
Title="Mini OAT Control" Height="75" MinHeight="75" MaxHeight="75" Width="330" MaxWidth="330" MinWidth="330" WindowStyle="None" >
<Window.Resources>
<Style x:Key="TextBlockHeading" TargetType="TextBlock" BasedOn="{StaticResource MetroTextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="FontSize" Value="20" />
<Setter Property="Margin" Value="2,0" />
<Setter Property="Padding" Value="6,0" />
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
<Style x:Key="TextBlockLabel" TargetType="TextBlock" BasedOn="{StaticResource TextBlockHeading}">
<Setter Property="Padding" Value="2,0" />
<Setter Property="HorizontalAlignment" Value="Left" />
</Style>
<Style x:Key="TextBlockLabelSmall" TargetType="TextBlock" BasedOn="{StaticResource TextBlockLabel}">
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="4,4" />
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
<Style x:Key="TextBlockLabelValue" TargetType="TextBlock" BasedOn="{StaticResource TextBlockLabelSmall}">
<Setter Property="Padding" Value="12,2" />
<Setter Property="Margin" Value="0,4" />
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Background" Value="{StaticResource AccentColorBrush2}" />
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="95"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="80"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="RA:" Style="{StaticResource TextBlockLabelSmall}" MouseDown="TextBlock_MouseDown" MouseUp="TextBlock_MouseUp" MouseMove="TextBlock_MouseMove" Cursor="SizeAll" />
<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding CurrentRAString}" Style="{StaticResource TextBlockLabelValue}" />

<controls:PushButton Grid.RowSpan="2" Grid.Column="2" Width="36" Height="32" Direction="W" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="W" />
<controls:PushButton Grid.Row="0" Grid.Column="3" Width="36" Height="36" Direction="N" Padding="0,0,0,4" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="N" />
<controls:PushButton Grid.Row="1" Grid.Column="3" Width="36" Height="36" Direction="S" Padding="0,0,0,4" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="S" />
<controls:PushButton Grid.RowSpan="2" Grid.Column="4" Width="36" Height="32" Direction="E" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="E" />

<TextBlock Grid.Row="1" Grid.Column="0" Text="DEC:" Style="{StaticResource TextBlockLabelSmall}" MouseDown="TextBlock_MouseDown" MouseUp="TextBlock_MouseUp" MouseMove="TextBlock_MouseMove" Cursor="SizeAll" />
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding CurrentDECString}" Style="{StaticResource TextBlockLabelValue}" />

<Button Grid.Row="0" Grid.Column="5" Margin="8,2" Padding="10,0" Content="Home" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding HomeCommand}"/>
<Button Grid.Row="1" Grid.Column="5" Margin="8,2" Padding="10,0" Content="{Binding ParkCommandString}" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding ParkCommand}"/>

</Grid>
</Window>
112 changes: 112 additions & 0 deletions OATControl/MiniController.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using OATControl.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace OATControl
{
/// <summary>
/// Interaction logic for MiniController.xaml
/// </summary>
public partial class MiniController : Window
{
MountVM _mount;
private Point _startCapturePos;
private Point _startWindowPos;

public MiniController(MountVM mount)
{
_mount = mount;
this.DataContext = mount;
InitializeComponent();
}

protected override void OnKeyDown(KeyEventArgs e)
{
string cmdParam = string.Empty;
switch (e.Key)
{
case Key.Up: cmdParam = "+N"; break;
case Key.Down: cmdParam = "+S"; break;
case Key.Left: cmdParam = "+W"; break;
case Key.Right: cmdParam = "+E"; break;
}

if (!String.IsNullOrEmpty(cmdParam))
{
_mount.StartSlewingCommand.Execute(cmdParam);
e.Handled = true;
}

base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyEventArgs e)
{
string cmdParam = string.Empty;
switch (e.Key)
{
case Key.H: _mount.HomeCommand.Execute(null); e.Handled = true; break;
case Key.P: _mount.ParkCommand.Execute(null); e.Handled = true; break;
case Key.Up: cmdParam = "-N"; break;
case Key.Down: cmdParam = "-S"; break;
case Key.Left: cmdParam = "-W"; break;
case Key.Right: cmdParam = "-E"; break;
case Key.Escape: this.Hide(); break;
}

if (!String.IsNullOrEmpty(cmdParam))
{
_mount.StartSlewingCommand.Execute(cmdParam);
e.Handled = true;
}

base.OnKeyUp(e);
}

private void TextBlock_MouseDown(object sender, MouseButtonEventArgs e)
{
UIElement el = (UIElement)sender;
if (el.IsEnabled)
{
el.CaptureMouse();
_startCapturePos = PointToScreen(e.GetPosition(el));
_startWindowPos = new Point(this.Left, this.Top);
e.Handled = true;
}
}

private void TextBlock_MouseUp(object sender, MouseButtonEventArgs e)
{
UIElement el = (UIElement)sender;
if (el.IsMouseCaptured)
{
el.ReleaseMouseCapture();
e.Handled = true;
}
}

private void TextBlock_MouseMove(object sender, MouseEventArgs e)
{
UIElement el = (UIElement)sender;
if (el.IsMouseCaptured)
{
var mousePos = PointToScreen(e.GetPosition(el));
var delta = new Point(_startCapturePos.X - mousePos.X, _startCapturePos.Y - mousePos.Y);
this.Left = _startWindowPos.X - delta.X;
this.Top = _startWindowPos.Y - delta.Y;
e.Handled = true;
}
}
}
}
7 changes: 7 additions & 0 deletions OATControl/OATControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
<Compile Include="LevelDisplay.xaml.cs">
<DependentUpon>LevelDisplay.xaml</DependentUpon>
</Compile>
<Compile Include="MiniController.xaml.cs">
<DependentUpon>MiniController.xaml</DependentUpon>
</Compile>
<Compile Include="SettingsDialog.xaml.cs">
<DependentUpon>SettingsDialog.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -122,6 +125,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MiniController.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Resources\RedControls.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
2 changes: 1 addition & 1 deletion OATControl/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 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("0.9.9.23")]
[assembly: AssemblyVersion("0.9.9.24")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 1e56f99

Please sign in to comment.