Skip to content

Commit

Permalink
- Trying to fix enumeration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnew committed Oct 23, 2024
1 parent dd5436a commit 61053ee
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 39 deletions.
10 changes: 5 additions & 5 deletions OpenEphys.Miniscope/LegacyUclaMiniscope.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Bonsai;
using OpenCV.Net;
using System;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Bonsai;
using OpenCV.Net;

namespace OpenEphys.Miniscope
{
Expand All @@ -23,7 +23,7 @@ public enum FrameRateLegacy
Fps60 = 0x16

Check warning on line 23 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (debug, ubuntu-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.FrameRateLegacy.Fps60'

Check warning on line 23 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (debug, windows-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.FrameRateLegacy.Fps60'

Check warning on line 23 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (release, ubuntu-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.FrameRateLegacy.Fps60'

Check warning on line 23 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (release, windows-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.FrameRateLegacy.Fps60'
};

[TypeConverter(typeof(IndexConverter))]
[TypeConverter(typeof(MiniscopeIndexConverter))]
[Description("The index of the camera from which to acquire images.")]
public int Index { get; set; } = 0;

Check warning on line 28 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (debug, ubuntu-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.Index'

Check warning on line 28 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (debug, windows-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.Index'

Check warning on line 28 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (release, ubuntu-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.Index'

Check warning on line 28 in OpenEphys.Miniscope/LegacyUclaMiniscope.cs

View workflow job for this annotation

GitHub Actions / build (release, windows-latest)

Missing XML comment for publicly visible type or member 'LegacyUclaMiniscope.Index'

Expand Down Expand Up @@ -69,7 +69,7 @@ public LegacyUclaMiniscope()
var lastLEDBrightness = LedBrightness;
var lastExposure = Exposure;
var lastSensorGain = SensorGain;
using (var capture = Capture.CreateCameraCapture(Index))
using (var capture = Capture.CreateCameraCapture(Index, CaptureDomain.DirectShow))
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using AForge.Video.DirectShow;

class IndexConverter : Int32Converter
class MiniscopeIndexConverter : Int32Converter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
Expand All @@ -17,25 +17,25 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
return base.ConvertFrom(context, culture, value);
}

FilterInfoCollection GetMiniscopes()
int[] GetMiniscopeIndices()
{
var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
for (int i = deviceFilters.Count - 1; i >= 0; i--)
var indices = new List<int>();
for (int i = 0; i < deviceFilters.Count; i++)
{
if (!deviceFilters[i].Name.Contains("MINISCOPE"))
deviceFilters.RemoveAt(i);
if (deviceFilters[i].Name.Contains("MINISCOPE"))
indices.Add(i);
}

return deviceFilters;
return indices.ToArray();
}


public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var index = (int)value;
var deviceFilters = GetMiniscopes();
var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
if (index >= 0 && index < deviceFilters.Count)
{
return string.Format(culture, "{0} ({1})", index, deviceFilters[index].Name);
Expand All @@ -54,9 +54,8 @@ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
return true;
}

public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
var deviceFilters = GetMiniscopes();
return new StandardValuesCollection(Enumerable.Range(0, deviceFilters.Count).ToArray());
return new StandardValuesCollection(GetMiniscopeIndices());
}
}
14 changes: 7 additions & 7 deletions OpenEphys.Miniscope/UclaMiniCam.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Bonsai;
using OpenCV.Net;
using System;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Bonsai;
using OpenCV.Net;

namespace OpenEphys.Miniscope
{
Expand Down Expand Up @@ -37,7 +37,7 @@ public enum FrameRateMiniCam
// causes link instabilities even with a short, high-quality, nomimal-gauge SMA cable.
const double LedBrigthnessScaleFactor = 0.26;

[TypeConverter(typeof(IndexConverter))]
[TypeConverter(typeof(MiniscopeIndexConverter))]
[Description("The index of the camera from which to acquire images.")]
public int Index { get; set; } = 0;

Expand All @@ -57,7 +57,7 @@ public enum FrameRateMiniCam
readonly object captureLock = new object();

// NB: Camera regiser (ab)uses
// CaptureProperty.Saturation -> Start acqusition
// CaptureProperty.Saturation -> Start acquisition
// CaptureProperty.Gamma -> Inverted state of trigger input (3.3 -> Gamma = 0, 0V -> Gamma != 0)
// CaptureProperty.Contrast -> DAQ Frame number

Expand All @@ -74,7 +74,7 @@ public UclaMiniCam()
var lastFps = FramesPerSecond;
var lastSensorGain = SensorGain;

using (var capture = Capture.CreateCameraCapture(Index))
using (var capture = Capture.CreateCameraCapture(Index, CaptureDomain.DirectShow))
{
try
{
Expand Down Expand Up @@ -117,7 +117,7 @@ public UclaMiniCam()
var gate = capture.GetProperty(CaptureProperty.Gamma) != 0;

if (LedBrightness != lastLedBrightness || !initialized)
{
{
var scaled = LedBrigthnessScaleFactor * LedBrightness;
Helpers.SendConfig(capture, Helpers.CreateCommand(108, 160, (byte)scaled));
lastLedBrightness = LedBrightness;
Expand Down
10 changes: 5 additions & 5 deletions OpenEphys.Miniscope/UclaMiniscopeV3.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Bonsai;
using OpenCV.Net;
using System;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Bonsai;
using OpenCV.Net;

namespace OpenEphys.Miniscope
{
Expand All @@ -31,7 +31,7 @@ public enum FrameRateV3
const int Width = 752;
const int Height = 480;

[TypeConverter(typeof(IndexConverter))]
[TypeConverter(typeof(MiniscopeIndexConverter))]
[Description("The index of the camera from which to acquire images.")]
public int Index { get; set; } = 0;

Expand Down Expand Up @@ -63,7 +63,7 @@ public UclaMiniscopeV3()
var lastFps = FramesPerSecond;
var lastSensorGain = SensorGain;

using (var capture = Capture.CreateCameraCapture(Index))
using (var capture = Capture.CreateCameraCapture(Index, CaptureDomain.DirectShow))
{
try
{
Expand Down
16 changes: 8 additions & 8 deletions OpenEphys.Miniscope/UclaMiniscopeV4.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using OpenCV.Net;
using System;
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Numerics;
using System.Reactive.Linq;
using System.Threading.Tasks;
using Bonsai;
using System.Numerics;
using OpenCV.Net;

namespace OpenEphys.Miniscope
{
Expand Down Expand Up @@ -34,10 +34,10 @@ public enum FrameRateV4
const int Width = 608;
const int Height = 608;

// 1 quaterion = 2^14 bits
// 1 quaternion = 2^14 bits
const float QuatConvFactor = 1.0f / (1 << 14);

[TypeConverter(typeof(IndexConverter))]
[TypeConverter(typeof(MiniscopeIndexConverter))]
[Description("The index of the camera from which to acquire images.")]
public int Index { get; set; } = 0;

Expand Down Expand Up @@ -72,7 +72,7 @@ public enum FrameRateV4


// NB: Camera regiser (ab)uses
// CaptureProperty.Saturation -> Quaternion W and start acqusition
// CaptureProperty.Saturation -> Quaternion W and start acquisition
// CaptureProperty.Hue -> Quaternion X
// CaptureProperty.Gain -> Quaternion Y
// CaptureProperty.Brightness -> Quaternion Z
Expand All @@ -94,7 +94,7 @@ public UclaMiniscopeV4()
var lastSensorGain = SensorGain;
// var lastInterleaveLed = InterleaveLed;

using (var capture = Capture.CreateCameraCapture(Index))
using (var capture = Capture.CreateCameraCapture(Index, CaptureDomain.DirectShow))
{
try
{
Expand Down Expand Up @@ -164,7 +164,7 @@ public UclaMiniscopeV4()

if (Focus != lastEWL || !initialized)
{
var scaled = Focus * 1.27;
var scaled = Focus * 1.27;
Helpers.SendConfig(capture, Helpers.CreateCommand(238, 8, (byte)(127 + scaled), 2));
lastEWL = Focus;
}
Expand Down
4 changes: 2 additions & 2 deletions OpenEphys.Miniscope/UclaMiniscopeV4Frame.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using OpenCV.Net;
using System.Numerics;
using System.Numerics;
using OpenCV.Net;

namespace OpenEphys.Miniscope
{
Expand Down

0 comments on commit 61053ee

Please sign in to comment.