Exemplo n.º 1
0
        private void flashButton_Click(object sender, EventArgs e)
        {
            if (!InvokeRequired)
            {
                var mcu      = mcuBox.Text;
                var filePath = filepathBox.Text;

                // Keep the form responsive during firmware flashing
                new Thread(() =>
                {
                    if (_usb.AreDevicesAvailable())
                    {
                        var error = 0;
                        if (mcu == "")
                        {
                            _printer.Print("Please select a microcontroller", MessageType.Error);
                            error++;
                        }
                        if (filePath == "")
                        {
                            _printer.Print("Please select a file", MessageType.Error);
                            error++;
                        }
                        if (error == 0)
                        {
                            if (!autoflashCheckbox.Checked)
                            {
                                this.Invoke(new Action(DisableUI));
                            }

                            _printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
                            _flasher.Flash(mcu, filePath);

                            if (!autoflashCheckbox.Checked)
                            {
                                this.Invoke(new Action(EnableUI));
                            }
                        }
                    }
                    else
                    {
                        _printer.Print("There are no devices available", MessageType.Error);
                    }
                }).Start();
            }
            else
            {
                Invoke(new Action <object, EventArgs>(flashButton_Click), sender, e);
            }
        }
Exemplo n.º 2
0
        private void FlashButton_Click(object sender, EventArgs e)
        {
            if (!InvokeRequired)
            {
                var mcu      = (string)mcuBox.SelectedValue;
                var filePath = filepathBox.Text;

                // 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();
            }
            else
            {
                Invoke(new Action <object, EventArgs>(FlashButton_Click), sender, e);
            }
        }
Exemplo n.º 3
0
        private void flashButton_Click(object sender, EventArgs e)
        {
            if (!InvokeRequired)
            {
                flashButton.Enabled = false;
                resetButton.Enabled = false;
                var mcu      = mcuBox.Text;
                var filePath = filepathBox.Text;

                // Keep the form responsive during firmware flashing
                new Thread(() =>
                {
                    if (_usb.AreDevicesAvailable())
                    {
                        var error = 0;
                        if (mcu == "")
                        {
                            _printer.Print("Please select a microcontroller", MessageType.Error);
                            error++;
                        }
                        if (filePath == "")
                        {
                            _printer.Print("Please select a file", MessageType.Error);
                            error++;
                        }
                        if (error == 0)
                        {
                            _printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
                            _flasher.Flash(mcu, filePath);
                        }
                    }
                    else
                    {
                        _printer.Print("There are no devices available", MessageType.Error);
                    }

                    // Re-enable flash/reset button after flashing
                    this.Invoke((MethodInvoker) delegate
                    {
                        flashButton.Enabled = true;
                        resetButton.Enabled = _flasher.CanReset();
                    });
                }).Start();
            }
            else
            {
                Invoke(new Action <object, EventArgs>(flashButton_Click), sender, e);
            }
        }
Exemplo n.º 4
0
        private void flashButton_Click(object sender, EventArgs e)
        {
            if (!InvokeRequired)
            {
                flashButton.Enabled = false;
                resetButton.Enabled = false;

                if (_usb.AreDevicesAvailable())
                {
                    var error = 0;
                    if (mcuBox.Text == "")
                    {
                        _printer.Print("Please select a microcontroller", MessageType.Error);
                        error++;
                    }
                    if (filepathBox.Text == "")
                    {
                        _printer.Print("Please select a file", MessageType.Error);
                        error++;
                    }
                    if (error == 0)
                    {
                        _printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
                        _flasher.Flash(mcuBox.Text, filepathBox.Text);
                    }
                }
                else
                {
                    _printer.Print("There are no devices available", MessageType.Error);
                }

                flashButton.Enabled = true;
                resetButton.Enabled = true;
            }
            else
            {
                Invoke(new Action <object, EventArgs>(flashButton_Click), sender, e);
            }
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            if (Mutex.WaitOne(TimeSpan.Zero, true) && args.Length > 0)
            {
                AttachConsole(AttachParentProcess);

                var printer = new Printing();
                if (args[0].Equals("list"))
                {
                    var flasher = new Flashing(printer);
                    var usb     = new Usb(flasher, printer);
                    flasher.Usb = usb;

                    ManagementObjectCollection collection;
                    using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE ""USB%"""))
                        collection = searcher.Get();

                    usb.DetectBootloaderFromCollection(collection);
                    FreeConsole();
                    Environment.Exit(0);
                }

                if (args[0].Equals("flash"))
                {
                    var flasher = new Flashing(printer);
                    var usb     = new Usb(flasher, printer);
                    flasher.Usb = usb;

                    ManagementObjectCollection collection;
                    using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_PnPEntity WHERE DeviceID LIKE ""USB%"""))
                        collection = searcher.Get();

                    usb.DetectBootloaderFromCollection(collection);

                    if (usb.AreDevicesAvailable())
                    {
                        var mcu      = args[1];
                        var filepath = args[2];
                        printer.Print("Attempting to flash, please don't remove device", MessageType.Bootloader);
                        flasher.Flash(mcu, filepath);
                        FreeConsole();
                        Environment.Exit(0);
                    }
                    else
                    {
                        printer.Print("There are no devices available", MessageType.Error);
                        FreeConsole();
                        Environment.Exit(1);
                    }
                }

                if (args[0].Equals("help"))
                {
                    printer.Print("QMK Toolbox (http://qmk.fm/toolbox)", MessageType.Info);
                    printer.PrintResponse("Supported bootloaders:\n", MessageType.Info);
                    printer.PrintResponse(" - Atmel/LUFA/QMK DFU via dfu-programmer (http://dfu-programmer.github.io/)\n", MessageType.Info);
                    printer.PrintResponse(" - Caterina (Arduino, Pro Micro) via avrdude (http://nongnu.org/avrdude/)\n", MessageType.Info);
                    printer.PrintResponse(" - Halfkay (Teensy, Ergodox EZ) via Teensy Loader (https://pjrc.com/teensy/loader_cli.html)\n", MessageType.Info);
                    printer.PrintResponse(" - ARM DFU (STM32, Kiibohd) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.PrintResponse(" - Atmel SAM-BA (Massdrop) via Massdrop Loader (https://github.com/massdrop/mdloader)\n", MessageType.Info);
                    printer.PrintResponse(" - BootloadHID (Atmel, PS2AVRGB) via bootloadHID (https://www.obdev.at/products/vusb/bootloadhid.html)\n", MessageType.Info);
                    printer.PrintResponse("Supported ISP flashers:\n", MessageType.Info);
                    printer.PrintResponse(" - USBTiny (AVR Pocket)\n", MessageType.Info);
                    printer.PrintResponse(" - AVRISP (Arduino ISP)\n", MessageType.Info);
                    printer.PrintResponse(" - USBasp (AVR ISP)\n", MessageType.Info);
                    printer.PrintResponse("usage: qmk_toolbox.exe <mcu> <filepath>", MessageType.Info);
                    FreeConsole();
                    Environment.Exit(0);
                }

                printer.Print("Command not found - use \"help\" for all commands", MessageType.Error);
                FreeConsole();
                Environment.Exit(1);
            }
            else
            {
                if (Mutex.WaitOne(TimeSpan.Zero, true))
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(args.Length == 0 ? new MainWindow(string.Empty) : new MainWindow(args[0]));
                    Mutex.ReleaseMutex();
                }
                else
                {
                    // send our Win32 message to make the currently running instance
                    // jump on top of all the other windows
                    if (args.Length > 0)
                    {
                        using (var sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox/file_passed_in.txt")))
                        {
                            sw.WriteLine(args[0]);
                        }
                    }
                    NativeMethods.PostMessage(
                        (IntPtr)NativeMethods.HwndBroadcast,
                        NativeMethods.WmShowme,
                        IntPtr.Zero,
                        IntPtr.Zero);
                }
            }
        }
Exemplo n.º 6
0
 public bool CanFlash() => Usb.AreDevicesAvailable();