53 lines
2.2 KiB
C#
53 lines
2.2 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
|
|
lblVorI.Text += $"Median: {medianVorI}{VormA} "; // Display median value
|
|
|
|
// 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)
|
|
{
|
|
lblVorI.Text += $" Median away from excepted {ExpVorI}{VormA}";
|
|
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)
|
|
{
|
|
lblVorI.ForeColor = Color.LightGreen;
|
|
}
|
|
else if (outOfRangeVoltageChannels.Count != 0)
|
|
{
|
|
lblVorI.Text += "error on " + string.Join(", ", outOfRangeVoltageChannels); // Join all problem channels together to present on form
|
|
lblVorI.ForeColor = Color.Red;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MainForm.Instance.AddToActionsList($"Error checking LEDs: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|