Skip to content

Commit

Permalink
Minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
COMBudda committed Dec 10, 2023
1 parent b4dc0d4 commit 0141fa8
Showing 1 changed file with 29 additions and 34 deletions.
63 changes: 29 additions & 34 deletions Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Collections.Generic;
using SaleaeDeviceSdkDotNet;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Security.Cryptography;


namespace CGATest
Expand Down Expand Up @@ -91,7 +92,6 @@ public Form1()
ftTimer.Start();

pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

}


Expand Down Expand Up @@ -180,7 +180,7 @@ await Task.Run(() =>
if (restartRequired)
{
mLogic.ReadStart();
toolStripStatusLabel8.Text = "Connected to Logic with " + mLogic.SampleRateHz + "Hz";
toolStripStatusLabel8.Text = "Connected to Logic with " + mLogic.SampleRateHz + " Hz";
}
restartRequired = false;
Thread.Sleep(10);
Expand Down Expand Up @@ -251,17 +251,21 @@ await Task.Run(() =>
sample_rates = mLogic16.GetSupportedSampleRates();


//Sample Rates
//Sample Rate Display
for (int i = 0; i < sample_rates.Count; ++i)
{
uint newSampleRate = sample_rates[i];
ToolStripItem item = toolStripDropDownButton1.DropDownItems.Add(string.Format(sample_rates[i].ToString(), newSampleRate ), null, new EventHandler(SetSamplingRate));

double userfriendlyRate = (double)(newSampleRate / 1000000.0);
string sampleUnit = " MHz";
if (userfriendlyRate < 1) {userfriendlyRate = userfriendlyRate * 1000.0; sampleUnit = " KHz"; }
string rateDescription = userfriendlyRate.ToString() + sampleUnit;
ToolStripItem item = toolStripDropDownButton1.DropDownItems.Add(/*string.Format(sample_rates[i].ToString()*/string.Format("{0,6}",rateDescription, newSampleRate ), null, new EventHandler(SetSamplingRate));
item.Tag = newSampleRate;
}


toolStripStatusLabel8.ForeColor = Color.Green;
toolStripStatusLabel8.Text = "Connected to Logic with " + mSampleRateHz + "Hz";
toolStripStatusLabel8.Text = "Connected to Logic with " + mSampleRateHz + " Hz";

if (mLogic != null)
mLogic.ReadStart();
Expand All @@ -284,7 +288,7 @@ await Task.Run(() =>
// If finished, clean up threads
if (Handler_TBufferInput != null) CTSTBufferInput.Cancel();
if (Handler_TSaleaeWatchdog != null) CTSTSaleaeWatchdog.Cancel();
//if (Handler_TShowPic != null) CTSshowpic.Cancel();
if (Handler_TShowPic != null) CTSshowpic.Cancel();
}

//Saleae
Expand All @@ -303,7 +307,6 @@ void devices_LogicOnConnect(ulong device_id, MLogic logic)

mLogic = logic;
mLogic.OnReadData += new MLogic.OnReadDataDelegate(mLogic_OnReadData);
mLogic.OnWriteData += new MLogic.OnWriteDataDelegate(mLogic_OnWriteData);
mLogic.OnError += new MLogic.OnErrorDelegate(mLogic_OnError);
mLogic.SampleRateHz = mSampleRateHz;
}
Expand Down Expand Up @@ -334,17 +337,6 @@ void mLogic16_OnReadData(ulong device_id, byte[] data)
Console.WriteLine("Logic16: Read {0} bytes, starting with 0x{1:X}", data.Length, data[0]);
}

void mLogic_OnWriteData(ulong device_id, byte[] data)
{
for (int i = 0; i < data.Length; i++)
{
data[i] = mWriteValue;
mWriteValue++;
}

Console.WriteLine("Wrote {0} bytes of data", data.Length);
}

void mLogic_OnError(ulong device_id)
{
toolStripStatusLabel8.Text = "Restarting Stream.";
Expand Down Expand Up @@ -375,13 +367,11 @@ await Task.Run(async () =>
if (newpic != null) // Valid picture received, extract only the area which has data in it
{
RectangleF cloneRect = new RectangleF(0, 0, xposmax_b, yposmax_b);
//if (newpic.Height > 5) newframe = (Bitmap)newpic.Clone(cloneRect, PixelFormat.DontCare);
newframe = (Bitmap)newpic.Clone();
newpic.Dispose();

newframeisready = true;
}

//Remember bitmap size to use small bitmaps later. This speeds up things.
xposmax_b = xposmax; yposmax_b = yposmax;

Expand Down Expand Up @@ -546,7 +536,7 @@ await Task.Run(() =>
sync_long = syncpulses;
}
// If we just got a smal sync, arm the system for an upcoming hsync
// If we just got a small sync, arm the system for an upcoming hsync
if (syncpulses > 0 && syncpulses < (sync_long / 10))
{
armed = true;
Expand Down Expand Up @@ -610,15 +600,20 @@ await Task.Run(() =>
xpos = 0;
//Quality
// Do we have a substantial change but not a hsync (in case of composite)
if (hsync_p > (hduration + 1) && hsync_p < (hduration * 3)) { /*Console.WriteLine("reset jitter"+hduration+":"+hsync_p);*/ hduration = hsync_p; }
// Find the shortest hsync pulse
if (hsync_p < hduration) hduration = hsync_p;
// If there is jitter, skip pixels
xoffset = (hsync_p - hduration);
xpos = xoffset;
//Filter for vsync in the composite mixed sync signal
if (hsync_p < (hduration * 3))
{
// Accomodate signal change if required
if (hsync_p > (hduration + 1)) hduration = hsync_p;
// Find the shortest hsync pulse
if (hsync_p < hduration) hduration = hsync_p;
// If there is jitter, skip pixels
xoffset = (hsync_p - hduration);
//Sanity Check, offset shouldn't exceed hsync pulse length
if (xoffset > hduration) hduration = hsync_p;
xpos = xoffset;
}
hsync_p = 0;
}
else // No sync and no recent changes: Set horizontal pixels
{
Expand All @@ -634,9 +629,9 @@ await Task.Run(() =>
if (smoothing)
{
if (!(blue == bline[xpos, ypos])) setblue = bline[xpos - xoffset, ypos];
if (!(green == gline[xpos, ypos])) setgreen = gline[xpos - xoffset, ypos];
if (!(red == rline[xpos, ypos])) setred = rline[xpos - xoffset, ypos];
if (!(blue == bline[xpos , ypos])) setblue = bline[xpos , ypos];
if (!(green == gline[xpos , ypos])) setgreen = gline[xpos , ypos];
if (!(red == rline[xpos , ypos])) setred = rline[xpos , ypos];
}
ptr[(xpos * 3) + ypos * stride] = setblue;
Expand Down Expand Up @@ -682,7 +677,7 @@ await Task.Run(() =>

}

private void reset()
private void reset()
{
// Reset
syncpulses = 0; sync_long = 0;
Expand Down

0 comments on commit 0141fa8

Please sign in to comment.