diff --git a/DMX/ClassDiagram1.cd b/DMX/ClassDiagram1.cd index 7a79a65..8d69c9f 100644 --- a/DMX/ClassDiagram1.cd +++ b/DMX/ClassDiagram1.cd @@ -1,53 +1,53 @@  - + - AAAAAAAAAAAIgoABIAOAACCAgAAIAAABABwQgQAgEAA= + AACAAAAAAAAIgoABIgOAACCAgAAIAAABABQggQAgAAA= Entities\LedMovinghead.cs - + - AAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAABgQAAAAEAA= + AAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAABAAAAAAAAA= Entities\LedSpot.cs - + - AAAAAAAAAABAAAAAAAAIAAAAAAAAAAAAABgQAAAAEAA= + AAAAAAAAAABAAAAAAAAIAAAAAAAAAAAAABAAAAAAAAA= Entities\LedPanel.cs - + - AAAAAAAAAAAAgoABIAOAAACAgAAAAAABABgQAQAgEAA= + AAAAAAAAAAAAgoABIAOAAACAgAAAAAABABAAAQAgAAA= Entities\LaserMovinghead.cs - + - IAAgAAAEAACAIAAAAAMIAAAAAAAAAAAAABgQAAAgEAA= + IAAgAAAEAACAIAAAAAMIAAAAAAAAAAAAABAAAAAgAAA= Entities\LedScanner.cs - + - IAAAAAAAAAAAAAAAAAAAAAYAAAAmAAAAAAAAAAAAAAA= - DmxDevice.cs + IAAAAAAAAAAAAAAAAAAAAAYAAAAmAAAAAAAQAAAAEAA= + Entities\DmxDevice.cs - ABAAAgAAAAAAAEAAAAAAAAAIAAACAAAAACAIAAAAAAA= + ABAEBBAAAAAAAEQAAAAAIAAIAAACACQAAAAIAAAAAAA= Tabs\TabLedMovinghead.xaml.cs @@ -55,7 +55,7 @@ - ABAAAAAAAAAAAAAAAAAAAAAKAAACAAAAAAAIAAAAAAA= + ABAAAAAAAAAAAAQEAAAAAAAIAAACAAQAAAAIAAAAAAA= Tabs\TabLaserMovinghead.xaml.cs @@ -71,7 +71,7 @@ - AAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAA= + AAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAI= Tabs\TabLedScanner.xaml.cs @@ -84,8 +84,15 @@ + + + + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= + Tabs\IDmxDeviceTabItem.cs + + - + AAAAAAAAAgAAAAAAAAAAAAABAAAAAIAAEAAAAAEQABA= Entities\Enumerations\DmxDeviceTypes.cs diff --git a/DMX/DMX.csproj b/DMX/DMX.csproj index d2500ea..2349b00 100644 --- a/DMX/DMX.csproj +++ b/DMX/DMX.csproj @@ -50,6 +50,7 @@ + @@ -156,19 +157,19 @@ PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest - + PreserveNewest diff --git a/DMX/DmxDevice.cs b/DMX/DmxDevice.cs index 498e121..26c2bdb 100644 --- a/DMX/DmxDevice.cs +++ b/DMX/DmxDevice.cs @@ -1,32 +1,36 @@ using DMX.Entities.Enumerations; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace DMX { - public abstract class DmxDevice + public class DmxDevice { - public DmxDevice(string name, int startAddress, DmxDeviceTypes deviceType, byte[] channels) + public DmxDevice(string name, int startAddress, DmxDeviceTypes deviceType, int numberOfChannels) { Name = name; StartAddress = startAddress; DeviceType = deviceType; - Channels = channels; + Channels = new byte[numberOfChannels]; + } + + public DmxDevice(JsonDmxDeviceObject jsonDmxDeviceObject) + { + Name = jsonDmxDeviceObject.Name; + StartAddress = jsonDmxDeviceObject.StartAddress; + DeviceType = Enum.IsDefined(typeof(DmxDeviceTypes), jsonDmxDeviceObject.DeviceType) ? (DmxDeviceTypes)jsonDmxDeviceObject.DeviceType : DmxDeviceTypes.Unknown; + Channels = new byte[jsonDmxDeviceObject.NumberOfChannels]; } private readonly string name; - public string Name { get; } + public virtual string Name { get; } private readonly int startAddress; - public int StartAddress { get; } + public virtual int StartAddress { get; } private readonly DmxDeviceTypes deviceType; - public DmxDeviceTypes DeviceType { get; } + public virtual DmxDeviceTypes DeviceType { get; } - private byte[] channels; - public byte[] Channels { get; private set; } + private readonly byte[] channels; + public virtual byte[] Channels { get; private set; } } } diff --git a/DMX/Entities/Enumerations/DmxDeviceTypes.cs b/DMX/Entities/Enumerations/DmxDeviceTypes.cs index 820c9d1..ad4043a 100644 --- a/DMX/Entities/Enumerations/DmxDeviceTypes.cs +++ b/DMX/Entities/Enumerations/DmxDeviceTypes.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace DMX.Entities.Enumerations +namespace DMX.Entities.Enumerations { /// /// Skytec_Mini_Spot_Led_Movinghead, diff --git a/DMX/Entities/LaserMovinghead.cs b/DMX/Entities/LaserMovinghead.cs index 3373a66..d22aec9 100644 --- a/DMX/Entities/LaserMovinghead.cs +++ b/DMX/Entities/LaserMovinghead.cs @@ -11,7 +11,7 @@ public class LaserMovinghead : DmxDevice, INotifyPropertyChanged const double DEGREES_PER_BYTE = 1 / 65535.0; public LaserMovinghead(string name, int startAddress, DmxDeviceTypes deviceType) - : base(name, startAddress, deviceType, new byte[NUMBER_OF_CHANNELS]) + : base(name, startAddress, deviceType, NUMBER_OF_CHANNELS) { } // CH1 + CH2 @@ -65,8 +65,7 @@ public string ShutterStatus public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(name)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } // CH1 + CH2 diff --git a/DMX/Entities/LedMovinghead.cs b/DMX/Entities/LedMovinghead.cs index a1f4970..e3bb34b 100644 --- a/DMX/Entities/LedMovinghead.cs +++ b/DMX/Entities/LedMovinghead.cs @@ -11,7 +11,7 @@ public class LedMovinghead : DmxDevice, INotifyPropertyChanged const double DEGREES_PER_BYTE = 1 / 65535.0; public LedMovinghead(string name, int startAddress, DmxDeviceTypes deviceType) - : base(name, startAddress, deviceType, new byte[NUMBER_OF_CHANNELS]) + : base(name, startAddress, deviceType, NUMBER_OF_CHANNELS) { } // CH1 + CH2 @@ -89,8 +89,7 @@ private set public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(name)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } // CH1 + CH2 diff --git a/DMX/Entities/LedPanel.cs b/DMX/Entities/LedPanel.cs index 8f1fa72..564ec46 100644 --- a/DMX/Entities/LedPanel.cs +++ b/DMX/Entities/LedPanel.cs @@ -12,15 +12,9 @@ public class LedPanel : DmxDevice const int NUMBER_OF_CHANNELS = 48; public LedPanel(string name, int startAddress, DmxDeviceTypes deviceType) - : base(name, startAddress, deviceType, new byte[NUMBER_OF_CHANNELS]) + : base(name, startAddress, deviceType, NUMBER_OF_CHANNELS) { } - public void UpdateChannel(int channelNumber, byte value) - { - if (channelNumber >= 0 && channelNumber < Channels.Count()) - Channels[channelNumber] = value; - } - public byte[] GetLedRGB(int ledNumber) { return new byte[3] { Channels[3 * ledNumber], Channels[(3 * ledNumber) + 1], Channels[(3 * ledNumber) + 2] }; diff --git a/DMX/Entities/LedScanner.cs b/DMX/Entities/LedScanner.cs index ac210b3..ca9b25f 100644 --- a/DMX/Entities/LedScanner.cs +++ b/DMX/Entities/LedScanner.cs @@ -15,29 +15,23 @@ public class LedScanner : DmxDevice const double DEGREES_PER_BYTE = 1 / 65535.0; public LedScanner(string name, int startAddress, DmxDeviceTypes deviceType) - : base(name, startAddress, deviceType, new byte[NUMBER_OF_CHANNELS]) + : base(name, startAddress, deviceType, NUMBER_OF_CHANNELS) { } - public void UpdateChannel(int channelNumber, byte value) - { - if (channelNumber >= 0 && channelNumber < Channels.Count()) - Channels[channelNumber] = value; - } - // CH1 + CH2 public string GetRotationX() { - return string.Format("X: {0:F2}°", MAX_X_ROTATION * ((Channels[0] << 8) + Channels[1]) * (double)DEGREES_PER_BYTE); + return string.Format("{0:F2}°", MAX_X_ROTATION * (((int)Channels[0] << 8) + (int)Channels[1]) * (double)DEGREES_PER_BYTE); } // CH3 + CH4 public string GetRotationY() { - return string.Format("Y: {0:F2}°", MAX_Y_ROTATION * ((Channels[2] << 8) + Channels[3]) * (double)DEGREES_PER_BYTE); + return string.Format("{0:F2}°", MAX_Y_ROTATION * (((int)Channels[2] << 8) + (int)Channels[3]) * (double)DEGREES_PER_BYTE); } // CH5 public string GetAxisSpeed() { - return string.Format("Speed: {0:F2}%", 100 * (1 - (Channels[4] / (double)255))); // 100->0% + return string.Format("{0:F2}%", 100 * (1 - (Channels[4] / (double)255))); // 100->0% } // CH6 public string GetDimmerStatus() diff --git a/DMX/Entities/LedSpot.cs b/DMX/Entities/LedSpot.cs index 6d6f3d9..7375bd3 100644 --- a/DMX/Entities/LedSpot.cs +++ b/DMX/Entities/LedSpot.cs @@ -12,15 +12,9 @@ public class LedSpot : DmxDevice const int NUMBER_OF_CHANNELS = 6; public LedSpot(string name, int startAddress, DmxDeviceTypes deviceType) - : base(name, startAddress, deviceType, new byte[NUMBER_OF_CHANNELS]) + : base(name, startAddress, deviceType, NUMBER_OF_CHANNELS) { } - public void UpdateChannel(int channelNumber, byte value) - { - if (channelNumber >= 0 && channelNumber < Channels.Count()) - Channels[channelNumber] = value; - } - //// CH1 + CH2 + CH3 //public byte[] GetRGB() //{ diff --git a/DMX/JsonDmxDeviceObject.cs b/DMX/JsonDmxDeviceObject.cs new file mode 100644 index 0000000..6b78f8b --- /dev/null +++ b/DMX/JsonDmxDeviceObject.cs @@ -0,0 +1,20 @@ +namespace DMX +{ + public class JsonDmxDeviceObject + { + public JsonDmxDeviceObject() + { } + + private string name; + public string Name { get; set; } + + private int startAddress; + public int StartAddress { get; set; } + + private int deviceType; + public int DeviceType { get; set; } + + private int numberOfChannels; + public int NumberOfChannels { get; set; } + } +} diff --git a/DMX/Properties/Resources.Designer.cs b/DMX/Properties/Resources.Designer.cs index a60cce2..cc51d3b 100644 --- a/DMX/Properties/Resources.Designer.cs +++ b/DMX/Properties/Resources.Designer.cs @@ -60,6 +60,26 @@ internal Resources() { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Ayra_LedLaserMovinghead { + get { + object obj = ResourceManager.GetObject("Ayra_LedLaserMovinghead", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Ayra_LedScanner { + get { + object obj = ResourceManager.GetObject("Ayra_LedScanner", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -110,6 +130,16 @@ internal static byte[] Datasheet_LED_Scanner { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap EuroLite_LedPanel { + get { + object obj = ResourceManager.GetObject("EuroLite_LedPanel", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -213,39 +243,9 @@ internal static System.Drawing.Bitmap Gobo_Open { /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Bitmap LedLaser { - get { - object obj = ResourceManager.GetObject("LedLaser", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap LedMovinghead { - get { - object obj = ResourceManager.GetObject("LedMovinghead", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap LedPanel { - get { - object obj = ResourceManager.GetObject("LedPanel", resourceCulture); - return ((System.Drawing.Bitmap)(obj)); - } - } - - /// - /// Looks up a localized resource of type System.Drawing.Bitmap. - /// - internal static System.Drawing.Bitmap LedPar56 { + internal static System.Drawing.Bitmap Showtec_LedSpot { get { - object obj = ResourceManager.GetObject("LedPar56", resourceCulture); + object obj = ResourceManager.GetObject("Showtec_LedSpot", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } @@ -253,9 +253,9 @@ internal static System.Drawing.Bitmap LedPar56 { /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// - internal static System.Drawing.Bitmap LedScanner { + internal static System.Drawing.Bitmap Skytec_LedMovinghead { get { - object obj = ResourceManager.GetObject("LedScanner", resourceCulture); + object obj = ResourceManager.GetObject("Skytec_LedMovinghead", resourceCulture); return ((System.Drawing.Bitmap)(obj)); } } diff --git a/DMX/Properties/Resources.resx b/DMX/Properties/Resources.resx index ed98344..a9c244b 100644 --- a/DMX/Properties/Resources.resx +++ b/DMX/Properties/Resources.resx @@ -163,19 +163,19 @@ ..\resources\images\gobo open.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\images\ledlaser.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\images\ayra_ledlasermovinghead.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\images\ledmovinghead.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\images\ayra_ledscanner.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\images\ledpanel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\images\eurolite_ledpanel.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\images\ledpar56.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\images\showtec_ledspot.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\resources\images\ledscanner.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\images\skytec_ledmovinghead.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a \ No newline at end of file diff --git a/DMX/Resources/Images/LedLaser.png b/DMX/Resources/Images/Ayra_LedLaserMovinghead.png similarity index 100% rename from DMX/Resources/Images/LedLaser.png rename to DMX/Resources/Images/Ayra_LedLaserMovinghead.png diff --git a/DMX/Resources/Images/LedScanner.png b/DMX/Resources/Images/Ayra_LedScanner.png similarity index 100% rename from DMX/Resources/Images/LedScanner.png rename to DMX/Resources/Images/Ayra_LedScanner.png diff --git a/DMX/Resources/Images/LedPanel.png b/DMX/Resources/Images/EuroLite_LedPanel.png similarity index 100% rename from DMX/Resources/Images/LedPanel.png rename to DMX/Resources/Images/EuroLite_LedPanel.png diff --git a/DMX/Resources/Images/LedPar56.png b/DMX/Resources/Images/Showtec_LedSpot.png similarity index 100% rename from DMX/Resources/Images/LedPar56.png rename to DMX/Resources/Images/Showtec_LedSpot.png diff --git a/DMX/Resources/Images/LedMovinghead.png b/DMX/Resources/Images/Skytec_LedMovinghead.png similarity index 100% rename from DMX/Resources/Images/LedMovinghead.png rename to DMX/Resources/Images/Skytec_LedMovinghead.png diff --git a/DMX/Tabs/TabLaserMovinghead.xaml.cs b/DMX/Tabs/TabLaserMovinghead.xaml.cs index bf829f7..d6c5cfe 100644 --- a/DMX/Tabs/TabLaserMovinghead.xaml.cs +++ b/DMX/Tabs/TabLaserMovinghead.xaml.cs @@ -14,8 +14,9 @@ public partial class TabLaserMovinghead : TabItem public TabLaserMovinghead(LaserMovinghead laserMovingheadDevice) { InitializeComponent(); - this.DataContext = laserMovinghead = laserMovingheadDevice; - DmxDevice = laserMovinghead; + this.DataContext = laserMovingheadDevice; + laserMovinghead = laserMovingheadDevice; + DmxDevice = laserMovingheadDevice; } private DmxDevice dmxDevice; @@ -25,21 +26,25 @@ public DmxDevice DmxDevice set { dmxDevice = value; } } + // CH1 + CH2 private void SldrRotationX_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { laserMovinghead.UpdateRotationX((byte)sldrChannel1.Value, (byte)sldrChannel2.Value); } + // CH3 + CH4 private void SldrRotationY_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { laserMovinghead.UpdateRotationY((byte)sldrChannel3.Value, (byte)sldrChannel4.Value); } + // CH5 private void SldrAxisSpeed_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { laserMovinghead.UpdateAxisSpeed((byte)sldrChannel5.Value); } + // CH6 private void SldrShutterStatus_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { laserMovinghead.UpdateShutterStatus((byte)sldrChannel6.Value); diff --git a/DMX/Tabs/TabLedMovinghead.xaml b/DMX/Tabs/TabLedMovinghead.xaml index 04465bb..9a41140 100644 --- a/DMX/Tabs/TabLedMovinghead.xaml +++ b/DMX/Tabs/TabLedMovinghead.xaml @@ -90,46 +90,46 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + @@ -138,38 +138,38 @@ - + - + - + - + - + - + - + - + - + - + - - + + diff --git a/DMX/Tabs/TabLedMovinghead.xaml.cs b/DMX/Tabs/TabLedMovinghead.xaml.cs index da9e9e2..2034153 100644 --- a/DMX/Tabs/TabLedMovinghead.xaml.cs +++ b/DMX/Tabs/TabLedMovinghead.xaml.cs @@ -15,8 +15,9 @@ public partial class TabLedMovinghead : TabItem public TabLedMovinghead(LedMovinghead ledMovingheadDevice) { InitializeComponent(); - this.DataContext = ledMovinghead = ledMovingheadDevice; - DmxDevice = ledMovinghead; + this.DataContext = ledMovingheadDevice; + ledMovinghead = ledMovingheadDevice; + DmxDevice = ledMovingheadDevice; } private DmxDevice dmxDevice; @@ -58,7 +59,7 @@ private void BudRGB_ValueChanged(object sender, RoutedPropertyChangedEventArgs public partial class TabLedPanel : TabItem { - public TabLedPanel() + private LedPanel ledPanel; + + public TabLedPanel(LedPanel ledPanelDevice) { InitializeComponent(); + this.DataContext = ledPanelDevice; + ledPanel = ledPanelDevice; + DmxDevice = ledPanelDevice; + } + + private DmxDevice dmxDevice; + public DmxDevice DmxDevice + { + get { return dmxDevice; } + set { dmxDevice = value; } } } } diff --git a/DMX/Tabs/TabLedScanner.xaml.cs b/DMX/Tabs/TabLedScanner.xaml.cs index 9880aaa..0932750 100644 --- a/DMX/Tabs/TabLedScanner.xaml.cs +++ b/DMX/Tabs/TabLedScanner.xaml.cs @@ -21,18 +21,21 @@ namespace DMX.Tabs /// public partial class TabLedScanner : TabItem { + private LedScanner ledScanner; + public TabLedScanner(LedScanner ledScannerDevice) { InitializeComponent(); - this.DataContext = ledScanner = ledScannerDevice; + this.DataContext = ledScannerDevice; + ledScanner = ledScannerDevice; + DmxDevice = ledScannerDevice; } - private LedScanner ledScanner; - public LedScanner LedScanner + private DmxDevice dmxDevice; + public DmxDevice DmxDevice { - get { return ledScanner; } - set { ledScanner = value; } + get { return dmxDevice; } + set { dmxDevice = value; } } - } } diff --git a/DMX/Tabs/TabLedSpot.xaml.cs b/DMX/Tabs/TabLedSpot.xaml.cs index 39f557b..2ad7a4e 100644 --- a/DMX/Tabs/TabLedSpot.xaml.cs +++ b/DMX/Tabs/TabLedSpot.xaml.cs @@ -1,4 +1,5 @@ -using System; +using DMX.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -20,9 +21,21 @@ namespace DMX.Tabs /// public partial class TabLedSpot : TabItem { - public TabLedSpot() + private LedSpot ledSpot; + + public TabLedSpot(LedSpot ledSpotDevice) { InitializeComponent(); + this.DataContext = ledSpotDevice; + ledSpot = ledSpotDevice; + DmxDevice = ledSpotDevice; + } + + private DmxDevice dmxDevice; + public DmxDevice DmxDevice + { + get { return dmxDevice; } + set { dmxDevice = value; } } } } diff --git a/DMX/bin/Debug/DMX.dll b/DMX/bin/Debug/DMX.dll index a8d4511..e7e1391 100644 Binary files a/DMX/bin/Debug/DMX.dll and b/DMX/bin/Debug/DMX.dll differ diff --git a/DMX/bin/Debug/DMX.pdb b/DMX/bin/Debug/DMX.pdb index d6390f4..ebe6c89 100644 Binary files a/DMX/bin/Debug/DMX.pdb and b/DMX/bin/Debug/DMX.pdb differ diff --git a/Logger/Logger.cs b/Logger/Logger.cs index cdada63..5d676ce 100644 --- a/Logger/Logger.cs +++ b/Logger/Logger.cs @@ -20,8 +20,13 @@ private Logger() /// ~Logger() { - writer.Close(); - writer.Dispose(); + try + { + writer.Close(); + writer.Dispose(); + } + catch (Exception) + { } writer = null; } @@ -88,5 +93,17 @@ public void Error(string error) DateTime dt = DateTime.Now; writer.WriteLine($"[ERROR] {dt.Hour.ToString().PadLeft(2, '0')}:{dt.Minute.ToString().PadLeft(2, '0')}:{dt.Second.ToString().PadLeft(2, '0')} >>>> {error}"); } + + /// + /// Logging error to logging file. + /// Used Format: + /// 'Exception message', 'Newline', 'Stack trace' + /// + /// Exception that's been thrown + public void Error(Exception ex) + { + DateTime dt = DateTime.Now; + writer.WriteLine($"[ERROR] {dt.Hour.ToString().PadLeft(2, '0')}:{dt.Minute.ToString().PadLeft(2, '0')}:{dt.Second.ToString().PadLeft(2, '0')} >>>> {ex.Message}\n{ex.StackTrace}"); + } } } diff --git a/Logger/bin/Debug/Logger.dll b/Logger/bin/Debug/Logger.dll index 95b10ea..a529150 100644 Binary files a/Logger/bin/Debug/Logger.dll and b/Logger/bin/Debug/Logger.dll differ diff --git a/Logger/bin/Debug/Logger.pdb b/Logger/bin/Debug/Logger.pdb index f48a162..5553bd9 100644 Binary files a/Logger/bin/Debug/Logger.pdb and b/Logger/bin/Debug/Logger.pdb differ diff --git a/Project DMX 2.0/ClassDiagram1.cd b/Project DMX 2.0/ClassDiagram1.cd index 6d4dead..0e361bf 100644 --- a/Project DMX 2.0/ClassDiagram1.cd +++ b/Project DMX 2.0/ClassDiagram1.cd @@ -1,29 +1,21 @@  - + AAAAAAAAAAAAAAACAAAAAAAAAAAAAAQAAAAAAAAAAAA= Event_Args\NewDmxDeviceEventArgs.cs - + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= Exceptions\UnknownDeviceTypeException.cs - - - - AAACgAgABACAQAACQABAAAAAAAEAAAAACAAAAAAQEAA= - MainWindow.xaml.cs - - - - + AAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAQAAAAEACAAI= NewDeviceUI.xaml.cs @@ -31,19 +23,27 @@ - + AAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAA= Event_Args\SettingsEventArgs.cs - + AAAAAAAAEAAAAAADAAAAAAAAAAAABAAAAAAAAAAAAAA= SettingsUI.xaml.cs + + + + AAACgBgABAKAQAACYABAAAAAgAkAAAAACAAAAAAAEAA= + MainWindow.xaml.cs + + + \ No newline at end of file diff --git a/Project DMX 2.0/Event_Args/NewDmxDeviceEventArgs.cs b/Project DMX 2.0/Event_Args/NewDmxDeviceEventArgs.cs index 53077dc..9ca7acf 100644 --- a/Project DMX 2.0/Event_Args/NewDmxDeviceEventArgs.cs +++ b/Project DMX 2.0/Event_Args/NewDmxDeviceEventArgs.cs @@ -1,51 +1,15 @@ using DMX; -using DMX.Entities; -using DMX.Entities.Enumerations; -using Logging; -using Project_DMX_2._0.Exceptions; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Project_DMX_2._0.Event_Args { public class NewDmxDeviceEventArgs : EventArgs { public DmxDevice DmxDevice { get; set; } - Logger logger; - public NewDmxDeviceEventArgs(DmxDeviceTypes deviceType, string name, int startAddress) + public NewDmxDeviceEventArgs(DmxDevice dmxDevice) { - logger = Logger.GetLogger; - switch (deviceType) - { - case DmxDeviceTypes.Skytec_LedMovinghead: - DmxDevice = new LedMovinghead(name, startAddress, deviceType); - logger.Log("New Skytec_LedMovinghead created"); - break; - case DmxDeviceTypes.Ayra_LedLaserMovinghead: - DmxDevice = new LaserMovinghead(name, startAddress, deviceType); - logger.Log("New Ayra_LedLaserMovinghead created"); - break; - case DmxDeviceTypes.Ayra_LedScanner: - DmxDevice = new LedScanner(name, startAddress, deviceType); - logger.Log("New Ayra_LedScanner created"); - break; - case DmxDeviceTypes.EuroLite_LedPanel: - DmxDevice = new LedPanel(name, startAddress, deviceType); - logger.Log("New EuroLite_LedPanel created"); - break; - case DmxDeviceTypes.Showtec_LedSpot: - DmxDevice = new LedSpot(name, startAddress, deviceType); - logger.Log("New Showtec_LedSpot created"); - break; - case DmxDeviceTypes.Unknown: - default: - logger.Warn("Unable to create new device. See Error message"); - throw new UnknownDeviceTypeException("Device type is unknown. Unable to create a new device."); - } + DmxDevice = dmxDevice; } } } diff --git a/Project DMX 2.0/Event_Args/SettingsEventArgs.cs b/Project DMX 2.0/Event_Args/SettingsEventArgs.cs index 19afd94..e197bd1 100644 --- a/Project DMX 2.0/Event_Args/SettingsEventArgs.cs +++ b/Project DMX 2.0/Event_Args/SettingsEventArgs.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Project_DMX_2._0.Event_Args { diff --git a/Project DMX 2.0/Exceptions/UnknownDeviceTypeException.cs b/Project DMX 2.0/Exceptions/UnknownDeviceTypeException.cs index c7c88da..563543a 100644 --- a/Project DMX 2.0/Exceptions/UnknownDeviceTypeException.cs +++ b/Project DMX 2.0/Exceptions/UnknownDeviceTypeException.cs @@ -1,9 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Project_DMX_2._0.Exceptions { diff --git a/Project DMX 2.0/MainWindow.xaml b/Project DMX 2.0/MainWindow.xaml index f7c5624..76a39d4 100644 --- a/Project DMX 2.0/MainWindow.xaml +++ b/Project DMX 2.0/MainWindow.xaml @@ -4,33 +4,44 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Title="DMX Controller v2.0" Height="465" Width="600" - MinHeight="200" MinWidth="300" + Title="DMX Controller v2.0" Height="470" Width="600" + MinHeight="230" MinWidth="300" Name="Main_Window" Closing="Main_Window_Closing"> - - - - + + + + + Settings + + + + + + + + Add device + + + + + + + + Remove selected device + + + + - - - - - - - - - - + + - + diff --git a/Project DMX 2.0/MainWindow.xaml.cs b/Project DMX 2.0/MainWindow.xaml.cs index fa393af..dde9e1a 100644 --- a/Project DMX 2.0/MainWindow.xaml.cs +++ b/Project DMX 2.0/MainWindow.xaml.cs @@ -3,6 +3,7 @@ using DMX.Entities.Enumerations; using DMX.Tabs; using Logging; +using Newtonsoft.Json; using Project_DMX_2._0.Event_Args; using System; using System.Collections.Generic; @@ -31,7 +32,8 @@ namespace Project_DMX_2._0 public partial class MainWindow : Window, INotifyPropertyChanged { Logger logger; - public List _dmxDevices; + List _dmxDevices; + List _availableDevices; NewDeviceUI _newDeviceUI; SettingsUI _settingsUI; @@ -57,15 +59,13 @@ public MainWindow() _dmxDevices = new List(); - TabLaserMovinghead tabLaserMovinghead = new TabLaserMovinghead(new LaserMovinghead("Ayra Laser Movinghead", 120, DmxDeviceTypes.Ayra_LedLaserMovinghead)); - _dmxDevices.Add(tabLaserMovinghead.DmxDevice); - tctDeviceTabs.Items.Add(tabLaserMovinghead); - logger.Log("tabLaserMovinghead added to tctDeviceTabs in MainWindow"); - - TabLedMovinghead tabLedMovinghead = new TabLedMovinghead(new LedMovinghead("Skytec LED Movinghead", 160, DmxDeviceTypes.Skytec_LedMovinghead)); - _dmxDevices.Add(tabLedMovinghead.DmxDevice); - tctDeviceTabs.Items.Add(tabLedMovinghead); - logger.Log("tabLedMovinghead added to tctDeviceTabs in MainWindow"); + string devicesJSON = new System.IO.StreamReader(Environment.CurrentDirectory + "\\devices.json").ReadToEnd(); + logger.Log("devices.json read"); + List tempDmxDevices = JsonConvert.DeserializeObject>(devicesJSON); + _availableDevices = new List(); + foreach (JsonDmxDeviceObject deviceObject in tempDmxDevices) + _availableDevices.Add(new DmxDevice(deviceObject)); + logger.Log("All available devices added"); _dt.Start(); logger.Log("Dispatcher timer started..."); @@ -75,12 +75,52 @@ private void NewDeviceUI_NewDmxDevice(object sender, NewDmxDeviceEventArgs e) { _newDeviceUI = null; _dmxDevices.Add(e.DmxDevice); + _availableDevices.Remove(e.DmxDevice); logger.Log("New DmxDevice added: " + e.DmxDevice.Name + " @ " + e.DmxDevice.StartAddress); + TabItem tempTabItem; + switch (e.DmxDevice.DeviceType) + { + case DmxDeviceTypes.Skytec_LedMovinghead: + tempTabItem = new TabLedMovinghead(new LedMovinghead(e.DmxDevice.Name, e.DmxDevice.StartAddress, e.DmxDevice.DeviceType)); + tctDeviceTabs.Items.Add(tempTabItem); + tctDeviceTabs.SelectedItem = tempTabItem; + logger.Log("TabLedMovinghead added"); + break; + case DmxDeviceTypes.Ayra_LedLaserMovinghead: + tempTabItem = new TabLaserMovinghead(new LaserMovinghead(e.DmxDevice.Name, e.DmxDevice.StartAddress, e.DmxDevice.DeviceType)); + tctDeviceTabs.Items.Add(tempTabItem); + logger.Log("TabLaserMovinghead added"); + tctDeviceTabs.SelectedItem = tempTabItem; + break; + case DmxDeviceTypes.Ayra_LedScanner: + tempTabItem = new TabLedScanner(new LedScanner(e.DmxDevice.Name, e.DmxDevice.StartAddress, e.DmxDevice.DeviceType)); + tctDeviceTabs.Items.Add(tempTabItem); + logger.Log("TabLedScanner added"); + tctDeviceTabs.SelectedItem = tempTabItem; + break; + case DmxDeviceTypes.EuroLite_LedPanel: + tempTabItem = new TabLedPanel(new LedPanel(e.DmxDevice.Name, e.DmxDevice.StartAddress, e.DmxDevice.DeviceType)); + tctDeviceTabs.Items.Add(tempTabItem); + logger.Log("TabLedPanel added"); + tctDeviceTabs.SelectedItem = tempTabItem; + break; + case DmxDeviceTypes.Showtec_LedSpot: + tempTabItem = new TabLedSpot(new LedSpot(e.DmxDevice.Name, e.DmxDevice.StartAddress, e.DmxDevice.DeviceType)); + tctDeviceTabs.Items.Add(tempTabItem); + logger.Log("TabLedSpot added"); + tctDeviceTabs.SelectedItem = tempTabItem; + break; + case DmxDeviceTypes.Unknown: + case DmxDeviceTypes.None: + default: + logger.Warn("Cannot add device tab because DeviceType is None/Unknown"); + break; + } } private void NewDevice_Click(object sender, RoutedEventArgs e) { - _newDeviceUI = new NewDeviceUI(); + _newDeviceUI = new NewDeviceUI(_availableDevices); _newDeviceUI.NewDmxDevice += new EventHandler(NewDeviceUI_NewDmxDevice); _newDeviceUI.ShowDialog(); } @@ -112,11 +152,40 @@ private void Settings_Click(object sender, RoutedEventArgs e) _settingsUI.ShowDialog(); } + private void RemoveSelectedDevice_Click(object sender, RoutedEventArgs e) + { + if (tctDeviceTabs.SelectedIndex >= 0 && tctDeviceTabs.SelectedItem != null) + { + MessageBoxResult result = MessageBox.Show("Are you sure you want to remove " + _dmxDevices[tctDeviceTabs.SelectedIndex].Name + "?\nThis can't be undone.", "Are you sure?", MessageBoxButton.YesNo, MessageBoxImage.Stop, MessageBoxResult.No); + if (result == MessageBoxResult.Yes) + { + _availableDevices.Add(_dmxDevices[tctDeviceTabs.SelectedIndex]); + _dmxDevices.RemoveAt(tctDeviceTabs.SelectedIndex); + tctDeviceTabs.Items.Remove(tctDeviceTabs.SelectedItem); + } + } + } + + private void TctDeviceTabs_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (e.Source is TabControl) + { + TabControl tc = sender as TabControl; + try + { + sbiStartAddress.Content = _dmxDevices[tc.SelectedIndex].StartAddress; + } + catch (Exception ex) + { + logger.Error(ex); + } + } + } + public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string name) { - if (PropertyChanged != null) - PropertyChanged(this, new PropertyChangedEventArgs(name)); + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)); } private void _dt_Tick(object sender, EventArgs e) @@ -161,21 +230,5 @@ private void Main_Window_Closing(object sender, System.ComponentModel.CancelEven logger.Warn("Closing application....."); logger = null; } - - private void TctDeviceTabs_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (e.Source is TabControl) - { - TabControl tc = sender as TabControl; - try - { - (((TabControl)sender).SelectedItem as TabItem). - } - catch (Exception) - { - - } - } - } } } diff --git a/Project DMX 2.0/NewDeviceUI.xaml b/Project DMX 2.0/NewDeviceUI.xaml index 1a25c5b..a5af145 100644 --- a/Project DMX 2.0/NewDeviceUI.xaml +++ b/Project DMX 2.0/NewDeviceUI.xaml @@ -1,17 +1,39 @@  + Title="Add new DMX device" Height="235" Width="370" + ResizeMode="NoResize" Icon="Resources/Images/Add_16x.png"> -