Now the SQLITE database is operationnal and is fed with driver infos
This commit is contained in:
+50
-28
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user