diff --git a/Form1.Designer.cs b/Form1.Designer.cs index 07eba34..e931598 100644 --- a/Form1.Designer.cs +++ b/Form1.Designer.cs @@ -34,8 +34,10 @@ private void InitializeComponent() radioButton1 = new RadioButton(); timer1 = new System.Windows.Forms.Timer(components); panel1 = new Panel(); - checkBox5 = new CheckBox(); - button1 = new Button(); + label3 = new Label(); + label2 = new Label(); + label1 = new Label(); + comboBox1 = new ComboBox(); checkBox4 = new CheckBox(); groupBox3 = new GroupBox(); label5 = new Label(); @@ -84,7 +86,7 @@ private void InitializeComponent() // radioButton1 // radioButton1.AutoSize = true; - radioButton1.Location = new Point(24, 26); + radioButton1.Location = new Point(24, 19); radioButton1.Name = "radioButton1"; radioButton1.Size = new Size(142, 29); radioButton1.TabIndex = 2; @@ -96,8 +98,10 @@ private void InitializeComponent() // panel1 // panel1.BorderStyle = BorderStyle.Fixed3D; - panel1.Controls.Add(checkBox5); - panel1.Controls.Add(button1); + panel1.Controls.Add(label3); + panel1.Controls.Add(label2); + panel1.Controls.Add(label1); + panel1.Controls.Add(comboBox1); panel1.Controls.Add(checkBox4); panel1.Controls.Add(groupBox3); panel1.Controls.Add(groupBox1); @@ -111,27 +115,44 @@ private void InitializeComponent() panel1.Size = new Size(222, 1233); panel1.TabIndex = 7; // - // checkBox5 - // - checkBox5.AutoSize = true; - checkBox5.Location = new Point(22, 231); - checkBox5.Name = "checkBox5"; - checkBox5.Size = new Size(185, 29); - checkBox5.TabIndex = 21; - checkBox5.Text = "Smoothing (alpha)"; - checkBox5.UseVisualStyleBackColor = true; - checkBox5.CheckedChanged += checkBox5_CheckedChanged; - // - // button1 - // - button1.Location = new Point(54, 802); - button1.Name = "button1"; - button1.Size = new Size(112, 34); - button1.TabIndex = 20; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; - button1.Visible = false; - button1.Click += button1_Click; + // label3 + // + label3.BorderStyle = BorderStyle.Fixed3D; + label3.Location = new Point(11, 62); + label3.Name = "label3"; + label3.Size = new Size(197, 2); + label3.TabIndex = 25; + label3.Text = "label3"; + // + // label2 + // + label2.BorderStyle = BorderStyle.Fixed3D; + label2.Location = new Point(12, 238); + label2.Name = "label2"; + label2.Size = new Size(197, 2); + label2.TabIndex = 24; + label2.Text = "label2"; + // + // label1 + // + label1.AutoSize = true; + label1.Font = new Font("Segoe UI", 8F); + label1.Location = new Point(20, 256); + label1.Name = "label1"; + label1.Size = new Size(87, 42); + label1.TabIndex = 23; + label1.Text = "Smoothing\r\nLevel"; + label1.Click += label1_Click; + // + // comboBox1 + // + comboBox1.DropDownStyle = ComboBoxStyle.DropDownList; + comboBox1.Items.AddRange(new object[] { "0", "1", "2" }); + comboBox1.Location = new Point(127, 260); + comboBox1.Name = "comboBox1"; + comboBox1.Size = new Size(77, 33); + comboBox1.TabIndex = 22; + comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; // // checkBox4 // @@ -155,7 +176,7 @@ private void InitializeComponent() groupBox3.Controls.Add(radioButton6); groupBox3.Controls.Add(textBox6); groupBox3.Controls.Add(textBox5); - groupBox3.Location = new Point(0, 465); + groupBox3.Location = new Point(0, 510); groupBox3.Name = "groupBox3"; groupBox3.Size = new Size(218, 229); groupBox3.TabIndex = 18; @@ -231,7 +252,7 @@ private void InitializeComponent() groupBox1.Controls.Add(radioButton4); groupBox1.Controls.Add(radioButton3); groupBox1.Controls.Add(radioButton2); - groupBox1.Location = new Point(0, 271); + groupBox1.Location = new Point(0, 316); groupBox1.Name = "groupBox1"; groupBox1.Size = new Size(218, 194); groupBox1.TabIndex = 13; @@ -449,7 +470,6 @@ private void InitializeComponent() private Label label5; private Label label4; private CheckBox checkBox4; - private Button button1; private StatusStrip statusStrip1; private ToolStripStatusLabel toolStripStatusLabel1; private ToolStripStatusLabel toolStripStatusLabel2; @@ -459,7 +479,10 @@ private void InitializeComponent() private ToolStripStatusLabel toolStripStatusLabel6; private ToolStripStatusLabel toolStripStatusLabel7; private ToolStripStatusLabel toolStripStatusLabel8; - private CheckBox checkBox5; private ToolStripDropDownButton toolStripDropDownButton1; + private ComboBox comboBox1; + private Label label1; + private Label label2; + private Label label3; } } diff --git a/Form1.cs b/Form1.cs index b1b2bc8..cc1c7a5 100644 --- a/Form1.cs +++ b/Form1.cs @@ -68,7 +68,6 @@ public partial class Form1 : Form UInt32 mSampleRateHz = 24000000; MLogic mLogic; MLogic16 mLogic16; - byte mWriteValue = 0; bool restartRequired = true; // vsync_polarity handling @@ -79,6 +78,7 @@ public partial class Form1 : Form //Test quality int hduration = 9999; bool smoothing = false; + int smoothingLevel = 0; public Form1() { @@ -104,7 +104,7 @@ private void TShowInfo(object myObject, EventArgs myEventArgs) screens = 0; } - + private async void TShowPic(object? obj) { Bitmap? resized = null; @@ -127,7 +127,7 @@ private async void TShowPic(object? obj) pictureBox1.Image = (Bitmap)resized.Clone(); resized.Dispose(); } - + newframe.Dispose(); newframeisready = false; } @@ -137,7 +137,7 @@ private async void TShowPic(object? obj) } ); } - + // Read input stream to buffer private async void TBufferInput(object? o) @@ -179,7 +179,7 @@ private async void TSaleaeWatchdog(object? o) { if (restartRequired) { - mLogic.ReadStart(); + mLogic.ReadStart(); toolStripStatusLabel8.Text = "Connected to Logic with " + mLogic.SampleRateHz + " Hz"; } restartRequired = false; @@ -258,9 +258,9 @@ private async void Form1_Shown(object sender, EventArgs e) double userfriendlyRate = (double)(newSampleRate / 1000000.0); string sampleUnit = " MHz"; - if (userfriendlyRate < 1) {userfriendlyRate = userfriendlyRate * 1000.0; sampleUnit = " KHz"; } + 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)); + ToolStripItem item = toolStripDropDownButton1.DropDownItems.Add(/*string.Format(sample_rates[i].ToString()*/string.Format("{0,6}", rateDescription, newSampleRate), null, new EventHandler(SetSamplingRate)); item.Tag = newSampleRate; } @@ -366,12 +366,17 @@ public async Task Main(object sender, EventArgs e) 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); - newframe = (Bitmap)newpic.Clone(); - newpic.Dispose(); + try + { + RectangleF cloneRect = new RectangleF(0, 0, xposmax_b, yposmax_b); + newframe = (Bitmap)newpic.Clone(); - newframeisready = true; + newframeisready = true; + } + catch { }; + newpic.Dispose(); } + //Remember bitmap size to use small bitmaps later. This speeds up things. xposmax_b = xposmax; yposmax_b = yposmax; @@ -388,7 +393,7 @@ public async Task Main(object sender, EventArgs e) private async Task CreatePicture(object sender, EventArgs e) { - Bitmap bmp = new Bitmap((xposmax_b > 10 ? xposmax : 10), (yposmax_b > 10 ? yposmax_b : 10)); + Bitmap bmp = new Bitmap((xposmax_b > 10 ? xposmax : 10), (yposmax_b > 10 ? yposmax_b : 10)); int readchar, readFail; int rawdata = 0; @@ -417,6 +422,9 @@ private async Task CreatePicture(object sender, EventArgs e) int stride = data.Stride; //experiment + //??? Real max value for consitent frame size + xposmax = 0; + await Task.Run(() => { while (loop && !endofstream) @@ -593,15 +601,18 @@ private async Task CreatePicture(object sender, EventArgs e) if (hsyncc) // Just coming from a hsync signal, new line { - // expectation setting and limiter - xposmax = xpos; + + //Real x-max value for consitent frame size + if (xpos > xposmax) { xposmax = xpos; } + // new line and reset horizontal if (ypos < height) ypos++; xpos = 0; //Quality - //Filter for vsync in the composite mixed sync signal - if (hsync_p < (hduration * 3)) + //IF-Then as a filter for vsync in the composite mixed sync signal + + if (hsync_p < (hduration * 3) && true) { // Accomodate signal change if required if (hsync_p > (hduration + 1)) hduration = hsync_p; @@ -617,7 +628,7 @@ private async Task CreatePicture(object sender, EventArgs e) } else // No sync and no recent changes: Set horizontal pixels { - if (xpos > 0 && xpos < width && xpos < xposmax_b && ypos < yposmax_b ) // Within defined bitmap ? + if (xpos > 0 && xpos < width && xpos < xposmax_b && ypos < yposmax_b) // Within defined bitmap ? { byte setblue = blue; byte setgreen = green; @@ -629,9 +640,9 @@ private async Task CreatePicture(object sender, EventArgs e) if (smoothing) { - 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]; + 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; @@ -641,9 +652,9 @@ private async Task CreatePicture(object sender, EventArgs e) if (smoothing) { - bline[xpos, ypos] = (byte)((setblue * 2 + blue) / 3); - gline[xpos, ypos] = (byte)((setgreen * 2 + green) / 3); - rline[xpos, ypos] = (byte)((setred * 2 + red) / 3); + bline[xpos, ypos] = (byte)((setblue * smoothingLevel + blue) / (smoothingLevel + 1)); + gline[xpos, ypos] = (byte)((setgreen * smoothingLevel + green) / (smoothingLevel + 1)); + rline[xpos, ypos] = (byte)((setred * smoothingLevel + red) / (smoothingLevel + 1)); } xpos++; } @@ -663,7 +674,7 @@ private async Task CreatePicture(object sender, EventArgs e) // Visualize parameters TB1 = xposmax_b; TB2 = yposmax_b; - + if (xposmax_b < 10 || yposmax_b < 10 || endofstream) return null; // received frame is too small or stream stopped, discard else { @@ -673,7 +684,7 @@ private async Task CreatePicture(object sender, EventArgs e) return bmp; } - + } @@ -791,12 +802,6 @@ private void button1_Click(object sender, EventArgs e) endofstream = true; } - private void checkBox5_CheckedChanged(object sender, EventArgs e) - { - smoothing = !smoothing; - checkBox5.Checked = smoothing; - } - private void SetSamplingRate(object sender, EventArgs e) { ToolStripItem item = (ToolStripItem)sender; @@ -806,6 +811,17 @@ private void SetSamplingRate(object sender, EventArgs e) mLogic.SampleRateHz = newRate; restartRequired = true; } -} + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + smoothingLevel = comboBox1.SelectedIndex; + if (smoothingLevel == 0) { smoothing = false; } else smoothing = true; + } + + private void label1_Click(object sender, EventArgs e) + { + + } + } }