diff --git a/windows/QMK Toolbox/App.config b/windows/QMK Toolbox/App.config
index b0e8945fd0..1c4afd8cf5 100644
--- a/windows/QMK Toolbox/App.config
+++ b/windows/QMK Toolbox/App.config
@@ -36,6 +36,9 @@
False
+
+ False
+
diff --git a/windows/QMK Toolbox/Flashing.cs b/windows/QMK Toolbox/Flashing.cs
deleted file mode 100644
index b5e985a18e..0000000000
--- a/windows/QMK Toolbox/Flashing.cs
+++ /dev/null
@@ -1,384 +0,0 @@
-using QMK_Toolbox.Helpers;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Threading;
-using System.Windows.Forms;
-
-namespace QMK_Toolbox
-{
- public enum Chipset
- {
- Apm32Dfu,
- AtmelDfu,
- AtmelSamBa,
- AvrIsp,
- BootloadHid,
- Caterina,
- Halfkay,
- Kiibohd,
- LufaMs,
- QmkDfu,
- Stm32Dfu,
- Stm32Duino,
- UsbAsp,
- UsbTiny,
- NumberOfChipsets
- };
-
- public class Flashing : EventArgs
- {
- private readonly Process _process;
- private readonly ProcessStartInfo _startInfo;
-
- public string ComPort = "";
- public string MountPoint = "";
-
- private readonly Printing _printer;
- public Usb Usb;
-
- private readonly string[] _resources = {
- "avrdude.conf",
- "reset.eep",
- "reset_left.eep",
- "reset_right.eep",
- "avrdude.exe",
- "bootloadHID.exe",
- "dfu-programmer.exe",
- "dfu-util.exe",
- "mdloader.exe",
- "teensy_loader_cli.exe",
- "libftdi1.dll",
- "libusb0.dll",
- "libusb-0-1-4.dll",
- "libusb-1.0.dll",
- "libwinpthread-1.dll"
- };
-
- public Flashing(Printing printer)
- {
- _printer = printer;
- EmbeddedResourceHelper.ExtractResources(_resources);
-
- _process = new Process();
- _startInfo = new ProcessStartInfo
- {
- UseShellExecute = false,
- RedirectStandardError = true,
- RedirectStandardOutput = true,
- RedirectStandardInput = true,
- CreateNoWindow = true
- };
- }
-
- private void OnOutputDataReceived(object sender, DataReceivedEventArgs e)
- {
- Debug.Write(e.Data);
- _printer.PrintResponse(e.Data, MessageType.Info);
- }
-
- private void OnErrorDataReceived(object sender, DataReceivedEventArgs e)
- {
- Debug.Write(e.Data);
- _printer.PrintResponse(e.Data, MessageType.Info);
- }
-
- private void ProcessOutput(object streamReader)
- {
- StreamReader _stream = (StreamReader)streamReader;
- string output;
-
- while (!_stream.EndOfStream)
- {
- output = _stream.ReadLine() + "\n";
- _printer.PrintResponse(output, MessageType.Info);
-
- if (output.Contains("Bootloader and code overlap.") || // DFU
- output.Contains("exceeds remaining flash size!") || // BootloadHID
- output.Contains("Not enough bytes in device info report")) // BootloadHID
- {
- _printer.Print("File is too large for device", MessageType.Error);
- }
- }
- }
- private void RunProcess(string command, string args)
- {
- _printer.Print($"{command} {args}", MessageType.Command);
- _startInfo.WorkingDirectory = Application.LocalUserAppDataPath;
- _startInfo.FileName = Path.Combine(Application.LocalUserAppDataPath, command);
- _startInfo.Arguments = args;
- _startInfo.RedirectStandardOutput = true;
- _startInfo.RedirectStandardError = true;
- _startInfo.UseShellExecute = false;
- _process.StartInfo = _startInfo;
-
- _process.Start();
-
- // Thread that handles STDOUT
- Thread _ThreadProcessOutput = new Thread(ProcessOutput);
- _ThreadProcessOutput.Start(_process.StandardOutput);
-
- // Thread that handles STDERR
- _ThreadProcessOutput = new Thread(ProcessOutput);
- _ThreadProcessOutput.Start(_process.StandardError);
-
- _process.WaitForExit();
- }
-
- public void Flash(string mcu, string file)
- {
- if (Usb.CanFlash(Chipset.AtmelDfu) || Usb.CanFlash(Chipset.QmkDfu))
- FlashAtmelDfu(mcu, file);
- if (Usb.CanFlash(Chipset.Caterina))
- FlashCaterina(mcu, file);
- if (Usb.CanFlash(Chipset.Halfkay))
- FlashHalfkay(mcu, file);
- if (Usb.CanFlash(Chipset.Stm32Dfu))
- FlashStm32Dfu(file);
- if (Usb.CanFlash(Chipset.Apm32Dfu))
- FlashApm32Dfu(file);
- if (Usb.CanFlash(Chipset.Kiibohd))
- FlashKiibohd(file);
- if (Usb.CanFlash(Chipset.LufaMs))
- FlashLufaMs(file);
- if (Usb.CanFlash(Chipset.AvrIsp))
- FlashAvrIsp(mcu, file);
- if (Usb.CanFlash(Chipset.UsbAsp))
- FlashUsbAsp(mcu, file);
- if (Usb.CanFlash(Chipset.UsbTiny))
- FlashUsbTiny(mcu, file);
- if (Usb.CanFlash(Chipset.BootloadHid))
- FlashBootloadHid(file);
- if (Usb.CanFlash(Chipset.AtmelSamBa))
- FlashAtmelSamBa(file);
- if (Usb.CanFlash(Chipset.Stm32Duino))
- FlashStm32Duino(file);
- }
-
- public void Reset(string mcu)
- {
- if (Usb.CanFlash(Chipset.AtmelDfu) || Usb.CanFlash(Chipset.QmkDfu))
- ResetAtmelDfu(mcu);
- if (Usb.CanFlash(Chipset.Halfkay))
- ResetHalfkay(mcu);
- if (Usb.CanFlash(Chipset.BootloadHid))
- ResetBootloadHid();
- if (Usb.CanFlash(Chipset.AtmelSamBa))
- ResetAtmelSamBa();
- }
-
- public void ClearEeprom(string mcu)
- {
- if (Usb.CanFlash(Chipset.AtmelDfu) || Usb.CanFlash(Chipset.QmkDfu))
- ClearEepromAtmelDfu(mcu, !Usb.CanFlash(Chipset.QmkDfu));
- if (Usb.CanFlash(Chipset.Caterina))
- ClearEepromCaterina(mcu);
- if (Usb.CanFlash(Chipset.UsbAsp))
- ClearEepromUsbAsp(mcu);
- }
-
- public void SetHandedness(string mcu, bool rightHand)
- {
- if (Usb.CanFlash(Chipset.AtmelDfu) || Usb.CanFlash(Chipset.QmkDfu))
- SetHandednessAtmelDfu(mcu, rightHand, !Usb.CanFlash(Chipset.QmkDfu));
- if (Usb.CanFlash(Chipset.Caterina))
- SetHandednessCaterina(mcu, rightHand);
- if (Usb.CanFlash(Chipset.UsbAsp))
- SetHandednessUsbAsp(mcu, rightHand);
- }
-
- public bool CanFlash() => Usb.AreDevicesAvailable();
-
- public bool CanReset()
- {
- var resettable = new List {
- Chipset.AtmelDfu,
- Chipset.AtmelSamBa,
- Chipset.BootloadHid,
- Chipset.Halfkay,
- Chipset.QmkDfu
- };
- foreach (Chipset chipset in resettable)
- {
- if (Usb.CanFlash(chipset))
- return true;
- }
- return false;
- }
-
- public bool CanClearEeprom()
- {
- var clearable = new List
- {
- Chipset.AtmelDfu,
- Chipset.Caterina,
- Chipset.QmkDfu,
- Chipset.UsbAsp
- };
- foreach (Chipset chipset in clearable)
- {
- if (Usb.CanFlash(chipset))
- return true;
- }
- return false;
- }
-
- private void FlashApm32Dfu(string file)
- {
- if (Path.GetExtension(file)?.ToLower() == ".bin")
- {
- RunProcess("dfu-util.exe", $"-a 0 -d 314B:0106 -s 0x08000000:leave -D \"{file}\"");
- }
- else
- {
- _printer.Print("Only firmware files in .bin format can be flashed with dfu-util!", MessageType.Error);
- }
- }
-
- private void FlashAtmelDfu(string mcu, string file)
- {
- RunProcess("dfu-programmer.exe", $"{mcu} erase --force");
- RunProcess("dfu-programmer.exe", $"{mcu} flash --force \"{file}\"");
- RunProcess("dfu-programmer.exe", $"{mcu} reset");
- }
-
- private void ResetAtmelDfu(string mcu) => RunProcess("dfu-programmer.exe", $"{mcu} reset");
-
- private void ClearEepromAtmelDfu(string mcu, bool erase)
- {
- if (erase)
- {
- RunProcess("dfu-programmer.exe", $"{mcu} erase --force");
- }
- RunProcess("dfu-programmer.exe", $"{mcu} flash --force --suppress-validation --eeprom reset.eep");
- if (erase)
- {
- _printer.Print("Please reflash device with firmware now", MessageType.Bootloader);
- }
- }
-
- private void SetHandednessAtmelDfu(string mcu, bool rightHand, bool erase)
- {
- if (erase)
- {
- RunProcess("dfu-programmer.exe", $"{mcu} erase --force");
- }
- RunProcess("dfu-programmer.exe", $"{mcu} flash --force --suppress-validation --eeprom reset_{(rightHand ? "right" : "left")}.eep");
- if (erase)
- {
- _printer.Print("Please reflash device with firmware now", MessageType.Bootloader);
- }
- }
-
- private void FlashAtmelSamBa(string file) => RunProcess("mdloader.exe", $"-p {ComPort} -D \"{file}\" --restart");
-
- private void ResetAtmelSamBa() => RunProcess("mdloader.exe", $"-p {ComPort} --restart");
-
- private void FlashAvrIsp(string mcu, string file)
- {
- RunProcess("avrdude.exe", $"-p {mcu} -c avrisp -U flash:w:\"{file}\":i -P {ComPort}");
- _printer.Print("Flash complete", MessageType.Bootloader);
- }
-
- private void FlashBootloadHid(string file) => RunProcess("bootloadHID.exe", $"-r \"{file}\"");
-
- private void ResetBootloadHid() => RunProcess("bootloadHID.exe", $"-r");
-
- private void FlashCaterina(string mcu, string file) => RunProcess("avrdude.exe", $"-p {mcu} -c avr109 -U flash:w:\"{file}\":i -P {ComPort}");
-
- private void ClearEepromCaterina(string mcu) => RunProcess("avrdude.exe", $"-p {mcu} -c avr109 -U eeprom:w:reset.eep:i -P {ComPort}");
-
- private void SetHandednessCaterina(string mcu, bool rightHand) => RunProcess("avrdude.exe", $"-p {mcu} -c avr109 -U eeprom:w:reset_{(rightHand ? "right" : "left")}.eep:i -P {ComPort}");
-
- private void FlashHalfkay(string mcu, string file) => RunProcess("teensy_loader_cli.exe", $"-mmcu={mcu} \"{file}\" -v");
-
- private void ResetHalfkay(string mcu) => RunProcess("teensy_loader_cli.exe", $"-mmcu={mcu} -bv");
-
- private void FlashKiibohd(string file)
- {
- if (Path.GetExtension(file)?.ToLower() == ".bin")
- {
- RunProcess("dfu-util.exe", $"-D \"{file}\"");
- }
- else
- {
- _printer.Print("Only firmware files in .bin format can be flashed with dfu-util!", MessageType.Error);
- }
- }
-
- private void FlashLufaMs(string file)
- {
- if (MountPoint != null)
- {
- if (Path.GetExtension(file)?.ToLower() == ".bin")
- {
- var destFile = $"{MountPoint}\\FLASH.BIN";
-
- try
- {
- _printer.Print($"Deleting {destFile}...", MessageType.Command);
- File.Delete(destFile);
-
- _printer.Print($"Copying {file} to {destFile}...", MessageType.Command);
- File.Copy(file, destFile);
-
- _printer.Print("Done, please eject drive now.", MessageType.Info);
- }
- catch (IOException e)
- {
- _printer.Print($"IO ERROR: {e.Message}", MessageType.Error);
- }
- }
- else
- {
- _printer.Print("Only firmware files in .bin format can be flashed with this bootloader!", MessageType.Error);
- }
- }
- else
- {
- _printer.Print("Could not find drive letter for device!", MessageType.Error);
- }
- }
-
- private void FlashStm32Dfu(string file)
- {
- if (Path.GetExtension(file)?.ToLower() == ".bin")
- {
- RunProcess("dfu-util.exe", $"-a 0 -d 0483:DF11 -s 0x08000000:leave -D \"{file}\"");
- }
- else
- {
- _printer.Print("Only firmware files in .bin format can be flashed with dfu-util!", MessageType.Error);
- }
- }
-
- private void FlashStm32Duino(string file)
- {
- if (Path.GetExtension(file)?.ToLower() == ".bin")
- {
- RunProcess("dfu-util.exe", $"-a 2 -d 1EAF:0003 -R -D \"{file}\"");
- }
- else
- {
- _printer.Print("Only firmware files in .bin format can be flashed with dfu-util!", MessageType.Error);
- }
- }
-
- private void FlashUsbAsp(string mcu, string file)
- {
- RunProcess("avrdude.exe", $"-p {mcu} -c usbasp -U flash:w:\"{file}\":i");
- _printer.Print("Flash complete", MessageType.Bootloader);
- }
-
- private void ClearEepromUsbAsp(string mcu) => RunProcess("avrdude.exe", $"-p {mcu} -c usbasp -U eeprom:w:reset.eep:i");
-
- private void SetHandednessUsbAsp(string mcu, bool rightHand) => RunProcess("avrdude.exe", $"-p {mcu} -c usbasp -U eeprom:w:reset_{(rightHand ? "right" : "left")}.eep:i");
-
- private void FlashUsbTiny(string mcu, string file)
- {
- RunProcess("avrdude.exe", $"-p {mcu} -c usbtiny -U flash:w:\"{file}\":i");
- _printer.Print("Flash complete", MessageType.Bootloader);
- }
- }
-}
diff --git a/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs b/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs
index 16c107b2e5..482a4f12bd 100644
--- a/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs
+++ b/windows/QMK Toolbox/Helpers/EmbeddedResourceHelper.cs
@@ -7,12 +7,38 @@ namespace QMK_Toolbox.Helpers
{
public static class EmbeddedResourceHelper
{
+ public static readonly string[] Resources =
+ {
+ "avrdude.conf",
+ "reset.eep",
+ "reset_left.eep",
+ "reset_right.eep",
+ "avrdude.exe",
+ "bootloadHID.exe",
+ "dfu-programmer.exe",
+ "dfu-util.exe",
+ "mdloader.exe",
+ "teensy_loader_cli.exe",
+ "libftdi1.dll",
+ "libusb0.dll",
+ "libusb-0-1-4.dll",
+ "libusb-1.0.dll",
+ "libwinpthread-1.dll"
+ };
+
public static void ExtractResource(string file)
{
- using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}"))
- using (var filestream = new FileStream(Path.Combine(Application.LocalUserAppDataPath, file), FileMode.Create))
+ var destPath = Path.Combine(Application.LocalUserAppDataPath, file);
+
+ if (!File.Exists(destPath))
{
- stream?.CopyTo(filestream);
+ using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"QMK_Toolbox.Resources.{file}"))
+ {
+ using (var filestream = new FileStream(destPath, FileMode.Create))
+ {
+ stream?.CopyTo(filestream);
+ }
+ }
}
}
diff --git a/windows/QMK Toolbox/MainWindow.Designer.cs b/windows/QMK Toolbox/MainWindow.Designer.cs
index 86a879ae8a..362f7ede66 100644
--- a/windows/QMK Toolbox/MainWindow.Designer.cs
+++ b/windows/QMK Toolbox/MainWindow.Designer.cs
@@ -61,6 +61,7 @@ private void InitializeComponent() {
this.exitDFUToolStripMenuItem = new QMK_Toolbox.BindableToolStripMenuItem();
this.toolsToolStripMenuSep1 = new System.Windows.Forms.ToolStripSeparator();
this.autoFlashToolStripMenuItem = new QMK_Toolbox.BindableToolStripMenuItem();
+ this.showAllDevicesToolStripMenuItem = new QMK_Toolbox.BindableToolStripMenuItem();
this.toolsToolStripMenuSep2 = new System.Windows.Forms.ToolStripSeparator();
this.keyTesterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.installDriversToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@@ -349,6 +350,7 @@ private void InitializeComponent() {
this.exitDFUToolStripMenuItem,
this.toolsToolStripMenuSep1,
this.autoFlashToolStripMenuItem,
+ this.showAllDevicesToolStripMenuItem,
this.toolsToolStripMenuSep2,
this.keyTesterToolStripMenuItem,
this.installDriversToolStripMenuItem,
@@ -440,6 +442,14 @@ private void InitializeComponent() {
this.autoFlashToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
this.autoFlashToolStripMenuItem.Text = "Auto-Flash";
//
+ // showAllDevicesToolStripMenuItem
+ //
+ this.showAllDevicesToolStripMenuItem.CheckOnClick = true;
+ this.showAllDevicesToolStripMenuItem.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.windowStateBindingSource, "ShowAllDevices", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
+ this.showAllDevicesToolStripMenuItem.Name = "showAllDevicesToolStripMenuItem";
+ this.showAllDevicesToolStripMenuItem.Size = new System.Drawing.Size(196, 22);
+ this.showAllDevicesToolStripMenuItem.Text = "Show All Devices";
+ //
// toolsToolStripMenuSep2
//
this.toolsToolStripMenuSep2.Name = "toolsToolStripMenuSep2";
@@ -584,5 +594,6 @@ private void InitializeComponent() {
private System.Windows.Forms.ToolStripSeparator eepromToolStripMenuSep;
private System.Windows.Forms.ToolStripMenuItem keyTesterToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolsToolStripMenuSep3;
+ private QMK_Toolbox.BindableToolStripMenuItem showAllDevicesToolStripMenuItem;
}
}
diff --git a/windows/QMK Toolbox/MainWindow.cs b/windows/QMK Toolbox/MainWindow.cs
index bb681939f0..6db587e9c4 100644
--- a/windows/QMK Toolbox/MainWindow.cs
+++ b/windows/QMK Toolbox/MainWindow.cs
@@ -2,13 +2,14 @@
using QMK_Toolbox.HidConsole;
using QMK_Toolbox.KeyTester;
using QMK_Toolbox.Properties;
+using QMK_Toolbox.Usb;
+using QMK_Toolbox.Usb.Bootloader;
using System;
using System.ComponentModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Permissions;
-using System.Threading;
using System.Windows.Forms;
namespace QMK_Toolbox
@@ -16,7 +17,7 @@ namespace QMK_Toolbox
using Newtonsoft.Json;
using Syroot.Windows.IO;
using System.Collections;
- using System.Management;
+ using System.Collections.Generic;
using System.Net;
public partial class MainWindow : Form
@@ -25,8 +26,6 @@ public partial class MainWindow : Form
private readonly Printing _printer;
- private readonly Flashing _flasher;
-
private readonly string _filePassedIn = string.Empty;
#region Window Events
@@ -51,17 +50,14 @@ public MainWindow(string path) : this()
}
_printer = new Printing(logTextBox);
- _flasher = new Flashing(_printer);
- _usb = new Usb(_flasher, _printer);
- _flasher.Usb = _usb;
-
- _usb.StartListeningForDeviceEvents(DeviceEvent);
}
private void MainWindow_Load(object sender, EventArgs e)
{
windowStateBindingSource.DataSource = windowState;
windowState.PropertyChanged += AutoFlashEnabledChanged;
+ windowState.PropertyChanged += ShowAllDevicesEnabledChanged;
+ windowState.ShowAllDevices = Settings.Default.showAllDevices;
if (Settings.Default.hexFileCollection != null)
{
@@ -70,6 +66,8 @@ private void MainWindow_Load(object sender, EventArgs e)
mcuBox.SelectedValue = Settings.Default.targetSetting;
+ EmbeddedResourceHelper.ExtractResources(EmbeddedResourceHelper.Resources);
+
_printer.Print($"QMK Toolbox {Application.ProductVersion} (https://qmk.fm/toolbox)", MessageType.Info);
_printer.PrintResponse("Supported bootloaders:\n", MessageType.Info);
_printer.PrintResponse(" - ARM DFU (APM32, Kiibohd, STM32, STM32duino) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
@@ -84,14 +82,12 @@ private void MainWindow_Load(object sender, EventArgs e)
_printer.PrintResponse(" - USBasp (AVR ISP)\n", MessageType.Info);
_printer.PrintResponse(" - USBTiny (AVR Pocket)\n", MessageType.Info);
- ManagementObjectCollection collection;
- using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE 'USB%'"))
- {
- collection = searcher.Get();
- }
-
- _usb.DetectBootloaderFromCollection(collection);
- EnableUI();
+ usbListener.usbDeviceConnected += UsbDeviceConnected;
+ usbListener.usbDeviceDisconnected += UsbDeviceDisconnected;
+ usbListener.bootloaderDeviceConnected += BootloaderDeviceConnected;
+ usbListener.bootloaderDeviceDisconnected += BootloaderDeviceDisconnected;
+ usbListener.outputReceived += BootloaderCommandOutputReceived;
+ usbListener.Start();
consoleListener.consoleDeviceConnected += ConsoleDeviceConnected;
consoleListener.consoleDeviceDisconnected += ConsoleDeviceDisconnected;
@@ -102,6 +98,8 @@ private void MainWindow_Load(object sender, EventArgs e)
{
SetFilePath(_filePassedIn);
}
+
+ EnableUI();
}
private void MainWindow_Shown(object sender, EventArgs e)
@@ -175,7 +173,7 @@ private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
Settings.Default.targetSetting = (string)mcuBox.SelectedValue;
Settings.Default.Save();
- _usb.StopListeningForDeviceEvents();
+ usbListener.Dispose();
consoleListener.Dispose();
}
@@ -254,33 +252,40 @@ private void UpdateConsoleList()
#endregion HID Console
#region USB Devices & Bootloaders
- private readonly Usb _usb;
+ private readonly UsbListener usbListener = new UsbListener();
- private void DeviceEvent(object sender, EventArrivedEventArgs e)
+ private void BootloaderDeviceConnected(BootloaderDevice device)
{
- (sender as ManagementEventWatcher)?.Stop();
+ _printer.Print($"{device.Name} device connected ({device.Driver}): {device}", MessageType.Bootloader);
- if (!(e.NewEvent["TargetInstance"] is ManagementBaseObject instance))
- {
- return;
- }
+ Invoke(new Action(EnableUI));
+ }
- var deviceDisconnected = e.NewEvent.ClassPath.ClassName.Equals("__InstanceDeletionEvent");
+ private void BootloaderDeviceDisconnected(BootloaderDevice device)
+ {
+ _printer.Print($"{device.Name} device disconnected ({device.Driver}): {device}", MessageType.Bootloader);
- if (deviceDisconnected)
- {
- _usb.DetectBootloader(instance, false);
- }
- else if (_usb.DetectBootloader(instance) && windowState.AutoFlashEnabled)
+ Invoke(new Action(EnableUI));
+ }
+
+ private void BootloaderCommandOutputReceived(BootloaderDevice device, string data, MessageType type)
+ {
+ _printer.PrintResponse($"{data}\n", type);
+ }
+
+ private void UsbDeviceConnected(UsbDevice device)
+ {
+ if (windowState.ShowAllDevices)
{
- FlashButton_Click(sender, e);
+ _printer.Print($"USB device connected ({device.Driver}): {device}", MessageType.Info);
}
+ }
- (sender as ManagementEventWatcher)?.Start();
-
- if (!windowState.AutoFlashEnabled)
+ private void UsbDeviceDisconnected(UsbDevice device)
+ {
+ if (windowState.ShowAllDevices)
{
- Invoke(new Action(EnableUI));
+ _printer.Print($"USB device disconnected ({device.Driver}): {device}", MessageType.Info);
}
}
#endregion
@@ -303,167 +308,122 @@ private void AutoFlashEnabledChanged(object sender, PropertyChangedEventArgs e)
}
}
- private void FlashButton_Click(object sender, EventArgs e)
+ private void ShowAllDevicesEnabledChanged(object sender, PropertyChangedEventArgs e)
{
- if (!InvokeRequired)
+ if (e.PropertyName == "ShowAllDevices")
+ {
+ Settings.Default.showAllDevices = windowState.ShowAllDevices;
+ }
+ }
+
+ private async void FlashButton_Click(object sender, EventArgs e)
+ {
+ string selectedMcu = (string)mcuBox.SelectedValue;
+ string filePath = filepathBox.Text;
+
+ if (filePath.Length == 0)
{
- var mcu = (string)mcuBox.SelectedValue;
- var filePath = filepathBox.Text;
+ _printer.Print("Please select a file", MessageType.Error);
+ return;
+ }
- // Keep the form responsive during firmware flashing
- new Thread(() =>
- {
- if (_usb.AreDevicesAvailable())
- {
- if (mcu.Length > 0)
- {
- if (filePath.Length > 0)
- {
- if (!windowState.AutoFlashEnabled)
- {
- Invoke(new Action(DisableUI));
- }
-
- _printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
- _flasher.Flash(mcu, filePath);
-
- if (!windowState.AutoFlashEnabled)
- {
- Invoke(new Action(EnableUI));
- }
- }
- else
- {
- _printer.Print("Please select a file", MessageType.Error);
- }
- }
- else
- {
- _printer.Print("Please select a microcontroller", MessageType.Error);
- }
- }
- else
- {
- _printer.Print("There are no devices available", MessageType.Error);
- }
- }).Start();
+ if (!windowState.AutoFlashEnabled)
+ {
+ Invoke(new Action(DisableUI));
}
- else
+
+ foreach (BootloaderDevice b in FindBootloaders())
{
- Invoke(new Action