Esempio n. 1
0
        private void flashButton_Click(object sender, EventArgs e)
        {
            if (!InvokeRequired)
            {
                flashButton.Enabled = false;
                resetButton.Enabled = false;

                if (usb.areDevicesAvailable())
                {
                    int 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
            {
                this.Invoke(new Action <object, EventArgs>(flashButton_Click), new object[] { sender, e });
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (mutex.WaitOne(TimeSpan.Zero, true) && args.Length > 0)
            {
                AttachConsole(ATTACH_PARENT_PROCESS);

                Printing printer = new Printing();
                if (args[0].Equals("list"))
                {
                    Flashing flasher = new Flashing(printer);
                    USB      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"))
                {
                    Flashing flasher = new Flashing(printer);
                    USB      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("Supporting following bootloaders:\n", MessageType.Info);
                    printer.printResponse(" - DFU (Atmel, LUFA) 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_cli (https://pjrc.com/teensy/loader_cli.html)\n", MessageType.Info);
                    printer.printResponse(" - STM32 (ARM) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.printResponse(" - Kiibohd (ARM) via dfu-util (http://dfu-util.sourceforge.net/)\n", MessageType.Info);
                    printer.printResponse("And the following ISP flasher protocols:\n", MessageType.Info);
                    printer.printResponse(" - USBTiny (AVR Pocket)\n", MessageType.Info);
                    printer.printResponse(" - AVRISP (Arduino 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 Form1(string.Empty) : new Form1(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 (StreamWriter sw = new StreamWriter(Path.Combine(Path.GetTempPath(), "qmk_toolbox/file_passed_in.txt"))) {
                            sw.WriteLine(args[0]);
                        }
                    }
                    NativeMethods.PostMessage(
                        (IntPtr)NativeMethods.HWND_BROADCAST,
                        NativeMethods.WM_SHOWME,
                        IntPtr.Zero,
                        IntPtr.Zero);
                }
            }
        }