Mobile API Refactoring

• Introduced new Mobile API.cs module
• Encapsulates firmware checks, day/night mode switching, and snapshot operations
• Methods: CheckFirmwareAsync(), SetDayModeAsync(), SetNightModeAsync()
• Improves code maintainability and separates API logic from test execution

UI Components
• DayImgPcbx PictureBox: Displays day snapshot
• NightImgPcbx PictureBox: Displays night snapshot
• DayImage Label: Shows day luminance percentage
• NightImage Label: Shows night luminance percentage

Features Implemented
• Luminance-based validation: Uses ImageProcessing.GetMeanLuminance() to quantitatively analyze day and night snapshots
• Validation logic: Day luminance must exceed night luminance to pass the test
• Real-time luminance display: Appends calculated luminance percentages (0-100%) to day and night image labels
• Enhanced error reporting: Logs detailed luminance values when test fails for debugging purposes

• Captures day mode snapshot → Analyzes luminance
• Captures night mode snapshot → Analyzes luminance
• Compares values and updates UI labels with percentages
• Result: "Day/Night Mode = Passed" (green) or "Day/Night Mode = Failed" (red) with error details
This commit is contained in:
2026-01-13 15:31:50 +00:00
parent 4a2e874b9d
commit d1d90f17fc
7 changed files with 308 additions and 162 deletions

View File

@@ -0,0 +1,68 @@
using LibVLCSharp.WinForms;
using System;
using System.Threading.Tasks;
namespace AiQ_GUI.Mobile_Tests
{
public static class MobilePreTest
{
public static async Task RunPreTestAsync()
{
await MobileAPI.CheckFirmwareAsync();// Check firmware version
VLC.Play(MainForm.Instance.VidView);// Test Live Video streaming
await Task.Delay(5000);
VLC.TakeSnapshot(MainForm.Instance.VidView);
if (!VLC.IsPLaying(MainForm.Instance.VidView))// Check Live Video streaming
{
MainForm.Instance.AddToActionsList("Live Video streaming test failed: Video is not playing.", Level.ERROR);
MainForm.Instance.AddLabelToPanel("Live Video = Not Playing", true);
}
else
{
MainForm.Instance.AddLabelToPanel("Live Video = Playing", false);
}
await TestDayNightMode();// Test day/night mode cycling
double dayLuminance = ImageProcessing.GetMeanLuminance(MainForm.Instance.DayImgPcbx.Image); // Calculates the Luminance
double nightLuminance = ImageProcessing.GetMeanLuminance(MainForm.Instance.NightImgPcbx.Image);
MainForm.Instance.DayImage.Text += $" - Luminance: {dayLuminance}%";
MainForm.Instance.NightImage.Text += $" - Luminance: {nightLuminance}%";
if (dayLuminance > nightLuminance)
{
MainForm.Instance.AddLabelToPanel("Day/Night Mode = Passed", false);
}
else
{
MainForm.Instance.AddToActionsList($"Day/Night mode test failed: Day luminance ({dayLuminance}%) is not greater than night luminance ({nightLuminance}%).", Level.ERROR);
MainForm.Instance.AddLabelToPanel("Day/Night Mode = Failed", true);
}
}
private static async Task TestDayNightMode()
{
await MobileAPI.SetDayModeAsync();// Set to Day mode
await Task.Delay(5000);
VLC.TakeSnapshot(MainForm.Instance.VidView, "Mobile_day_snapshot.png");// Take Day Image Snapshot
MainForm.Instance.DayImgPcbx.Image = System.Drawing.Image.FromFile(Path.Combine(LDS.MAVPath, "Mobile_day_snapshot.png"));// Display Day mode snapshot
await MobileAPI.SetNightModeAsync();// Set to Night mode
await Task.Delay(5000);
VLC.TakeSnapshot(MainForm.Instance.VidView, "Mobile_night_snapshot.png");// Take Night Image Snapshot
MainForm.Instance.NightImgPcbx.Image = System.Drawing.Image.FromFile(Path.Combine(LDS.MAVPath, "Mobile_night_snapshot.png"));// Display Night mode snapshot
}
}
}