Files
AiQ_GUI/Camera/LED.cs
Bradley Born 693da58fcb • Camera/LED.cs
• Added null-checks so labels are created dynamically when lblVorI is null (uses MainForm.Instance.AddLabelToPanel).
• Camera/CameraModules.cs
• Added null-label handling to create dynamic module labels with the correct content (OK or the error message).
• AiQ_GUI.cs
• Increased dynamic label width in MakeNewLabel from 220 → 700 to avoid truncated messages.
• Succesfully ran through a pre-test with dynamic labels
2026-01-05 12:35:28 +00:00

97 lines
4.0 KiB
C#

namespace AiQ_GUI
{
internal class LED
{
// Checks the LED voltages and currents against expected values, displaying results in the provided label
public static void CheckLEDs(List<double> VorI, Label lblVorI, string VormA, double ExpVorI)
{
try
{
VorI.Sort(); // Sort the list from lowest to highest to prepare for finding the median
double medianVorI = (VorI[2] + VorI[3]) / 2.0; // Will always be even (6) number of channels therefore average the two middle elements
string medianText = $"Median: {medianVorI}{VormA}";
//Expected value of 0 means informational only (force green)
if (ExpVorI == 0)
{
if (lblVorI == null)
{
MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", false);
return;
}
lblVorI.Invoke(() =>
{
lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText;
lblVorI.ForeColor = Color.LimeGreen;
});
return;
}
// Define the 20% threshold ranges
double LowerThreshold = ExpVorI * 0.8;
double UpperThreshold = ExpVorI * 1.2;
// Check median is within 20% of the expected value
if (medianVorI < LowerThreshold || medianVorI > UpperThreshold)
{
medianText += $" (away from expected {ExpVorI}{VormA})";
if (lblVorI == null)
{
MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", true);
return;
}
lblVorI.Invoke(() =>
{
lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText;
lblVorI.ForeColor = Color.Red;
});
return;
}
List<string> outOfRangeVoltageChannels = []; // List to store out-of-range channels
// Check each voltage/current channel is within 20% of expected
for (int i = 0; i < 6; i++)
{
if (VorI[i] < LowerThreshold || VorI[i] > UpperThreshold)
outOfRangeVoltageChannels.Add($"Ch{i + 1}");
}
// If there are no single channels outside the threshold then green, else red
if (outOfRangeVoltageChannels.Count == 0)
{
if (lblVorI == null)
{
MainForm.Instance.AddLabelToPanel($"LED {VormA} = {medianText}", false);
return;
}
lblVorI.Invoke(() =>
{
lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + medianText;
lblVorI.ForeColor = Color.LimeGreen;
});
}
else if (outOfRangeVoltageChannels.Count != 0)
{
string errorText = medianText + " (error on " + string.Join(", ", outOfRangeVoltageChannels) + ")";
if (lblVorI == null)
{
MainForm.Instance.AddLabelToPanel($"LED {VormA} = {errorText}", true);
return;
}
lblVorI.Invoke(() =>
{
lblVorI.Text = lblVorI.Text.TrimEnd('=', ' ') + " = " + errorText;
lblVorI.ForeColor = Color.Red;
});
}
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList($"Error checking LEDs: {ex.Message}", Level.ERROR);
}
}
}
}