Skip to content

Commit

Permalink
Implemented min/max statistics and cleaned up the *nix ports list
Browse files Browse the repository at this point in the history
This fixes #7 and #8.
  • Loading branch information
bmuessig committed Jul 3, 2020
1 parent 9e2a4ed commit 6fde639
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 23 deletions.
2 changes: 2 additions & 0 deletions ParksideView/Language.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ internal static class Language
public const string WindowHeading = "Fenster";
public const string TopMostCheckBox = "Deckend";
public const string MinimizeButton = "Minimieren";
public const string StatisticsHeading = "Statistik";
public const string AcqStatusRecording = " Aufzeichnung ({0} seit {1:00}h {2:00}m {3:00}s).";
public const string AcqStatusPrefix = "Status: ";
public const string AcqStatusRunning = "Laufend.";
Expand Down Expand Up @@ -79,6 +80,7 @@ internal static class Language
public const string WindowHeading = "Window";
public const string TopMostCheckBox = "Top most";
public const string MinimizeButton = "Minimize";
public const string StatisticsHeading = "Statistics";
public const string AcqStatusRecording = " Recording ({0} since {1:00}h {2:00}m {3:00}s).";
public const string AcqStatusPrefix = "Status: ";
public const string AcqStatusRunning = "Running.";
Expand Down
120 changes: 98 additions & 22 deletions ParksideView/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 57 additions & 1 deletion ParksideView/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal partial class MainWindow : Form
private StringBuilder recordingBuffer = new StringBuilder();
private DateTime recordingStart = DateTime.Now;
private int blankCount = 0, recordingCount = 0;
private Mode lastMode = Mode.Squarewave;
private double minValue = 0, maxValue = 0;
private bool resetStatistics = true;
private Multimeter meter = null;

public MainWindow()
Expand Down Expand Up @@ -88,6 +91,11 @@ private void refreshPortsButton_Click(object sender, EventArgs e)
RefreshPorts();
}

private void resetButton_Click(object sender, EventArgs e)
{
ClearStatistics();
}

private void acquisitionTimer_Tick(object sender, EventArgs e)
{
// Make sure that the state and meter objects are valid
Expand Down Expand Up @@ -203,6 +211,13 @@ private void acquisitionTimer_Tick(object sender, EventArgs e)
break;
}

// Compare the last range with the current one
if (lastMode != sample.Mode)
{
ClearStatistics();
lastMode = sample.Mode;
}

// Allocate variables for the number parsing
bool negative = false;
int integer = 0, fractional = 0, exponent = 0, precision = 0;
Expand Down Expand Up @@ -247,9 +262,33 @@ private void acquisitionTimer_Tick(object sender, EventArgs e)
// Update the UI
if (!overloaded)
{
// Update the bargraph
bargraphBar.Minimum = 0;
bargraphBar.Maximum = sample.Value < 0 ? Math.Abs(Multimeter.RangeMin(sample.Mode, sample.Range)) : Multimeter.RangeMax(sample.Mode, sample.Range);
bargraphBar.Value = Math.Abs(sample.Value);

// Calculate the double value
double currentValue = Math.Pow(10, exponent) * (integer + (fractional * Math.Pow(10, -precision)));
if (negative)
currentValue = -currentValue;

// Update the min statistics
if (resetStatistics || minValue > currentValue)
{
minValue = currentValue;
minValueLabel.Text = valueLabel.Text + unitLabel.Text;
}

// Update the max statistics
if (resetStatistics || maxValue < currentValue)
{
maxValue = currentValue;
maxValueLabel.Text = valueLabel.Text + unitLabel.Text;
}

// Unset the statistics flag
if (resetStatistics)
resetStatistics = false;
}

// Handle record mode only for valid value modes
Expand Down Expand Up @@ -445,7 +484,7 @@ private void RefreshPorts()
/// <summary>
/// The regex used to match skippable entries in a ports list
/// </summary>
private readonly Regex skippablePortsRegex = new Regex("^/dev/tty[a-z][0-9a-z]$",
private readonly Regex skippablePortsRegex = new Regex("^/dev/tty(?:[a-rt-z]?[0-9]+)$",
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);

/// <summary>
Expand Down Expand Up @@ -685,6 +724,10 @@ private void ChangeUI(bool isConnected, bool isPaused, bool isRecording)
acquisitionPauseButton.Enabled = isConnected;
csvFormatGroup.Enabled = isConnected && !isRecording;
intervalNumeric.Enabled = !isRecording;
resetButton.Enabled = isConnected;

// Clear the statistics
ClearStatistics();

// Clear the readout and bargraph after disconnecting
if (!isConnected)
Expand All @@ -694,6 +737,19 @@ private void ChangeUI(bool isConnected, bool isPaused, bool isRecording)
}
}

/// <summary>
/// Clears the statistics and blanks the labels.
/// </summary>
private void ClearStatistics()
{
lastMode = Mode.Squarewave;
minValue = 0;
maxValue = 0;
resetStatistics = true;
minValueLabel.Text = "-";
maxValueLabel.Text = "-";
}

/// <summary>
/// Updates the status labels.
/// </summary>
Expand Down

0 comments on commit 6fde639

Please sign in to comment.