Now the SQLITE database is operationnal and is fed with driver infos

This commit is contained in:
2023-05-17 15:23:19 +02:00
parent ac65c7b4f3
commit e727dc9301
5 changed files with 230 additions and 71 deletions
+50 -28
View File
@@ -15,35 +15,15 @@ namespace Test_Merge
{
Reader Reader = null;
F1TVEmulator Emulator = null;
private bool cancelRequested = false;
public Form1()
{
InitializeComponent();
}
public async void RefreshUI()
{
if (Emulator != null && Reader != null)
{
btnSettings.Enabled = false;
btnUpdate.Enabled = false;
Stopwatch sw = new Stopwatch();
sw.Start();
Bitmap screen = Emulator.Screenshot();
screen.Save("SCREEEEEEEEN.png");
Reader.ChangeImage(screen);
string result = await Reader.Decode(Reader.MainZones, Reader.Drivers);
sw.Stop();
tbxResult.Text = "";
tbxResult.Text = "Decoding done in :" + sw.ElapsedMilliseconds + "ms"+Environment.NewLine;
tbxResult.Text += result;
pbxResult.Image = screen;
btnSettings.Enabled = true;
btnUpdate.Enabled = true;
}
}
private async void btnSettings_Click(object sender, EventArgs e)
{
@@ -74,13 +54,42 @@ namespace Test_Merge
Reader = new Reader(configFile, Emulator.Screenshot(), true);
}
private void btnUpdate_Click(object sender, EventArgs e)
private async void btnUpdate_Click(object sender, EventArgs e)
{
btnUpdate.Enabled = false;
RefreshUI();
btnUpdate.Enabled = true;
}
cancelRequested = false;
if (Emulator != null && Reader != null)
{
// Disable UI controls to prevent re-entrancy
btnStartDecoding.Enabled = false;
btnStopUpdating.Enabled = true;
btnSettings.Enabled = false;
while (!cancelRequested)
{
// Start the time-consuming task on a separate thread
await Task.Run(async () =>
{
Stopwatch sw = new Stopwatch();
sw.Start();
Bitmap screen = Emulator.Screenshot();
screen.Save("SCREEEEEEEEN.png");
Reader.ChangeImage(screen);
string result = await Reader.Decode(Reader.MainZones, Reader.Drivers);
sw.Stop();
// Task completed
Invoke((MethodInvoker)delegate
{
DisplayResults(result, sw, screen);
});
});
}
// Re-enable UI controls
btnStartDecoding.Enabled = true;
btnStopUpdating.Enabled = false;
btnSettings.Enabled = true;
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (Emulator != null)
@@ -88,5 +97,18 @@ namespace Test_Merge
Emulator.Stop();
}
}
private void DisplayResults(string result,Stopwatch sw,Bitmap screen)
{
tbxResult.Text = "";
tbxResult.Text = "Decoding done in :" + sw.ElapsedMilliseconds + "ms" + Environment.NewLine;
tbxResult.Text += result;
pbxResult.Image = screen;
}
private void btnStopUpdating_Click(object sender, EventArgs e)
{
// Set the cancellation flag
cancelRequested = true;
}
}
}