Skip to content

Commit

Permalink
Merge pull request #22 from open-ephys/issue-21
Browse files Browse the repository at this point in the history
Fix MiniCam frame rate
  • Loading branch information
bparks13 authored Nov 6, 2024
2 parents 08a1aeb + 00e9b76 commit 696040f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<UseArtifactsOutput>true</UseArtifactsOutput>
<PackageIcon>icon.png</PackageIcon>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.3.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<LangVersion>10.0</LangVersion>
<Features>strict</Features>
Expand Down
4 changes: 2 additions & 2 deletions ExamplesWorkflows/UclaMiniCam.bonsai
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.5"
<WorkflowBuilder Version="2.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
Expand All @@ -13,7 +13,7 @@
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps50</p1:FramesPerSecond>
<p1:FramesPerSecond>30</p1:FramesPerSecond>
</Combinator>
</Expression>
<Expression xsi:type="MemberSelector">
Expand Down
4 changes: 2 additions & 2 deletions ExamplesWorkflows/UclaMiniCamTriggered.bonsai
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.5"
<WorkflowBuilder Version="2.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
Expand All @@ -13,7 +13,7 @@
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps50</p1:FramesPerSecond>
<p1:FramesPerSecond>30</p1:FramesPerSecond>
</Combinator>
</Expression>
<Expression xsi:type="rx:Condition">
Expand Down
22 changes: 10 additions & 12 deletions OpenEphys.Miniscope/UclaMiniCam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ public enum GainMiniCam
Maximum = 6240,
};

// NB: Needs a unique name, even though its a class member, for de/serilizaiton without issues
public enum FrameRateMiniCam
{
Fps10 = 2048,
Fps40 = 1536,
Fps50 = 6240,
};

// Frame size
const int Width = 1024;
const int Height = 768;
Expand All @@ -50,7 +42,9 @@ public enum FrameRateMiniCam
public GainMiniCam SensorGain { get; set; } = GainMiniCam.Low;

[Description("Frames captured per second.")]
public FrameRateMiniCam FramesPerSecond { get; set; } = FrameRateMiniCam.Fps50;
[Range(5, 47)]
[Editor(DesignTypes.SliderEditor, typeof(UITypeEditor))]
public int FramesPerSecond { get; set; } = 30;

// State
readonly IObservable<UclaMiniCamFrame> source;
Expand Down Expand Up @@ -82,7 +76,7 @@ static internal AbusedUvcRegisters IssueStartCommands(Capture capture)
Helpers.SendConfig(capture, Helpers.CreateCommand(176, 15, 2)); // Speed up I2c bus timer to 50u Max
Helpers.SendConfig(capture, Helpers.CreateCommand(176, 30, 10)); // Decrease BCC timeout, units in 2 ms
Helpers.SendConfig(capture, Helpers.CreateCommand(192, 8, 186, 108)); // Set aliases for MT9P031 and LM3509
Helpers.SendConfig(capture, Helpers.CreateCommand(192, 16, 186, 108)); // Set aliasesor MT9P031 and LM3509
Helpers.SendConfig(capture, Helpers.CreateCommand(192, 16, 186, 108)); // Set aliases for MT9P031 and LM3509
Helpers.SendConfig(capture, Helpers.CreateCommand(186, 3, 5, 255)); // Set height to 1535 rows
Helpers.SendConfig(capture, Helpers.CreateCommand(186, 4, 7, 255)); // Set width to 2047 colums
Helpers.SendConfig(capture, Helpers.CreateCommand(186, 34, 0, 17)); // 2x subsamp and binning 1
Expand Down Expand Up @@ -142,8 +136,12 @@ public UclaMiniCam()

if (FramesPerSecond != lastFps || !initialized)
{
byte vl = (byte)((int)FramesPerSecond & 0x00000FF);
byte vh = (byte)(((int)FramesPerSecond & 0x000FF00) >> 8);
// This was found empirically.
var reg = 37000 / FramesPerSecond;
if (reg < 0) reg = 0;

byte vl = (byte)(reg & 0x00000FF);
byte vh = (byte)((reg & 0x000FF00) >> 8);
Helpers.SendConfig(capture, Helpers.CreateCommand(186, 9, vh, vl));
lastFps = FramesPerSecond;
}
Expand Down

0 comments on commit 696040f

Please sign in to comment.