Files
AiQ_GUI/Camera/CameraModules.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

158 lines
7.5 KiB
C#

namespace AiQ_GUI
{
internal class CameraModules
{
// Chack camera modules are in default state according to what the diagnostics API.
public static void CheckCamModule(Module CamMod, Label Lbl, Camera CamOnTest)
{
if (CamMod == null)
{
MainForm.Instance.AddToActionsList("Camera module was null in CheckCamModule.", Level.ERROR);
return;
}
string errMssg = "";
if (CamMod.zoom != 0) // Check camera module is at full wide
errMssg += $"Zoom not at 0 - {CamMod.zoom} ";
bool LessTanOrEqualTo = false;
try
{
LessTanOrEqualTo = Convert.ToDouble(CamMod.firmwareVer) <= Convert.ToDouble(UniversalData.WonwooFirmware);
}
catch
{
MainForm.Instance.AddToActionsList($"{CamMod.firmwareVer} or {UniversalData.WonwooFirmware} could not be converted to a double", Level.ERROR);
}
if (CamOnTest.RMANum > 0 && !LessTanOrEqualTo)
errMssg += $"Firmware: {CamMod.firmwareVer} should be less than or equal to {UniversalData.WonwooFirmware} for RMA {CamOnTest.RMANum}";
else if (CamOnTest.RMANum < 1 && CamMod.firmwareVer != UniversalData.WonwooFirmware)
errMssg += $"Firmware: {CamMod.firmwareVer} should be {UniversalData.WonwooFirmware} ";
if (CamMod.expMode != 0) // Auto 0=0x00
errMssg += $"Exp mode not set: {CamMod.expMode} ";
// Determine display result
string displayResult = string.IsNullOrWhiteSpace(errMssg) ? "OK" : errMssg;
bool isError = !string.IsNullOrWhiteSpace(errMssg);
// Create label dynamically if not provided
if (Lbl == null)
{
string moduleName;
try
{
if (object.ReferenceEquals(CamMod, AiQ_GUI.AiQ_Tests.TestingFunctions.DiagsAPI.IRmodule))
moduleName = "IR Module";
else if (object.ReferenceEquals(CamMod, AiQ_GUI.AiQ_Tests.TestingFunctions.DiagsAPI.OVmodule))
moduleName = "OV Module";
else
moduleName = CamMod.firmwareVer == null ? "OV Module" : (CamMod.zoom < 5000 ? "IR Module" : "OV Module");
}
catch
{
moduleName = CamMod.firmwareVer == null ? "OV Module" : (CamMod.zoom < 5000 ? "IR Module" : "OV Module");
}
MainForm.Instance.AddLabelToPanel($"{moduleName} = {displayResult}", isError);
return;
}
// Update existing label
try
{
Lbl.Invoke(() =>
{
Lbl.Text = Lbl.Text.TrimEnd('=', ' ') + " = " + displayResult;
Lbl.ForeColor = isError ? Color.Red : Color.LimeGreen;
});
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList("Exception in CheckCamModule: " + ex.Message, Level.ERROR);
}
}
// Sets shutter, iris and gain to the values given in the dropdowns on the GUI.
public static async Task SetSIG(ComboBox Shutter, ComboBox Iris, ComboBox Gain, string IPAddress) // Set SIG according to the comboboxes on the images tab
{
if (Shutter.SelectedIndex == -1 || Iris.SelectedIndex == -1 || Gain.SelectedIndex == -1)
{
MainForm.Instance.AddToActionsList("Shutter, Iris and Gain need selecting in images tab.", Level.WARNING);
return;
}
string ShutterVISCA = BuildVISCACommand("A", Shutter.SelectedIndex + 7); // Offset for not starting at the beggining of the VISCA table
string IrisVISCA = BuildVISCACommand("B", Iris.SelectedIndex + 4); // Offset for not starting at the beggining of the VISCA table
string GainVISCA = BuildVISCACommand("C", Gain.SelectedIndex);
if (ShutterVISCA.Contains("ERROR") || IrisVISCA.Contains("ERROR") || GainVISCA.Contains("ERROR"))
{
MainForm.Instance.AddToActionsList("Problem with selected SIG values", Level.ERROR);
return;
}
string ShutterReply = await FlexiAPI.APIHTTPVISCA(IPAddress, ShutterVISCA, true); // Set Shutter
string IrisReply = await FlexiAPI.APIHTTPVISCA(IPAddress, IrisVISCA, true); // Set Iris
string GainReply = await FlexiAPI.APIHTTPVISCA(IPAddress, GainVISCA, true); // Set Gain
string OneshotReply = await FlexiAPI.APIHTTPVISCA(IPAddress, "8101041801FF", true); // Oneshot auto focus
if (!ShutterReply.Contains("41") || !IrisReply.Contains("41") || !GainReply.Contains("41") || !OneshotReply.Contains("41"))
MainForm.Instance.AddToActionsList("Could not set Shutter, Iris, Gain correctly" + Environment.NewLine + "Shutter: " + ShutterReply + Environment.NewLine + "Iris: " + IrisReply + Environment.NewLine + "Gain: " + GainReply + Environment.NewLine + "Oneshot: " + OneshotReply, Level.ERROR);
}
// Sets back to the latest factory defaults CSV that is in Flexi.
public static async Task FactoryResetModules(string IPAddress)
{
// Set both camera modules back to MAV defaults. Found in WonwooDefaultSettingsIR.csv & WonwooDefaultSettingsOV.csv
Task<string> IRReply = FlexiAPI.APIHTTPRequest("/Infrared-camera-factory-reset", IPAddress, 10);
Task<string> OVReply = FlexiAPI.APIHTTPRequest("/Colour-camera-factory-reset", IPAddress, 10);
await Task.WhenAll(IRReply, OVReply);
if (IRReply.Result != "Factory reset OK." || OVReply.Result != "Factory reset OK.")
MainForm.Instance.AddToActionsList($"Could not reset camera modules to factory default.{Environment.NewLine}{IRReply}{Environment.NewLine}{OVReply}", Level.ERROR);
}
public static string BuildVISCACommand(string command, int hexValue)
{
// Take the augmented Selected index into a two nibble hex value.
string hex = $"{hexValue:X2}";
// Build the final VISCA command string using the input characters split as p and q
return $"8101044{command}00000{hex[0]}0{hex[1]}FF";
}
public static async Task<bool> SetZoomLockOn(string IP)
{
// Set Zoomlock on and if it fails ask user to set it manually
if (!(await FlexiAPI.APIHTTPRequest("/api/zoomLock?enable=true", IP)).Contains("Zoom lock enabled.")
&& !await MainForm.Instance.DisplayQuestion("Could not set zoomlock on" + Environment.NewLine + "Set Zoomlock to on then click YES. Click NO to restart."))
{
return false;
}
return true;
}
public static async Task<bool> ZoomModules(string VISCAInput, string IPAddress)
{
// Populate the VISCA command with the four zoom characters
string VISCA = $"810104470{VISCAInput[0]}0{VISCAInput[1]}0{VISCAInput[2]}0{VISCAInput[3]}FF";
Task<string> TS1 = FlexiAPI.APIHTTPVISCA(IPAddress, VISCA, true);
Task<string> TS2 = FlexiAPI.APIHTTPVISCA(IPAddress, VISCA, false);
await Task.WhenAll(TS1, TS2);
const string ExpReply = "9041FF9051FF";
if (TS1.Result == ExpReply && TS1.Result == ExpReply)
return true;
return false;
}
}
}