Skip to content

Commit

Permalink
Persistence, 2021.1
Browse files Browse the repository at this point in the history
Camera, Microphone, Driver, Interpreter, and Experiment Selection Tab all are persistent now using the C# configuration manager.

2021.1 is feature complete!
  • Loading branch information
Philip-S-Martin committed Feb 19, 2021
1 parent 3713407 commit 9df1839
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 76 deletions.
Binary file added InstallForge/2021_1_InstallProject.ifp
Binary file not shown.
37 changes: 21 additions & 16 deletions McIntyreAFC/McIntyreAFC.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\ProtocolMasterWPF\bin\Debug\netcoreapp3.1\Extensions\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<WarningLevel>5</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\ProtocolMasterWPF\bin\Debug\netcoreapp3.1\Extensions\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<WarningLevel>5</WarningLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SerialPortStream" Version="2.2.2" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\ProtocolMasterWPF\bin\Release\netcoreapp3.1\Extensions\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ProtocolMasterCore\ProtocolMasterCore.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SerialPortStream" Version="2.2.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ProtocolMasterCore\ProtocolMasterCore.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion ProtocolMasterCore/Protocol/Driver/DriverMeta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public DriverMeta(string name, string version, params string[] eventNames) : bas
this.Version = version;
this.HandlerLabels = eventNames;
}
public DriverMeta()
{
}

public DriverMeta(IDictionary<string, object> inputs)
{
Expand All @@ -34,7 +37,7 @@ public override string ToString()

public bool Equals([AllowNull] IExtensionMeta other)
{
return this.Name == other.Name && this.Version == other.Version;
return this.Name == other.Name && this.Version == other.Version;
}
}
}
4 changes: 2 additions & 2 deletions ProtocolMasterCore/Protocol/ExtensionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public IExtensionMeta Selected
{
foreach (ExportFactory<E, T> i in Extensions)
{
if ((IExtensionMeta)i.Metadata == value)
if (i.Metadata.Equals(value))
{
extensionFactory = i;
return;
}
}
throw new Exception($"No extension of type {typeof(E)} of with metadata {value} is loaded");
throw new ArgumentException($"No extension of type {typeof(E)} of with metadata {value} is loaded");
}
}
public IEnumerable<IExtensionMeta> Options
Expand Down
4 changes: 4 additions & 0 deletions ProtocolMasterCore/Protocol/IExtensionMeta.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml.Serialization;

namespace ProtocolMasterCore.Protocol
{
Expand All @@ -7,4 +10,5 @@ public interface IExtensionMeta : IEquatable<IExtensionMeta>
string Name { get; }
string Version { get; }
}

}
2 changes: 1 addition & 1 deletion ProtocolMasterWPF/Helpers/NotNullToBoolConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value != null;
throw new NotSupportedException();
}
}
}
36 changes: 28 additions & 8 deletions ProtocolMasterWPF/Model/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,38 @@ private async void InitVideoStore()
{
videoStore = await StorageFolder.GetFolderFromPathAsync(storagePath);
}
public async void InitializeCap(DeviceInformation videoDevice, DeviceInformation audioDevice)
public void InitializeCap(DeviceInformation videoDevice, DeviceInformation audioDevice)
{
try
if(videoDevice == null)
Log.Error($"Video Device null");
if (audioDevice == null)
{
await MediaCap.InitializeAsync(new MediaCaptureInitializationSettings() {
VideoDeviceId = videoDevice.Id,
AudioDeviceId = audioDevice.Id
});
try
{
MediaCap.InitializeAsync(new MediaCaptureInitializationSettings()
{
VideoDeviceId = videoDevice.Id
}).AsTask().Wait();
}
catch (UnauthorizedAccessException ex)
{
Log.Error($"The app was denied access to the camera: {ex}");
}
}
catch (UnauthorizedAccessException ex)
else
{
Log.Error($"The app was denied access to the camera:\t{ex}");
try
{
MediaCap.InitializeAsync(new MediaCaptureInitializationSettings()
{
VideoDeviceId = videoDevice.Id,
AudioDeviceId = audioDevice.Id
}).AsTask().Wait();
}
catch (UnauthorizedAccessException ex)
{
Log.Error($"The app was denied access to the camera: {ex}");
}
}
}
public async void StartPreview()
Expand Down
88 changes: 58 additions & 30 deletions ProtocolMasterWPF/Model/CameraContainer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using ProtocolMasterCore.Utility;
using ProtocolMasterWPF.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -11,53 +13,79 @@ internal class CameraContainer : Observable
{
public CameraContainer()
{
RefreshDevices();
_videoDevice = VideoDevices.First();
_audioDevice = AudioDevices.First();
InitDefaultDevices();
ResetCam();
}
public Camera Cam { get => _cam; private set { _cam = value; NotifyProperty(); } }
private Camera _cam;
public DeviceInformation VideoDevice { get => _videoDevice; set { _videoDevice = value; NotifyProperty(); ResetCam(); } }
private DeviceInformation _videoDevice;
public DeviceInformation AudioDevice { get => _audioDevice; set { _audioDevice = value; NotifyProperty(); ResetCam(); } }
private DeviceInformation _audioDevice;
public void StartRecord() => Cam.StartRecord();
public void StopRecord() => Cam.StopRecord();
private DeviceInformationCollection _videoDevices;
public DeviceInformationCollection VideoDevices
public Camera Cam
{
get => _videoDevices;
set
get => _cam;
private set
{
_videoDevices = value;
_cam = value;
NotifyProperty();
}
}
public void RefreshDevices()
private Camera _cam;
public DeviceInformation VideoDevice
{
Task<DeviceInformationCollection> task = DeviceInformation.FindAllAsync(DeviceClass.VideoCapture).AsTask();
task.Wait();
VideoDevices = task.Result;
task.Dispose();

task = DeviceInformation.FindAllAsync(DeviceClass.AudioCapture).AsTask();
task.Wait();
AudioDevices = task.Result;
get => _videoDevice;
set
{
_videoDevice = value;
NotifyProperty();
ResetCam();
if (value.Id != Settings.Default.CameraID)
{
Settings.Default.CameraID = value.Id;
Settings.Default.Save();
}
}
}
private DeviceInformationCollection _audioDevices;
public DeviceInformationCollection AudioDevices
private DeviceInformation _videoDevice;
public DeviceInformation AudioDevice
{
get => _audioDevices;
get => _audioDevice;
set
{
_audioDevices = value;
_audioDevice = value;
NotifyProperty();
ResetCam();
if(value.Id != Settings.Default.MicrophoneID)
{
Settings.Default.MicrophoneID = value.Id;
Settings.Default.Save();
}
}
}
private DeviceInformation _audioDevice;
public void StartRecord() => Cam.StartRecord();
public void StopRecord() => Cam.StopRecord();

private void ResetCam()
{
Cam = new Camera(VideoDevice, AudioDevice);
}

public void InitDefaultDevices()
{
try
{
_videoDevice = MediaDevices.Instance.VideoDeviceByID(Settings.Default.CameraID);
}
catch (Exception e)
{
Log.Error($"Default Camera could not be seleted, exception: {e}");
VideoDevice = MediaDevices.Instance.VideoDevices.First();
}
try
{
_audioDevice = MediaDevices.Instance.AudioDeviceByID(Settings.Default.MicrophoneID);
}
catch (Exception e)
{
Log.Error($"Default Microphone could not be seleted, exception: {e}");
AudioDevice = MediaDevices.Instance.AudioDevices.First();
}
}
}
}
27 changes: 27 additions & 0 deletions ProtocolMasterWPF/Model/ExtensionMetaSetting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using ProtocolMasterCore.Protocol;
using ProtocolMasterCore.Protocol.Driver;
using ProtocolMasterCore.Protocol.Interpreter;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics.CodeAnalysis;
using System.Text;

namespace ProtocolMasterWPF.Model
{
[Serializable]
public sealed class ExtensionMetaSetting : IExtensionMeta
{
public string Name { get; set; }
public string Version { get; set; }
public ExtensionMetaSetting() { }
public ExtensionMetaSetting(IExtensionMeta from)
{
Name = from.Name; Version = from.Version;
}
public bool Equals([AllowNull] IExtensionMeta other)
{
return this.Name == other.Name && this.Version == other.Version;
}
}
}
60 changes: 60 additions & 0 deletions ProtocolMasterWPF/Model/MediaDevices.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;

namespace ProtocolMasterWPF.Model
{
internal class MediaDevices : Observable
{
private static MediaDevices instance = new MediaDevices();
public static MediaDevices Instance { get => instance; }
static MediaDevices() { }
private MediaDevices()
{
RefreshDevices();
}
private DeviceInformationCollection _videoDevices;

public DeviceInformationCollection VideoDevices
{
get => _videoDevices;
set
{
_videoDevices = value;
NotifyProperty();
}
}
public void RefreshDevices()
{
Task<DeviceInformationCollection> task = DeviceInformation.FindAllAsync(DeviceClass.VideoCapture).AsTask();
task.Wait();
VideoDevices = task.Result;
task.Dispose();

task = DeviceInformation.FindAllAsync(DeviceClass.AudioCapture).AsTask();
task.Wait();
AudioDevices = task.Result;
}
private DeviceInformationCollection _audioDevices;
public DeviceInformationCollection AudioDevices
{
get => _audioDevices;
set
{
_audioDevices = value;
NotifyProperty();
}
}
public DeviceInformation AudioDeviceByID(string id)
{
return AudioDevices.First(a => a.Id == id);
}
public DeviceInformation VideoDeviceByID(string id)
{
return VideoDevices.First(a => a.Id == id);
}
}
}
Loading

0 comments on commit 9df1839

Please sign in to comment.