From dbfde8706313c147a28b16bcc7e7fef158d930bb Mon Sep 17 00:00:00 2001 From: Roy Date: Sat, 10 Feb 2018 23:23:29 +0200 Subject: Implemented GPIO Controller. --- .../Editors/IOElementEditor.xaml | 106 +++++++++++++++++++++ .../Editors/IOElementEditor.xaml.cs | 102 ++++++++++++++++++++ .../Images/binary.png | Bin 0 -> 2163 bytes .../PropertiesTemplates/DispenserTemplate.xaml | 2 +- .../PropertiesTemplates/IOTemplate.xaml | 33 +++++++ .../PropertiesTemplates/IOTemplate.xaml.cs | 37 +++++++ .../Tango.MachineStudio.Technician.csproj | 18 ++++ .../TechItems/IOItem.cs | 72 ++++++++++++++ .../ViewModels/MachineTechViewVM.cs | 35 ++++++- .../Views/MachineTechView.xaml | 3 + 10 files changed, 405 insertions(+), 3 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/binary.png create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/IOItem.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml new file mode 100644 index 000000000..aa4f8aee6 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + GPIO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml.cs new file mode 100644 index 000000000..95710abd3 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Editors/IOElementEditor.xaml.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Markup; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using Tango.Editors; +using Tango.Integration.Observables; +using Tango.MachineStudio.Technician.TechItems; + +namespace Tango.MachineStudio.Technician.Editors +{ + [ContentProperty("InnerContent")] + public partial class IOElementEditor : ElementEditor + { + /// + /// Initializes a new instance of the class. + /// + public IOElementEditor() + : base() + { + InitializeComponent(); + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + public IOElementEditor(IOItem ioItem) + : this() + { + IOItem = ioItem; + DataContext = IOItem; + } + + /// + /// Initializes a new instance of the class. + /// + /// The framework element. + /// The bounds. + public IOElementEditor(IOItem monitorItem, Rect bounds) + : this(monitorItem) + { + Left = bounds.Left; + Top = bounds.Top; + Width = bounds.Width; + Height = bounds.Height; + } + + private IOItem _monitorItem; + + public IOItem IOItem + { + get { return _monitorItem; } + set { _monitorItem = value; RaisePropertyChanged(nameof(IOItem)); } + } + + + /// + /// Clones this instance. + /// + /// + public override IElementEditor Clone() + { + try + { + var clonedItem = IOItem.Clone() as IOItem; + IOElementEditor cloned = new IOElementEditor(clonedItem); + cloned.Top = Top; + cloned.Left = Left; + cloned.Width = Width; + cloned.Height = Height; + cloned.Angle = Angle; + return cloned; + } + catch (Exception ex) + { + throw new InvalidOperationException("Could not clone this editor. You may have to create a custom editor and implement a custom Clone method.", ex); + } + } + + /// + /// Gets the hosted element. + /// + [ParameterIgnore] + public override Object HostedElement + { + get { return IOItem; } + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/binary.png b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/binary.png new file mode 100644 index 000000000..24b399f96 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Images/binary.png differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DispenserTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DispenserTemplate.xaml index 0eca72dcd..a732e2924 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DispenserTemplate.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/DispenserTemplate.xaml @@ -22,7 +22,7 @@ - + Selected Motor diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml new file mode 100644 index 000000000..c03b72837 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + Selected Port + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml.cs new file mode 100644 index 000000000..fae3586dc --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/PropertiesTemplates/IOTemplate.xaml.cs @@ -0,0 +1,37 @@ +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.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.Technician.PropertiesTemplates +{ + /// + /// Interaction logic for MonitorTemplate.xaml + /// + public partial class IOTemplate : UserControl + { + public IOTemplate() + { + InitializeComponent(); + + List ports = new List(); + + for (int i = 0; i < 120; i++) + { + ports.Add(i); + } + + combo.ItemsSource = ports; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj index 34208aded..9af2c8ef8 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Tango.MachineStudio.Technician.csproj @@ -100,6 +100,9 @@ DispenserElementEditor.xaml + + IOElementEditor.xaml + MotorElementEditor.xaml @@ -116,6 +119,9 @@ MonitorElementEditor.xaml + + IOTemplate.xaml + MeterTemplate.xaml @@ -134,6 +140,7 @@ SingleGraphTemplate.xaml + @@ -171,6 +178,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -191,6 +202,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -358,5 +373,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/IOItem.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/IOItem.cs new file mode 100644 index 000000000..c0a87842a --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechItems/IOItem.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; +using System.Xml.Serialization; +using Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Technician.TechItems +{ + public class IOItem : TechItem + { + public event EventHandler ValueChanged; + + public override object Data => new object(); + + private int _port; + + public int Port + { + get { return _port; } + set { _port = value; RaisePropertyChangedAuto(); } + } + + private bool _value; + [XmlIgnore] + public bool Value + { + get { return _value; } + set { _value = value; RaisePropertyChangedAuto(); ValueChanged?.Invoke(this, value); } + } + + private bool _effectiveValue; + [XmlIgnore] + public bool EffectiveValue + { + get { return _effectiveValue; } + set + { + if (_effectiveValue != value) + { + _effectiveValue = value; + RaisePropertyChangedAuto(); + _value = value; + RaisePropertyChanged(nameof(Value)); + } + } + } + + + public IOItem() : base() + { + Name = "GPIO Controller"; + Description = "GPIO Controller"; + Image = ResourceHelper.GetImageFromResources("Images/binary.png"); + Color = Colors.White; + } + + public IOItem(int port) : this() + { + Port = port; + } + + public override TechItem Clone() + { + IOItem cloned = base.Clone() as IOItem; + cloned.Port = Port; + return cloned; + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 8ed8a4a80..21d2c50c2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -116,6 +116,15 @@ namespace Tango.MachineStudio.Technician.ViewModels } } } + else if (item.GetType() == typeof(IOItem)) + { + IOItem ioItem = item as IOItem; + + if (ioItem.Port < data.GPIO.Count) + { + ioItem.EffectiveValue = data.GPIO[ioItem.Port]; + } + } else if (item.GetType() == typeof(MeterItem)) { MeterItem meterItem = item as MeterItem; @@ -260,6 +269,13 @@ namespace Tango.MachineStudio.Technician.ViewModels Elements.Add(editor); InitDispenserItem(dispenserItem); } + else if (SelectedTechItem is IOItem) + { + var ioItem = new IOItem(0); + IOElementEditor editor = new IOElementEditor(ioItem, bounds); + Elements.Add(editor); + InitIOItem(ioItem); + } } public void OnElementsRemoved(List elements) @@ -366,13 +382,13 @@ namespace Tango.MachineStudio.Technician.ViewModels { Code = item.TechMotor.Code }) - .Subscribe((response) => + .Subscribe((response) => { item.HomingMaximumProgress = response.Message.MaxProgress; item.HomingProgress = response.Message.Progress; - }, () => + }, () => { item.IsHoming = false; @@ -461,5 +477,20 @@ namespace Tango.MachineStudio.Technician.ViewModels } }; } + + private void InitIOItem(IOItem item) + { + item.ValueChanged += async (x, value) => + { + try + { + await MachineOperator.SetGPIOState(new SetGPIOStateRequest() { Port = item.Port, Value = value }); + } + catch (Exception ex) + { + //TODO: Show Exception. + } + }; + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml index 9e3970719..494f0892f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/Views/MachineTechView.xaml @@ -200,6 +200,9 @@ + + + -- cgit v1.3.1