Skip to content

Commit

Permalink
Updated applications
Browse files Browse the repository at this point in the history
  • Loading branch information
gusmanb committed Jan 29, 2023
1 parent 2816c8b commit bf29561
Show file tree
Hide file tree
Showing 23 changed files with 354 additions and 49 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
38 changes: 36 additions & 2 deletions Software/LogicAnalyzer/CLCapture/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,25 @@
if (opts.Trigger.TriggerType == CLTriggerType.Edge)
{
Console.WriteLine("Starting edge triggered capture...");
driver.StartCapture(opts.SamplingFrequency, opts.PreSamples, opts.PostSamples,
var resStart = driver.StartCapture(opts.SamplingFrequency, opts.PreSamples, opts.PostSamples,
channels, opts.Trigger.Channel - 1, opts.Trigger.Value == "0", CaptureFinished);

if (resStart != CaptureError.None)
{
switch (resStart)
{
case CaptureError.Busy:
Console.WriteLine("Device is busy, stop the capture before starting a new one.");
return -1;
case CaptureError.BadParams:
Console.WriteLine("Specified parameters are incorrect.\r\n\r\n -Frequency must be between 3.1Khz and 100Mhz\r\n -PreSamples must be between 2 and 31743\r\n -PostSamples must be between 512 and 32767\r\n -Total samples cannot exceed 32767");
return -1;
case CaptureError.HardwareError:
Console.WriteLine("Device reported error starting capture. Restart the device and try again.");
return -1;
}
}

Console.WriteLine("Capture running...");
}
else
Expand All @@ -150,8 +167,25 @@
triggerPattern |= (UInt16)(1 << buc);
}

driver.StartPatternCapture(opts.SamplingFrequency, opts.PreSamples, opts.PostSamples,
var resStart = driver.StartPatternCapture(opts.SamplingFrequency, opts.PreSamples, opts.PostSamples,
channels, opts.Trigger.Channel - 1, bitCount, triggerPattern, opts.Trigger.TriggerType == CLTriggerType.Fast, CaptureFinished);

if (resStart != CaptureError.None)
{
switch (resStart)
{
case CaptureError.Busy:
Console.WriteLine("Device is busy, stop the capture before starting a new one.");
return -1;
case CaptureError.BadParams:
Console.WriteLine("Specified parameters are incorrect.\r\n\r\n -Frequency must be between 3.1Khz and 100Mhz\r\n -PreSamples must be between 2 and 31743\r\n -PostSamples must be between 512 and 32767\r\n -Total samples cannot exceed 32767");
return -1;
case CaptureError.HardwareError:
Console.WriteLine("Device reported error starting capture. Restart the device and try again.");
return -1;
}
}

Console.WriteLine("Capture running...");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using LogicAnalyzer.Classes;
using Newtonsoft.Json;
using Newtonsoft.Json;
using SharedDriver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LogicAnalyzer
namespace LogicAnalyzer.Classes
{
public class ExportedCapture
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static Brush GetBrush(Color BrushColor)

public static Pen GetPen(Color PenColor, double PenThickness, IDashStyle Style = null)
{
string key = "COLOR" + PenColor.ToString() + PenThickness.ToString() + (Style?.ToString() ?? "");
string key = "COLOR" + PenColor.ToString() + PenThickness.ToString() + GetDashName(Style);

if (!_pens.ContainsKey(key))
{
Expand All @@ -39,7 +39,7 @@ public static Pen GetPen(Color PenColor, double PenThickness, IDashStyle Style =

public static Pen GetPen(IBrush PenBrush, double PenThickness, IDashStyle Style = null)
{
string key = "BRUSH" + PenBrush.GetHashCode().ToString() + PenThickness.ToString() + (Style?.ToString() ?? "");
string key = "BRUSH" + PenBrush.GetHashCode().ToString() + PenThickness.ToString() + GetDashName(Style);

if (!_pens.ContainsKey(key))
{
Expand All @@ -50,5 +50,10 @@ public static Pen GetPen(IBrush PenBrush, double PenThickness, IDashStyle Style

return _pens[key];
}

static string GetDashName(IDashStyle Style)
{
return Style == null ? "" : string.Join("", Style.Dashes) + "-" + Style.Offset.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SelectedSampleRegion
{
public int FirstSample { get; set; }
public int LastSample { get; set; }
public int SampleCount { get { return LastSample - FirstSample; } }
public int SampleCount { get { return Math.Abs(LastSample - FirstSample); } }
public string RegionName { get; set; } = "";
public Color RegionColor { get; set; } = Color.FromArgb(128, 255,255,255);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,15 @@ public class RegionEventArgs : EventArgs
{
public SelectedSampleRegion? Region { get; set; }
}

public class SamplesEventArgs : EventArgs
{
public int FirstSample { get; set; }
public int SampleCount { get; set; }
}

public class UserMarkerEventArgs : EventArgs
{
public int Position { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@
<TextBlock Margin="0,0,0,0" Name="lblLeft" VerticalAlignment="Center" HorizontalAlignment="Left"></TextBlock>
<TextBlock Name="lblCenter" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<TextBlock Margin="0,0,0,0" Name="lblRight" VerticalAlignment="Center" HorizontalAlignment="Right"></TextBlock>

<Panel.ContextMenu>
<ContextMenu Name="rgnDeleteMenu">
<MenuItem Header="Delete regions" Name="mnuDeleteRegions" />
<MenuItem Header="Delete regions and samples" Name="mnuDeleteRegionsSamples" />
</ContextMenu>
</Panel.ContextMenu>
</Panel>
</UserControl>
123 changes: 109 additions & 14 deletions Software/LogicAnalyzer/LogicAnalyzer/Controls/SampleMarker.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,59 @@ public int VisibleSamples
public event EventHandler<RegionEventArgs> RegionCreated;
public event EventHandler<RegionEventArgs> RegionDeleted;

public event EventHandler<SamplesEventArgs> SamplesDeleted;
public event EventHandler<UserMarkerEventArgs> UserMarkerSelected;

List<SelectedSampleRegion> regions = new List<SelectedSampleRegion>();

SelectedSampleRegion? regionUnderConstruction;
SelectedSampleRegion[] regionsToDelete = null;

int? userMarker = null;
public SelectedSampleRegion[] SelectedRegions { get { return regions.ToArray(); } }

public SampleMarker()
{
InitializeComponent();
mnuDeleteRegions.Click += MnuDeleteRegions_Click;
mnuDeleteRegionsSamples.Click += MnuDeleteRegionsSamples_Click;
}

private void MnuDeleteRegionsSamples_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var minDelete = regionsToDelete.Select(r => Math.Min(r.FirstSample, r.LastSample)).Min();
var maxDelete = regionsToDelete.Select(r => Math.Max(r.LastSample, r.FirstSample)).Max();

int len = maxDelete - minDelete;

if (RegionDeleted != null)
{
foreach (var region in regionsToDelete)
{
RegionDeleted(this, new RegionEventArgs { Region = region });
RemoveRegion(region);
}
}

if (SamplesDeleted != null)
SamplesDeleted(this, new SamplesEventArgs { FirstSample = minDelete, SampleCount = len });
}

private void MnuDeleteRegions_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
var minDelete = regionsToDelete.Select(r => Math.Min(r.FirstSample, r.LastSample)).Min();
var maxDelete = regionsToDelete.Select(r => Math.Max(r.LastSample, r.FirstSample)).Max();

int len = maxDelete - minDelete;

if (RegionDeleted != null)
{
foreach (var region in regionsToDelete)
{
RegionDeleted(this, new RegionEventArgs { Region = region });
RemoveRegion(region);
}
}
}

public void AddRegion(SelectedSampleRegion Region)
Expand Down Expand Up @@ -111,8 +156,8 @@ public override void Render(DrawingContext context)

if (regionUnderConstruction != null)
{

double start = (regionUnderConstruction.FirstSample - FirstSample) * sampleWidth;
int first = Math.Min(regionUnderConstruction.FirstSample, regionUnderConstruction.LastSample);
double start = (first - FirstSample) * sampleWidth;
double end = sampleWidth * regionUnderConstruction.SampleCount;
context.FillRectangle(GraphicObjectsCache.GetBrush(regionUnderConstruction.RegionColor), new Rect(start, 0, end, this.Bounds.Height));

Expand All @@ -122,7 +167,8 @@ public override void Render(DrawingContext context)
{
foreach (var region in regions)
{
double start = (region.FirstSample - FirstSample) * sampleWidth;
int first = Math.Min(region.FirstSample, region.LastSample);
double start = (first - FirstSample) * sampleWidth;
double end = sampleWidth * region.SampleCount;
context.FillRectangle(GraphicObjectsCache.GetBrush(region.RegionColor), new Rect(start, 0, end, this.Bounds.Height));
FormattedText text = new FormattedText(region.RegionName, Typeface.Default, 12, TextAlignment.Left, TextWrapping.NoWrap, Size.Infinity);
Expand All @@ -138,6 +184,11 @@ public override void Render(DrawingContext context)
double y2 = this.Bounds.Height;

context.DrawLine(GraphicObjectsCache.GetPen(Foreground, 1), new Point(x, y1), new Point(x, y2));

x = buc * sampleWidth;
y1 = halfHeight * 1.75f;

context.DrawLine(GraphicObjectsCache.GetPen(Foreground, 1), new Point(x, y1), new Point(x, y2));
}

base.Render(context);
Expand Down Expand Up @@ -191,7 +242,7 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)

int ovrSample = (int)(pos.Position.X / sampleWidth) + FirstSample;

regionUnderConstruction = new SelectedSampleRegion { FirstSample = ovrSample, LastSample = ovrSample + 1 };
regionUnderConstruction = new SelectedSampleRegion { FirstSample = ovrSample, LastSample = ovrSample };
this.InvalidateVisual();
}
}
Expand Down Expand Up @@ -229,12 +280,48 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)
double sampleWidth = this.Bounds.Width / (float)VisibleSamples;
int ovrSample = (int)(pos.Position.X / sampleWidth) + FirstSample;
regionUnderConstruction.LastSample = ovrSample + 1;

if (regionUnderConstruction.LastSample < regionUnderConstruction.FirstSample)
{
int val = regionUnderConstruction.FirstSample;
regionUnderConstruction.FirstSample = regionUnderConstruction.LastSample;
regionUnderConstruction.LastSample = val;
}

var rgn = regionUnderConstruction;
regionUnderConstruction = null;

if (rgn.SampleCount > 0)
{
ShowDialog(rgn);
if (rgn.SampleCount == 1)
{

if(userMarker != null && userMarker == rgn.FirstSample)
userMarker = null;

if (e.InputModifiers.HasFlag(InputModifiers.Shift) && userMarker != null)
{

if (this.UserMarkerSelected != null)
this.UserMarkerSelected(this, new UserMarkerEventArgs { Position = userMarker.Value });

rgn.FirstSample = userMarker.Value;

userMarker = null;

ShowDialog(rgn);
return;
}

userMarker = rgn.FirstSample;

if (this.UserMarkerSelected != null)
this.UserMarkerSelected(this, new UserMarkerEventArgs { Position = rgn.FirstSample });

this.InvalidateVisual();
}
else
ShowDialog(rgn);

}
else
Expand All @@ -245,18 +332,26 @@ protected override void OnPointerReleased(PointerReleasedEventArgs e)
double sampleWidth = this.Bounds.Width / (float)VisibleSamples;
int ovrSample = (int)(pos.Position.X / sampleWidth) + FirstSample;

var toDelete = regions.Where(r => ovrSample >= r.FirstSample && ovrSample < r.LastSample).ToArray();
var toDelete = regions.Where(r => ovrSample >= Math.Min(r.FirstSample , r.LastSample) && ovrSample < Math.Max(r.FirstSample, r.LastSample)).ToArray();

foreach (var region in toDelete)
if (toDelete != null && toDelete.Length > 0)
{
if (ovrSample >= region.FirstSample && ovrSample < region.LastSample)
{
if (RegionDeleted != null)
RegionDeleted(this, new RegionEventArgs { Region = region });

RemoveRegion(region);
}
regionsToDelete= toDelete;
rgnDeleteMenu.PlacementRect = new Rect(pos.Position.X, pos.Position.Y, 1, 1);
rgnDeleteMenu.Open();
}

//foreach (var region in toDelete)
//{
// if (ovrSample >= region.FirstSample && ovrSample < region.LastSample)
// {

// if (RegionDeleted != null)
// RegionDeleted(this, new RegionEventArgs { Region = region });

// RemoveRegion(region);
// }
//}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ public partial class SampleViewer : UserControl
public int SamplesInScreen { get; set; }
public int FirstSample { get; set; }

public int? UserMarker { get; set; }

bool updating = false;

List<SelectedSampleRegion> regions = new List<SelectedSampleRegion>();

public SelectedSampleRegion[] SelectedRegions { get { return regions.ToArray(); } }

List<ProtocolAnalyzedChannel> analysisData = new List<ProtocolAnalyzedChannel>();
Color sampleLineColor = Color.FromArgb(80,120,120,120);
Color sampleLineColor = Color.FromArgb(80, 120, 120, 120);
Color triggerLineColor = Colors.White;
Color userLineColor = Colors.Cyan;
DashStyle halfDash = new DashStyle(new double[] { 1, 8 }, 0);
DashStyle fullDash = new DashStyle(new double[] { 4, 5 }, 0);
public SampleViewer()
{
InitializeComponent();
Expand Down Expand Up @@ -107,7 +112,8 @@ public override void Render(DrawingContext context)
{
foreach (var region in regions)
{
double start = (region.FirstSample - FirstSample) * sampleWidth;
int first = Math.Min(region.FirstSample, region.LastSample);
double start = (first - FirstSample) * sampleWidth;
double end = sampleWidth * region.SampleCount;
context.FillRectangle(GraphicObjectsCache.GetBrush(region.RegionColor), new Rect(start, 0, end, this.Bounds.Height));
}
Expand All @@ -120,11 +126,16 @@ public override void Render(DrawingContext context)
uint prevSample = buc == 0 ? 0 : Samples[buc - 1];
double lineX = (buc - FirstSample) * sampleWidth;

context.DrawLine(GraphicObjectsCache.GetPen(sampleLineColor, 1, DashStyle.Dash), new Point(lineX + sampleWidth / 2, 0), new Point(lineX + sampleWidth / 2, thisBounds.Height));
context.DrawLine(GraphicObjectsCache.GetPen(sampleLineColor, 1, fullDash), new Point(lineX + sampleWidth / 2, 0), new Point(lineX + sampleWidth / 2, thisBounds.Height));

context.DrawLine(GraphicObjectsCache.GetPen(sampleLineColor, 1, halfDash), new Point(lineX, 0), new Point(lineX, thisBounds.Height));

if (buc == PreSamples)
context.DrawLine(GraphicObjectsCache.GetPen(triggerLineColor, 2), new Point(lineX, 0), new Point(lineX, thisBounds.Height));

if(UserMarker != null && UserMarker == buc)
context.DrawLine(GraphicObjectsCache.GetPen(userLineColor, 2, DashStyle.DashDot), new Point(lineX, 0), new Point(lineX, thisBounds.Height));

for (int chan = 0; chan < ChannelCount; chan++)
{
double lineY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock VerticalAlignment="Center" Margin="0,0,5,0">Pre samples:</TextBlock>
<NumericUpDown Width="130" Height="35" Value="512" Minimum="0" Maximum="32767" Name="nudPreSamples"></NumericUpDown>
<NumericUpDown Width="130" Height="35" Value="512" Minimum="2" Maximum="31743" Name="nudPreSamples"></NumericUpDown>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
<TextBlock VerticalAlignment="Center" Margin="0,0,5,0">Post samples:</TextBlock>
<NumericUpDown Width="130" Height="35" Value="1024" Minimum="0" Maximum="32767" Name="nudPostSamples"></NumericUpDown>
<NumericUpDown Width="130" Height="35" Value="1024" Minimum="512" Maximum="32767" Name="nudPostSamples"></NumericUpDown>
</StackPanel>
</Grid>
<Grid Grid.Row="1" RowDefinitions="2*,5*">
Expand Down
Loading

0 comments on commit bf29561

Please sign in to comment.