2025-09-02 15:32:24 +01:00
namespace AiQ_GUI
{
internal class CameraModules
{
// Chack camera modules are in default state according to what the diagnostics API.
2025-11-26 14:39:07 +00:00
public static void CheckCamModule ( Module CamMod , Label Lbl , Camera CamOnTest )
2025-09-02 15:32:24 +01:00
{
if ( CamMod = = null | | Lbl = = null )
{
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( "Camera module or label was null in CheckCamModule." , Level . ERROR ) ;
2025-09-02 15:32:24 +01:00
return ;
}
string errMssg = "" ;
if ( CamMod . zoom ! = 0 ) // Check camera module is at full wide
errMssg + = $"Zoom not at 0 - {CamMod.zoom} " ;
2025-11-26 14:39:07 +00:00
bool LessTanOrEqualTo = false ;
try
{
LessTanOrEqualTo = Convert . ToDouble ( CamMod . firmwareVer ) < = Convert . ToDouble ( UniversalData . WonwooFirmware ) ;
}
catch
{
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( $"{CamMod.firmwareVer} or {UniversalData.WonwooFirmware} could not be converted to a double" , Level . ERROR ) ;
2025-11-26 14:39:07 +00:00
}
2025-12-02 11:02:24 +00:00
if ( CamOnTest . RMANum > 0 & & ! LessTanOrEqualTo )
2025-11-26 14:39:07 +00:00
errMssg + = $"Firmware: {CamMod.firmwareVer} should be less than or equal to {UniversalData.WonwooFirmware} for RMA {CamOnTest.RMANum}" ;
2025-12-02 11:02:24 +00:00
else if ( CamOnTest . RMANum < 1 & & CamMod . firmwareVer ! = UniversalData . WonwooFirmware )
2025-09-02 15:32:24 +01:00
errMssg + = $"Firmware: {CamMod.firmwareVer} should be {UniversalData.WonwooFirmware} " ;
if ( CamMod . expMode ! = 0 ) // Auto 0=0x00
errMssg + = $"Exp mode not set: {CamMod.expMode} " ;
try
{
Lbl . Invoke ( ( ) = >
{
if ( string . IsNullOrWhiteSpace ( errMssg ) )
{
Lbl . Text + = "OK" ;
Lbl . ForeColor = Color . LightGreen ;
}
else
{
Lbl . Text + = errMssg ;
Lbl . ForeColor = Color . Red ;
}
} ) ;
}
catch ( Exception ex )
{
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( "Exception in CheckCamModule: " + ex . Message , Level . ERROR ) ;
2025-09-02 15:32:24 +01:00
}
}
// 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 )
{
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( "Shutter, Iris and Gain need selecting in images tab." , Level . WARNING ) ;
2025-09-02 15:32:24 +01:00
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" ) )
{
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( "Problem with selected SIG values" , Level . ERROR ) ;
2025-09-02 15:32:24 +01:00
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" ) )
2025-12-02 12:59:40 +00:00
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 ) ;
2025-09-02 15:32:24 +01:00
}
// 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." )
2025-12-02 12:59:40 +00:00
MainForm . Instance . AddToActionsList ( $"Could not reset camera modules to factory default.{Environment.NewLine}{IRReply}{Environment.NewLine}{OVReply}" , Level . ERROR ) ;
2025-09-02 15:32:24 +01:00
}
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" ;
}
2025-12-02 11:02:24 +00:00
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 ;
}
2025-09-02 15:32:24 +01:00
}
}