Skip to content

Commit 35caf44

Browse files
OATControl V0.9.1.0
- Added Pushbutton and made the manual slew control use them. Only slews while pressed now. - Added version number display. - Only supports ESP8266 board currently with IP of 192.168.86.61 (edit in MountVM.cs)
1 parent f97311b commit 35caf44

File tree

9 files changed

+408
-81
lines changed

9 files changed

+408
-81
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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;
7+
using System.Windows.Media;
8+
9+
namespace OATControl.Controls
10+
{
11+
public class Arrow : FrameworkElement
12+
{
13+
private Pen _pen;
14+
private double _angle;
15+
16+
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register(
17+
"Angle",
18+
typeof(double),
19+
typeof(Arrow),
20+
new PropertyMetadata(0.0, Arrow.SomePropertyChanged));
21+
22+
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register(
23+
"Background",
24+
typeof(Brush),
25+
typeof(Arrow),
26+
new PropertyMetadata(Brushes.White, Arrow.SomePropertyChanged));
27+
28+
public static readonly DependencyProperty ForegroundProperty = DependencyProperty.Register(
29+
"Foreground",
30+
typeof(Brush),
31+
typeof(Arrow),
32+
new PropertyMetadata(Brushes.Black, Arrow.SomePropertyChanged));
33+
34+
35+
//public static readonly DependencyProperty ScaleProperty = DependencyProperty.Register(
36+
// "Scale",
37+
// typeof(double),
38+
// typeof(Arrow),
39+
// new PropertyMetadata(1.0, Arrow.SomePropertyChanged));
40+
41+
private static void SomePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
42+
{
43+
var pointer = obj as Arrow;
44+
pointer.InvalidateVisual();
45+
}
46+
47+
48+
public double Angle
49+
{
50+
get
51+
{
52+
return (double)this.GetValue(Arrow.AngleProperty);
53+
}
54+
set
55+
{
56+
this.SetValue(Arrow.AngleProperty, value);
57+
}
58+
}
59+
60+
public Brush Foreground
61+
{
62+
get
63+
{
64+
return (Brush)this.GetValue(Arrow.ForegroundProperty);
65+
}
66+
set
67+
{
68+
this.SetValue(Arrow.ForegroundProperty, value);
69+
}
70+
}
71+
72+
public Brush Background
73+
{
74+
get
75+
{
76+
return (Brush)this.GetValue(Arrow.BackgroundProperty);
77+
}
78+
set
79+
{
80+
this.SetValue(Arrow.BackgroundProperty, value);
81+
}
82+
}
83+
84+
//public double Scale
85+
//{
86+
// get
87+
// {
88+
// return (double)this.GetValue(Arrow.ScaleProperty);
89+
// }
90+
// set
91+
// {
92+
// this.SetValue(Arrow.ScaleProperty, value);
93+
// }
94+
//}
95+
96+
protected override Size MeasureOverride(Size availableSize)
97+
{
98+
return availableSize;
99+
}
100+
101+
protected override void OnRender(DrawingContext dc)
102+
{
103+
//double Scale = 1;
104+
105+
dc.PushTransform(new RotateTransform(Angle,RenderSize.Width/2, RenderSize.Height/2));
106+
Point p1 = new Point(0.2 * RenderSize.Width, 0.05 * RenderSize.Height);
107+
Point p2 = new Point(0.8 * RenderSize.Width, 0.50 * RenderSize.Height);
108+
Point p3 = new Point(0.2 * RenderSize.Width, 0.95 * RenderSize.Height);
109+
StreamGeometry streamGeometry = new StreamGeometry();
110+
using (StreamGeometryContext geometryContext = streamGeometry.Open())
111+
{
112+
geometryContext.BeginFigure(p1, true, true);
113+
PointCollection points = new PointCollection { p2, p3 };
114+
geometryContext.PolyLineTo(points, true, true);
115+
}
116+
117+
streamGeometry.Freeze();
118+
Pen pen = new Pen(Foreground, 1.5);
119+
dc.DrawGeometry(Background, pen, streamGeometry);
120+
//dc.DrawLine(_pen, p1, p2);
121+
//dc.DrawLine(_pen, p2, p3);
122+
//dc.DrawLine(_pen, p3, p1);
123+
124+
//Geometry
125+
//dc.DrawRectangle
126+
////Point center = new Point(RenderSize.Width / 2, RenderSize.Height / 2);
127+
//Point cursorPos = new Point(center.X, center.Y );
128+
129+
//dc.DrawEllipse(null, _pen, cursorPos, 10, 10);
130+
//dc.DrawEllipse(null, _pen, cursorPos, 5, 5);
131+
132+
//Point p1 = new Point(cursorPos.X - 12, cursorPos.Y);
133+
//Point p2 = new Point(cursorPos.X + 12, cursorPos.Y);
134+
//dc.DrawLine(_pen, p1, p2);
135+
136+
//p1 = new Point(cursorPos.X, cursorPos.Y - 12);
137+
//p2 = new Point(cursorPos.X, cursorPos.Y + 12);
138+
//dc.DrawLine(_pen, p1, p2);
139+
}
140+
}
141+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<UserControl x:Class="OATControl.Controls.PushButton"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:OATControl.Controls"
7+
mc:Ignorable="d"
8+
Name="ThisPushButton"
9+
d:DesignHeight="148" d:DesignWidth="148" >
10+
11+
<Grid x:Name="MainGrid" Background="Transparent" IsHitTestVisible="True" MouseDown="MainGrid_OnMouseButtonDown" MouseUp="MainGrid_OnMouseButtonUp" >
12+
<Grid.Resources>
13+
<Style x:Key="arrowStyle" TargetType="{x:Type local:Arrow}" x:Name="arrowStyle">
14+
<Setter Property="Foreground" Value="{StaticResource HighlightBrush}" />
15+
<Setter Property="Background" Value="{StaticResource AccentColorBrush4}" />
16+
<Style.Triggers>
17+
<DataTrigger Binding="{Binding IsMouseOver, ElementName=MainGrid}" Value="True">
18+
<Setter Property="Foreground" Value="{StaticResource HighlightBrush}" />
19+
<Setter Property="Background" Value="{StaticResource AccentColorBrush2}" />
20+
</DataTrigger>
21+
<DataTrigger Binding="{Binding IsPressed, ElementName=ThisPushButton}" Value="True">
22+
<Setter Property="Foreground" Value="{StaticResource HighlightBrush}" />
23+
<Setter Property="Background" Value="{StaticResource AccentBaseColorBrush}" />
24+
</DataTrigger>
25+
<DataTrigger Binding="{Binding IsEnabled, ElementName=ThisPushButton}" Value="False">
26+
<Setter Property="Foreground" Value="{StaticResource AccentBaseColorBrush}" />
27+
<Setter Property="Background" Value="{StaticResource AccentBaseColorBrush}" />
28+
</DataTrigger>
29+
</Style.Triggers>
30+
</Style>
31+
</Grid.Resources>
32+
<local:Arrow Angle="{Binding RotAngle, ElementName=ThisPushButton}" Style="{StaticResource arrowStyle}" IsHitTestVisible="False" />
33+
</Grid>
34+
</UserControl>
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
using MahApps.Metro.Converters;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
using System.Windows;
9+
using System.Windows.Controls;
10+
using System.Windows.Data;
11+
using System.Windows.Documents;
12+
using System.Windows.Input;
13+
using System.Windows.Media;
14+
using System.Windows.Media.Animation;
15+
using System.Windows.Media.Imaging;
16+
using System.Windows.Navigation;
17+
using System.Windows.Shapes;
18+
19+
namespace OATControl.Controls
20+
{
21+
/// <summary>
22+
/// Interaction logic for PushButton.xaml
23+
/// </summary>
24+
public partial class PushButton : UserControl
25+
{
26+
/// <summary>
27+
/// The dependency property for the Minimum property
28+
/// </summary>
29+
30+
public static readonly DependencyProperty DirectionProperty = DependencyProperty.Register(
31+
"Direction",
32+
typeof(char),
33+
typeof(PushButton),
34+
new PropertyMetadata('A', PushButton.DirectionPropertyChanged));
35+
36+
public static readonly DependencyProperty IsPressedProperty = DependencyProperty.Register(
37+
"IsPressed",
38+
typeof(bool),
39+
typeof(PushButton),
40+
new PropertyMetadata(false, PushButton.AnyPropertyChanged));
41+
42+
public static readonly DependencyProperty RotAngleProperty = DependencyProperty.Register(
43+
"RotAngle",
44+
typeof(double),
45+
typeof(PushButton),
46+
new PropertyMetadata(0.0, PushButton.AnyPropertyChanged));
47+
48+
public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
49+
"Command",
50+
typeof(ICommand),
51+
typeof(PushButton),
52+
new PropertyMetadata(null, PushButton.AnyPropertyChanged));
53+
54+
public static readonly DependencyProperty CommandParameterProperty = DependencyProperty.Register(
55+
"CommandParameter",
56+
typeof(object),
57+
typeof(PushButton),
58+
new PropertyMetadata(null, PushButton.AnyPropertyChanged));
59+
60+
//
61+
// Summary:
62+
// Gets or sets the parameter to pass to the System.Windows.Controls.Primitives.ButtonBase.Command
63+
// property.
64+
//
65+
// Returns:
66+
// Parameter to pass to the System.Windows.Controls.Primitives.ButtonBase.Command
67+
// property.
68+
[Bindable(true)]
69+
[Category("Action")]
70+
[Localizability(LocalizationCategory.NeverLocalize)]
71+
public object CommandParameter
72+
{
73+
get
74+
{
75+
return this.GetValue(PushButton.CommandParameterProperty);
76+
}
77+
set
78+
{
79+
this.SetValue(PushButton.CommandParameterProperty, value);
80+
}
81+
}
82+
//
83+
// Summary:
84+
// Gets or sets the command to invoke when this button is pressed.
85+
//
86+
// Returns:
87+
// A command to invoke when this button is pressed. The default value is null.
88+
[Bindable(true)]
89+
[Category("Action")]
90+
[Localizability(LocalizationCategory.NeverLocalize)]
91+
public ICommand Command
92+
{
93+
get
94+
{
95+
return (ICommand)this.GetValue(PushButton.CommandProperty);
96+
}
97+
set
98+
{
99+
this.SetValue(PushButton.CommandProperty, value);
100+
}
101+
}
102+
103+
private static void DirectionPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
104+
{
105+
var pushButton = obj as PushButton;
106+
switch (char.ToUpper((char)e.NewValue))
107+
{
108+
case 'N': pushButton.RotAngle = 270.0;break;
109+
case 'E': pushButton.RotAngle = 0.0; break;
110+
case 'W': pushButton.RotAngle = 180.0; break;
111+
case 'S': pushButton.RotAngle = 90.0; break;
112+
}
113+
}
114+
115+
private static void AnyPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
116+
{
117+
var pushButton = obj as PushButton;
118+
}
119+
120+
public PushButton()
121+
{
122+
InitializeComponent();
123+
//this.DataContext = this;
124+
}
125+
126+
[Bindable(true)]
127+
public char Direction
128+
{
129+
get
130+
{
131+
return (char)this.GetValue(PushButton.DirectionProperty);
132+
}
133+
set
134+
{
135+
this.SetValue(PushButton.DirectionProperty, value);
136+
}
137+
}
138+
139+
[Bindable(true)]
140+
public double RotAngle
141+
{
142+
get
143+
{
144+
return (double)this.GetValue(PushButton.RotAngleProperty);
145+
}
146+
set
147+
{
148+
this.SetValue(PushButton.RotAngleProperty, value);
149+
}
150+
}
151+
152+
[Bindable(true)]
153+
public bool IsPressed
154+
{
155+
get
156+
{
157+
return (bool)this.GetValue(PushButton.IsPressedProperty);
158+
}
159+
set
160+
{
161+
this.SetValue(PushButton.IsPressedProperty, value);
162+
}
163+
}
164+
165+
166+
/// <summary>
167+
/// Handles the OnMouseButtonDown event of the MainGrid control. Captures the mouse and sets the current
168+
/// value to the click point. If the textbox currently is active, it is made inactive.
169+
/// </summary>
170+
/// <param name="sender">The source of the event.</param>
171+
/// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param>
172+
private void MainGrid_OnMouseButtonDown(object sender, MouseButtonEventArgs e)
173+
{
174+
if (e.LeftButton == MouseButtonState.Pressed)
175+
{
176+
IsPressed = true;
177+
this.MainGrid.CaptureMouse();
178+
this.Command.Execute("+" + CommandParameter.ToString());
179+
}
180+
}
181+
182+
/// <summary>
183+
/// Handles the OnMouseButtonUp event of the MainGrid control.
184+
/// </summary>
185+
/// <param name="sender">The source of the event.</param>
186+
/// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param>
187+
private void MainGrid_OnMouseButtonUp(object sender, MouseButtonEventArgs e)
188+
{
189+
this.MainGrid.ReleaseMouseCapture();
190+
IsPressed = false;
191+
this.Command.Execute("-" + CommandParameter.ToString());
192+
}
193+
}
194+
}

Software/OpenAstroTracker ASCOM/OATControl/MainWindow.xaml

Lines changed: 5 additions & 7 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:OATControl" xmlns:controls="clr-namespace:OATControl.Controls" xmlns:converters="clr-namespace:OATControl.Converters"
88
mc:Ignorable="d"
9-
Title="OpenAstroTracker Control" MinHeight="675" MinWidth="790" Height="718" Width="790">
9+
Title="{Binding Version, StringFormat={} OpenAstroTracker Control V{0}}" MinHeight="675" MinWidth="790" Height="718" Width="790">
1010
<Window.Resources>
1111
<converters:BoolToStringConverter x:Key="SlewModeConverter" TrueString="Pulsed" FalseString="Continuous" />
1212
<converters:BoolToVisibilityConverter x:Key="CoarseBoolToVisible" Collapse="False" />
@@ -218,12 +218,10 @@
218218
<ColumnDefinition />
219219
</Grid.ColumnDefinitions>
220220

221-
<!--<local:PushButton Grid.Column="1" Grid.Row="0" Width="90" Height="90" />-->
222-
223-
<Button Grid.Column="1" Grid.Row="1" Width="90" Height="90" Content="{StaticResource IconArrowLeft}" Style="{StaticResource ArrowStyle}" Command="{Binding StartSlewingCommand}" CommandParameter="W" />
224-
<Button Grid.Column="2" Grid.Row="0" Width="90" Height="90" Content="{StaticResource IconArrowUp}" Style="{StaticResource ArrowStyle}" Command="{Binding StartSlewingCommand}" CommandParameter="N" Margin="9,0" />
225-
<Button Grid.Column="3" Grid.Row="1" Width="90" Height="90" Content="{StaticResource IconArrowRight}" Style="{StaticResource ArrowStyle}" Command="{Binding StartSlewingCommand}" CommandParameter="E" />
226-
<Button Grid.Column="2" Grid.Row="3" Width="90" Height="90" Content="{StaticResource IconArrowDown}" Style="{StaticResource ArrowStyle}" Command="{Binding StartSlewingCommand}" CommandParameter="S" Margin="9,0" />
221+
<controls:PushButton Grid.Column="1" Grid.Row="1" Width="90" Height="90" Direction="W" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="W" />
222+
<controls:PushButton Grid.Column="2" Grid.Row="0" Width="90" Height="90" Direction="N" Margin="9,0" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="N" />
223+
<controls:PushButton Grid.Column="3" Grid.Row="1" Width="90" Height="90" Direction="E" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="E" />
224+
<controls:PushButton Grid.Column="2" Grid.Row="3" Width="90" Height="90" Direction="S" Margin="9,0" IsEnabled="{Binding MountConnected}" Command="{Binding StartSlewingCommand}" CommandParameter="S" />
227225

228226
<StackPanel Grid.Column="2" Grid.Row="1" Orientation="Vertical">
229227
<Button Margin="2,0,2,2" Style="{StaticResource AccentedSquareButtonStyle}" Command="{Binding StopSlewingCommand}" >Stop</Button>

0 commit comments

Comments
 (0)