Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
PelcoD-Plugin done & Bugfixes
Browse files Browse the repository at this point in the history
- Fixed some translation issues
- Implemented the PelcoD-Protocol
  • Loading branch information
CShark committed Sep 27, 2021
1 parent 0cecdf5 commit 50d8cab
Show file tree
Hide file tree
Showing 16 changed files with 567 additions and 19 deletions.
Binary file added Assets/PelcoConfig.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/PelcoSlot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion BetterMultiview/Plugins/KNX/KnxPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace ObsMultiview.Plugins.KNX {
/// <summary>
/// A plugin to talk to a KNX/IP Interface
/// </summary>
class KnxPlugin : PluginBase {
public class KnxPlugin : PluginBase {
public override string Name => "KNX";
public override string Author => "Nathanael Schneider";
public override string Version => "1.0";
Expand Down
2 changes: 1 addition & 1 deletion BetterMultiview/Plugins/Keyboard/GlobalSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:converters="clr-namespace:ObsMultiview.Plugins.Converters"
mc:Ignorable="d"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="StreamDeck.Plugins"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="Keyboard"
Background="White"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Expand Down
9 changes: 9 additions & 0 deletions BetterMultiview/Plugins/ObsMultiview.Plugins.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
</Compile>
<Compile Update="Strings\PelcoD.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>PelcoD.resx</DependentUpon>
</Compile>
<Compile Update="Strings\Qlc.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand All @@ -52,6 +57,10 @@
<LastGenOutput>KNX.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
</EmbeddedResource>
<EmbeddedResource Update="Strings\PelcoD.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>PelcoD.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Strings\Qlc.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Qlc.Designer.cs</LastGenOutput>
Expand Down
42 changes: 42 additions & 0 deletions BetterMultiview/Plugins/PelcoD/GlobalSettings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<plugins:SettingsControl x:TypeArguments="local:PelcoSettings" x:Class="ObsMultiview.Plugins.PelcoD.GlobalSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ObsMultiview.Plugins.PelcoD"
xmlns:plugins="clr-namespace:ObsMultiview.Plugins"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="PelcoD"
mc:Ignorable="d"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Background="White"
Height="350" Width="500">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock Text="{lex:Loc Port}" Margin="5" VerticalAlignment="Center" />
<ComboBox Grid.Column="1" Margin="5" SelectedItem="{Binding Settings.ComPort}" ItemsSource="{Binding AvailablePorts}"/>
<TextBlock Text="{lex:Loc Baudrate}" Grid.Column="2" VerticalAlignment="Center" Margin="5" />
<TextBox Grid.Column="4" Margin="5" Text="{Binding Settings.BaudRate}"/>

<DataGrid Grid.Row="1" Grid.ColumnSpan="4" AutoGenerateColumns="False" ItemsSource="{Binding Settings.Presets}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding CameraID}" Header="{lex:Loc CameraID}" Width="100"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding PresetID}" Header="{lex:Loc PresetID}" Width="100"></DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Name}" Header="{lex:Loc Name}" Width="*"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</plugins:SettingsControl>
35 changes: 35 additions & 0 deletions BetterMultiview/Plugins/PelcoD/GlobalSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.IO.Ports;
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 ObsMultiview.Plugins.PelcoD {
/// <summary>
/// Interaktionslogik für GlobalSettings.xaml
/// </summary>
public partial class GlobalSettings : SettingsControl<PelcoSettings> {
public static readonly DependencyProperty AvailablePortsProperty = DependencyProperty.Register(
nameof(AvailablePorts), typeof(List<string>), typeof(GlobalSettings), new PropertyMetadata(default(List<string>)));

public List<string> AvailablePorts {
get { return (List<string>) GetValue(AvailablePortsProperty); }
set { SetValue(AvailablePortsProperty, value); }
}

public GlobalSettings(CommandFacade management) : base(management) {
AvailablePorts = SerialPort.GetPortNames().ToList();
InitializeComponent();
}
}
}
33 changes: 21 additions & 12 deletions BetterMultiview/Plugins/PelcoD/PelcoPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
using Microsoft.Extensions.Logging;

namespace ObsMultiview.Plugins.PelcoD {
class PelcoPlugin : PluginBase {
public class PelcoPlugin : PluginBase {
public override string Name => "Pelco-D";
public override string Author => "Nathanael Schneider";
public override string Version => "1.0";

public override bool HasSettings => true;
public override bool HasSlotSettings => true;

private SerialPort _port;

public override void OnEnabled() {
Expand All @@ -21,8 +24,10 @@ class PelcoPlugin : PluginBase {

try {
_port.Open();
State = PluginState.Active;
} catch (Exception ex) {
Logger.LogError(ex, "Failed to open port");
State = PluginState.Faulted;
}
}

Expand All @@ -32,29 +37,33 @@ class PelcoPlugin : PluginBase {
_port.Close();
} catch {
}

State = PluginState.Disabled;
}

public override void ApplySlot(Guid slot) {
var settings = CommandFacade.RequestSlotSetting<PelcoSlotSettings>(slot);

byte[] message = new byte[7];
message[0] = 0xFF;
message[1] = settings.CameraID;
message[2] = 0x00;
message[3] = 0x07;
message[4] = 0x00;
message[5] = settings.PresetID;
message[6] = message.Skip(1).Take(5).Aggregate((byte) 0, (s, x) => (byte) (s + x));
if (settings.Preset != null && settings.Preset.CameraID > 0) {
byte[] message = new byte[7];
message[0] = 0xFF;
message[1] = settings.Preset.CameraID;
message[2] = 0x00;
message[3] = 0x07;
message[4] = 0x00;
message[5] = settings.Preset.PresetID;
message[6] = message.Skip(1).Take(5).Aggregate((byte) 0, (s, x) => (byte) (s + x));

_port.Write(message, 0, 7);
_port.Write(message, 0, 7);
}
}

public override SettingsControl GetGlobalSettings() {
throw new NotImplementedException();
return new GlobalSettings(CommandFacade);
}

public override SettingsControl GetSlotSettings(Guid slot) {
throw new NotImplementedException();
return new SlotSettings(CommandFacade, slot);
}
}
}
13 changes: 11 additions & 2 deletions BetterMultiview/Plugins/PelcoD/PelcoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
using System.Threading.Tasks;

namespace ObsMultiview.Plugins.PelcoD {
public class Preset {
public byte CameraID { get; set; }

public byte PresetID { get; set; }

public string Name { get; set; }
}

public class PelcoSettings {
public string ComPort { get; set; }
public int BaudRate { get; set; } = 9600;

public List<Preset> Presets { get; set; } = new();
}

public class PelcoSlotSettings {
public byte CameraID { get; set; }
public byte PresetID { get; set; }
public Preset Preset { get; set; }
}
}
25 changes: 25 additions & 0 deletions BetterMultiview/Plugins/PelcoD/SlotSettings.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<plugins:SlotSettingsControl x:TypeArguments="local:PelcoSlotSettings"
x:Class="ObsMultiview.Plugins.PelcoD.SlotSettings"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ObsMultiview.Plugins.PelcoD"
xmlns:plugins="clr-namespace:ObsMultiview.Plugins"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="ObsMultiview.Plugins"
lex:ResxLocalizationProvider.DefaultDictionary="PelcoD"
Height="26" d:DesignWidth="800">
<Grid>
<ComboBox ItemsSource="{Binding Presets}" SelectedItem="{Binding Settings.Preset}" >
<ComboBox.ItemTemplate>
<DataTemplate DataType="local:Preset">
<TextBlock Text="{Binding Name}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</plugins:SlotSettingsControl>
45 changes: 45 additions & 0 deletions BetterMultiview/Plugins/PelcoD/SlotSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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;
using ObsMultiview.Plugins.Extensions;

namespace ObsMultiview.Plugins.PelcoD {
/// <summary>
/// Interaktionslogik für SlotSettings.xaml
/// </summary>
public partial class SlotSettings : SlotSettingsControl<PelcoSlotSettings> {
public static readonly DependencyProperty PresetsProperty = DependencyProperty.Register(
nameof(Presets), typeof(List<Preset>), typeof(SlotSettings), new PropertyMetadata(default(List<Preset>)));

public List<Preset> Presets {
get { return (List<Preset>) GetValue(PresetsProperty); }
set { SetValue(PresetsProperty, value); }
}

public SlotSettings(CommandFacade commandFacade, Guid slotID) : base(commandFacade, slotID) {
var settings = commandFacade.RequestSettings<PelcoSettings>();
Presets = settings.Presets;
Presets.Insert(0,
new Preset {CameraID = 0, PresetID = 0, Name = Localizer.Localize<string>("PelcoD", "NoCamera")});
InitializeComponent();
}

public override void WriteSettings() {
if (Settings.Preset.CameraID == 0) {
Settings.Preset = null;
}
base.WriteSettings();
}
}
}
Loading

0 comments on commit 50d8cab

Please sign in to comment.