コード例 #1
0
ファイル: Flashing.cs プロジェクト: umrjmac/qmk_toolbox
        private string 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;
            _process.StartInfo          = _startInfo;
            var output = "";

            _process.Start();
            while (!_process.HasExited)
            {
                var buffer = new char[4096];
                while (_process.StandardOutput.Peek() > -1 || _process.StandardError.Peek() > -1)
                {
                    if (_process.StandardOutput.Peek() > -1)
                    {
                        var length = _process.StandardOutput.Read(buffer, 0, buffer.Length);
                        var data   = new string(buffer, 0, length);
                        output += data;
                        _printer.PrintResponse(data, MessageType.Info);
                    }
                    if (_process.StandardError.Peek() > -1)
                    {
                        var length = _process.StandardError.Read(buffer, 0, buffer.Length);
                        var data   = new string(buffer, 0, length);
                        output += data;
                        _printer.PrintResponse(data, MessageType.Info);
                    }
                    Application.DoEvents(); // This keeps your form responsive by processing events
                }
            }
            return(output);
        }
コード例 #2
0
ファイル: Flashing.cs プロジェクト: wjchen-vlsi/qmk_toolbox
        public Flashing(Printing printer)
        {
            _printer = printer;
            EmbeddedResourceHelper.ExtractResources(_resources);

            var query = new System.Management.SelectQuery("Win32_SystemDriver")
            {
                Condition = "Name = 'libusb0'"
            };
            var searcher = new System.Management.ManagementObjectSearcher(query);
            var drivers  = searcher.Get();

            if (drivers.Count > 0)
            {
                printer.Print("libusb0 driver found on system", MessageType.Info);
            }
            else
            {
                printer.Print("libusb0 driver not found - attempting to install", MessageType.Info);

                if (Directory.Exists(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2")))
                {
                    Directory.Delete(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2"), true);
                }
                ZipFile.ExtractToDirectory(Path.Combine(Application.LocalUserAppDataPath, "dfu-prog-usb-1.2.2.zip"), Application.LocalUserAppDataPath);

                var size    = 0;
                var success = Program.SetupCopyOEMInf(Path.Combine(Application.LocalUserAppDataPath,
                                                                   "dfu-prog-usb-1.2.2",
                                                                   "atmel_usb_dfu.inf"),
                                                      "",
                                                      Program.OemSourceMediaType.SpostNone,
                                                      Program.OemCopyStyle.SpCopyNewer,
                                                      null,
                                                      0,
                                                      ref size,
                                                      null);
                if (!success)
                {
                    var errorCode   = Marshal.GetLastWin32Error();
                    var errorString = new Win32Exception(errorCode).Message;
                    printer.Print("Error: " + errorString, MessageType.Error);
                }
            }

            _process = new Process();
            //process.EnableRaisingEvents = true;
            //process.OutputDataReceived += OnOutputDataReceived;
            //process.ErrorDataReceived += OnErrorDataReceived;
            _startInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                CreateNoWindow         = true
            };
        }
コード例 #3
0
ファイル: Flashing.cs プロジェクト: michalgr/qmk_toolbox
        private void ProcessOutput(Object streamReader)
        {
            StreamReader _stream = (StreamReader)streamReader;
            var          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);
                }
            }
        }
コード例 #4
0
ファイル: USB.cs プロジェクト: fauxpark/qmk_toolbox
        public bool DetectBootloader(ManagementBaseObject instance, bool connected = true)
        {
            var deviceId = GetHardwareId(instance);

            var vpr = DeviceIdRegex.Match(deviceId);

            if (vpr.Success)
            {
                var vendorId    = Convert.ToUInt16(vpr.Groups[1].ToString(), 16);
                var productId   = Convert.ToUInt16(vpr.Groups[2].ToString(), 16);
                var revisionBcd = Convert.ToUInt16(vpr.Groups[3].ToString(), 16);

                string  deviceName;
                string  comPort    = null;
                string  mountPoint = null;
                string  driverName = GetDriverName(instance);
                Chipset deviceType;

                if (IsSerialDevice(instance))
                {
                    if (vendorId == 0x03EB && productId == 0x6124) // Atmel SAM-BA
                    {
                        deviceName = "Atmel SAM-BA";
                        deviceType = Chipset.AtmelSamBa;
                    }
                    else if (caterinaVids.Contains(vendorId) && caterinaPids.Contains(productId)) // Caterina
                    {
                        deviceName = "Caterina";
                        deviceType = Chipset.Caterina;
                    }
                    else if (vendorId == 0x16C0 && productId == 0x0483) // ArduinoISP/AVRISP
                    {
                        deviceName = "AVRISP";
                        deviceType = Chipset.AvrIsp;
                    }
                    else
                    {
                        return(false);
                    }

                    comPort          = GetComPort(instance);
                    _flasher.ComPort = comPort;
                }
                else if (vendorId == 0x03EB)
                {
                    if (atmelDfuPids.Contains(productId))
                    {
                        if (revisionBcd == 0x0936) // QMK-DFU
                        {
                            deviceName = "QMK DFU";
                            deviceType = Chipset.QmkDfu;
                        }
                        else // Atmel DFU
                        {
                            deviceName = "Atmel DFU";
                            deviceType = Chipset.AtmelDfu;
                        }
                    }
                    else if (productId == 0x2045) // LUFA MS
                    {
                        deviceName          = "LUFA Mass Storage";
                        deviceType          = Chipset.LufaMs;
                        mountPoint          = GetMountPoint(instance);
                        _flasher.MountPoint = mountPoint;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (vendorId == 0x16C0 && productId == 0x0478) // PJRC Teensy
                {
                    deviceName = "Halfkay";
                    deviceType = Chipset.Halfkay;
                }
                else if (vendorId == 0x0483 && productId == 0xDF11) // STM32 DFU
                {
                    deviceName = "STM32 DFU";
                    deviceType = Chipset.Stm32Dfu;
                }
                else if (vendorId == 0x314B && productId == 0x0106) // APM32 DFU
                {
                    deviceName = "APM32 DFU";
                    deviceType = Chipset.Apm32Dfu;
                }
                else if (vendorId == 0x1C11 && productId == 0xB007) // Kiibohd
                {
                    deviceName = "Kiibohd";
                    deviceType = Chipset.Kiibohd;
                }
                else if (vendorId == 0x16C0 && productId == 0x05DF) // Objective Development BootloadHID
                {
                    deviceName = "BootloadHID";
                    deviceType = Chipset.BootloadHid;
                }
                else if (vendorId == 0x16C0 && productId == 0x05DC) // USBasp and USBaspLoader
                {
                    deviceName = "USBasp";
                    deviceType = Chipset.UsbAsp;
                }
                else if (vendorId == 0x1781 && productId == 0x0C9F) // AVR Pocket ISP
                {
                    deviceName = "USB Tiny";
                    deviceType = Chipset.UsbTiny;
                }
                else if (vendorId == 0x1EAF && productId == 0x0003) // STM32Duino
                {
                    deviceName = "STM32Duino";
                    deviceType = Chipset.Stm32Duino;
                }
                else
                {
                    return(false);
                }

                var connectedString  = connected ? "connected" : "disconnected";
                var comPortString    = comPort != null ? $" [{comPort}]" : "";
                var mountPointString = mountPoint != null ? $" [{mountPoint}]" : "";
                var driverString     = driverName ?? "NO DRIVER";

                _printer.Print($"{deviceName} device {connectedString} ({driverString}): {instance.GetPropertyValue("Manufacturer")} {instance.GetPropertyValue("Name")} ({vendorId:X4}:{productId:X4}:{revisionBcd:X4}){comPortString}{mountPointString}", MessageType.Bootloader);

                _devicesAvailable[(int)deviceType] += (connected ? 1 : -1);

                return(true);
            }

            return(false);
        }
コード例 #5
0
        public bool DetectBootloader(ManagementBaseObject instance, bool connected = true)
        {
            var hardwareIds = (System.String[])instance.GetPropertyValue("HardwareID");
            var deviceId    = hardwareIds[0];

            var deviceidRegex = new Regex(@"VID_([0-9A-F]+).*PID_([0-9A-F]+).*REV_([0-9A-F]+)");
            var vp            = deviceidRegex.Match(deviceId);
            var vid           = vp.Groups[1].ToString().PadLeft(4, '0');
            var pid           = vp.Groups[2].ToString().PadLeft(4, '0');
            var rev           = vp.Groups[3].ToString().PadLeft(4, '0');

            string deviceName;

            if (MatchVid(deviceId, 0x03EB) && MatchPid(deviceId, 0x6124)) // Detects Atmel SAM-BA VID & PID
            {
                deviceName            = "Atmel SAM-BA";
                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.AtmelSamBa] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x03EB)) // Detects Atmel Vendor ID for other Atmel devices
            {
                deviceName = "DFU";
                _devicesAvailable[(int)Chipset.Dfu] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x2341) || MatchVid(deviceId, 0x1B4F) || MatchVid(deviceId, 0x239A)) // Detects Arduino Vendor ID, Sparkfun Vendor ID, Adafruit Vendor ID
            {
                deviceName            = "Caterina";
                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.Caterina] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x0478)) // Detects PJRC VID & PID
            {
                deviceName = "Halfkay";
                _devicesAvailable[(int)Chipset.Halfkay] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x0483) && MatchPid(deviceId, 0xDF11)) // Detects STM32 PID & VID
            {
                deviceName = "STM32";
                _devicesAvailable[(int)Chipset.Stm32] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x1C11) && MatchPid(deviceId, 0xB007)) // Detects Kiibohd VID & PID
            {
                deviceName = "Kiibohd";
                _devicesAvailable[(int)Chipset.Kiibohd] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x0483)) // Detects Arduino ISP VID & PID
            {
                deviceName            = "AVRISP";
                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.AvrIsp] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x05DC)) // Detects AVR USBAsp VID & PID
            {
                deviceName            = "USBAsp";
                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.UsbAsp] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x1781) && MatchPid(deviceId, 0x0C9F)) // Detects AVR Pocket ISP VID & PID
            {
                deviceName = "USB Tiny";

                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.UsbTiny] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x05DF)) // Detects Objective Development VID & PID
            {
                deviceName = "BootloadHID";
                _devicesAvailable[(int)Chipset.BootloadHid] += connected ? 1 : -1;
            }
            else
            {
                return(false);
            }

            var connectedString = connected ? "connected" : "disconnected";

            _printer.Print($"{deviceName} device {connectedString}: {instance.GetPropertyValue("Manufacturer")} {instance.GetPropertyValue("Name")} ({vid}:{pid}:{rev})", MessageType.Bootloader);
            return(true);
        }
コード例 #6
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            ServicePointManager.SecurityProtocol =
                SecurityProtocolType.Tls |
                SecurityProtocolType.Tls11 |
                SecurityProtocolType.Tls12;

            var menuHandle = GetSystemMenu(Handle, false);

            InsertMenu(menuHandle, 0, MfByposition | MfSeparator, 0, string.Empty); // <-- Add a menu seperator
            InsertMenu(menuHandle, 0, MfByposition, About, "About");

            //_backgroundWorker.RunWorkerAsync();

            foreach (var mcu in _flasher.GetMcuList())
            {
                mcuBox.Items.Add(mcu);
            }
            if (mcuBox.SelectedIndex == -1)
            {
                mcuBox.SelectedIndex = 0;
            }

            if (Settings.Default.hexFileCollection != null)
            {
                filepathBox.Items.AddRange(Settings.Default.hexFileCollection.ToArray());
            }

            logTextBox.Font = new Font(FontFamily.GenericMonospace, 8);

            _printer.Print("QMK Toolbox (https://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(" - BootloadHID (Atmel, ps2avrGB, CA66) via bootloadHID (https://www.obdev.at/products/vusb/bootloadhid.html)\n", MessageType.Info);
            _printer.PrintResponse(" - Atmel SAM-BA via mdloader (https://github.com/patrickmt/mdloader)\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);

            var devices = new List <UsbDeviceInfo>();

            ManagementObjectCollection collection;

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

            _usb.DetectBootloaderFromCollection(collection);

            UpdateHidDevices(false);
            UpdateHidList();

            if (_filePassedIn != string.Empty)
            {
                SetFilePath(_filePassedIn);
            }

            LoadKeyboardList();
            LoadKeymapList();
        }
コード例 #7
0
        public bool DetectBootloader(ManagementBaseObject instance, bool connected = true)
        {
            var deviceId = GetHardwareId(instance);

            var vpr = DeviceIdRegex.Match(deviceId);
            var vid = vpr.Groups[1].ToString().PadLeft(4, '0');
            var pid = vpr.Groups[2].ToString().PadLeft(4, '0');
            var rev = vpr.Groups[3].ToString().PadLeft(4, '0');

            string deviceName;
            string comPort    = null;
            string driverName = GetDriverName(instance);

            if (IsSerialDevice(instance))
            {
                comPort = GetComPort(instance);

                if (MatchVidPid(deviceId, 0x03EB, 0x6124)) // Atmel SAM-BA
                {
                    deviceName       = "Atmel SAM-BA";
                    _flasher.ComPort = comPort;
                    _devicesAvailable[(int)Chipset.AtmelSamBa] += connected ? 1 : -1;
                }
                else if (caterinaVids.Contains(vid) && caterinaPids.Contains(pid)) // Caterina
                {
                    deviceName       = "Caterina";
                    _flasher.ComPort = comPort;
                    _devicesAvailable[(int)Chipset.Caterina] += connected ? 1 : -1;
                }
                else if (MatchVidPid(deviceId, 0x16C0, 0x0483)) // ArduinoISP/AVRISP
                {
                    deviceName       = "AVRISP";
                    _flasher.ComPort = comPort;
                    _devicesAvailable[(int)Chipset.AvrIsp] += connected ? 1 : -1;
                }
                else
                {
                    return(false);
                }
            }
            else if (MatchVid(deviceId, 0x03EB) && atmelDfuPids.Contains(pid)) // Atmel DFU
            {
                deviceName = "Atmel DFU";
                _devicesAvailable[(int)Chipset.AtmelDfu] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x16C0, 0x0478)) // PJRC Teensy
            {
                deviceName = "Halfkay";
                _devicesAvailable[(int)Chipset.Halfkay] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x0483, 0xDF11)) // STM32 DFU
            {
                deviceName = "STM32 DFU";
                _devicesAvailable[(int)Chipset.Stm32Dfu] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x314B, 0x0106)) // APM32 DFU
            {
                deviceName = "APM32 DFU";
                _devicesAvailable[(int)Chipset.Apm32Dfu] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x1C11, 0xB007)) // Kiibohd
            {
                deviceName = "Kiibohd";
                _devicesAvailable[(int)Chipset.Kiibohd] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x16C0, 0x05DF)) // Objective Development BootloadHID
            {
                deviceName = "BootloadHID";
                _devicesAvailable[(int)Chipset.BootloadHid] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x16C0, 0x05DC)) // USBAsp and USBAspLoader
            {
                deviceName = "USBAsp";
                _devicesAvailable[(int)Chipset.UsbAsp] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x1781, 0x0C9F)) // AVR Pocket ISP
            {
                deviceName = "USB Tiny";
                _devicesAvailable[(int)Chipset.UsbTiny] += connected ? 1 : -1;
            }
            else if (MatchVidPid(deviceId, 0x1EAF, 0x0003)) // Detects STM32duino Bootloader
            {
                deviceName = "STM32duino";
                _devicesAvailable[(int)Chipset.Stm32Duino] += connected ? 1 : -1;
            }
            else
            {
                return(false);
            }

            var connectedString = connected ? "connected" : "disconnected";
            var comPortString   = comPort != null ? $" [{comPort}]" : "";
            var driverString    = driverName ?? "NO DRIVER";

            _printer.Print($"{deviceName} device {connectedString} ({driverString}): {instance.GetPropertyValue("Manufacturer")} {instance.GetPropertyValue("Name")} ({vid}:{pid}:{rev}){comPortString}", MessageType.Bootloader);

            return(true);
        }
コード例 #8
0
ファイル: MainWindow.cs プロジェクト: jsmccid/qmk_toolbox
        private void MainWindow_Load(object sender, EventArgs e)
        {
            ServicePointManager.SecurityProtocol =
                SecurityProtocolType.Tls |
                SecurityProtocolType.Tls11 |
                SecurityProtocolType.Tls12;

            var menuHandle = GetSystemMenu(Handle, false);

            InsertMenu(menuHandle, 0, MfByposition | MfSeparator, 0, string.Empty); // <-- Add a menu seperator
            InsertMenu(menuHandle, 0, MfByposition, About, "About");

            //_backgroundWorker.RunWorkerAsync();

            foreach (var mcu in _flasher.GetMcuList())
            {
                mcuBox.Items.Add(mcu);
            }

            if (Settings.Default.hexFileCollection != null)
            {
                filepathBox.Items.AddRange(Settings.Default.hexFileCollection.ToArray());
            }

            _printer.Print($"QMK Toolbox {Application.ProductVersion} (https://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, APM32, Kiibohd, STM32duino) 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);

            ManagementObjectCollection collection;

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

            _usb.DetectBootloaderFromCollection(collection);
            EnableUI();

            UpdateHidDevices(false);

            if (_filePassedIn != string.Empty)
            {
                SetFilePath(_filePassedIn);
            }

            LoadKeyboardList();
        }
コード例 #9
0
ファイル: MainWindow.cs プロジェクト: tzarc/qmk_toolbox
        private void AutoFlashEnabledChanged(object sender, EventArgs e)
        {
            PropertyChangedEventArgs args = (PropertyChangedEventArgs)e;

            if (args.PropertyName == "AutoFlashEnabled")
            {
                if (windowState.AutoFlashEnabled)
                {
                    _printer.Print("Auto-flash enabled", MessageType.Info);
                    DisableUI();
                }
                else
                {
                    _printer.Print("Auto-flash disabled", MessageType.Info);
                    EnableUI();
                }
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: zjcymk/qmk_toolbox
        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);
                }
            }
        }
コード例 #11
0
ファイル: MainWindow.cs プロジェクト: fauxpark/qmk_toolbox
        private void MainWindow_Load(object sender, EventArgs e)
        {
            windowStateBindingSource.DataSource = windowState;
            windowState.PropertyChanged        += AutoFlashEnabledChanged;

            if (Settings.Default.hexFileCollection != null)
            {
                filepathBox.Items.AddRange(Settings.Default.hexFileCollection.ToArray());
            }

            mcuBox.SelectedValue = Settings.Default.targetSetting;

            _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);
            _printer.PrintResponse(" - Atmel/LUFA/QMK DFU via dfu-programmer (http://dfu-programmer.github.io/)\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(" - 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(" - LUFA Mass Storage\n", MessageType.Info);
            _printer.PrintResponse("Supported ISP flashers:\n", MessageType.Info);
            _printer.PrintResponse(" - AVRISP (Arduino ISP)\n", MessageType.Info);
            _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();

            consoleListener.consoleDeviceConnected    += ConsoleDeviceConnected;
            consoleListener.consoleDeviceDisconnected += ConsoleDeviceDisconnected;
            consoleListener.consoleReportReceived     += ConsoleReportReceived;
            consoleListener.Start();

            if (_filePassedIn != string.Empty)
            {
                SetFilePath(_filePassedIn);
            }
        }
コード例 #12
0
ファイル: USB.cs プロジェクト: yoshi415/qmk_toolbox
        public bool DetectBootloader(ManagementBaseObject instance, bool connected = true)
        {
            var connectedString = connected ? "connected" : "disconnected";
            var deviceId        = instance.GetPropertyValue("DeviceID").ToString();

            var deviceidRegex = new Regex(@"VID_([0-9A-F]+).*PID_([0-9A-F]+)\\([0-9A-F]+)");
            var vp            = deviceidRegex.Match(instance.GetPropertyValue("DeviceID").ToString());
            var vid           = vp.Groups[1].ToString().PadLeft(4, '0');
            var pid           = vp.Groups[2].ToString().PadLeft(4, '0');
            var ver           = vp.Groups[3].ToString().PadLeft(4, '0');
            var uni           = instance.GetPropertyValue("ClassGuid").ToString();
            var comRegex      = new Regex("(COM[0-9]+)");

            string deviceName;

            if (MatchVid(deviceId, 0x03EB)) // Detects Atmel Vendor ID
            {
                deviceName = "DFU";
                _devicesAvailable[(int)Chipset.Dfu] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x2341) || MatchVid(deviceId, 0x1B4F) || MatchVid(deviceId, 0x239a)) // Detects Arduino Vendor ID, Sparkfun Vendor ID, Adafruit Vendor ID
            {
                deviceName = "Caterina";

                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.Caterina] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x0478)) // Detects PJRC VID & PID
            {
                deviceName = "Halfkay";
                _devicesAvailable[(int)Chipset.Halfkay] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x0483) && MatchPid(deviceId, 0xDF11)) // Detects STM32 PID & VID
            {
                deviceName = "STM32";
                _devicesAvailable[(int)Chipset.Stm32] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x1C11) && MatchPid(deviceId, 0xB007)) // Detects Kiibohd VID & PID
            {
                deviceName = "Kiibohd";
                _devicesAvailable[(int)Chipset.Kiibohd] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x0483)) // Detects Arduino ISP VID & PID
            {
                deviceName            = "AVRISP";
                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.Avrisp] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x1781) && MatchPid(deviceId, 0x0C9F)) // Detects AVR Pocket ISP VID & PID
            {
                deviceName = "USB Tiny";

                _flasher.CaterinaPort = GetComPort(deviceId);
                _devicesAvailable[(int)Chipset.UsbTiny] += connected ? 1 : -1;
            }
            else if (MatchVid(deviceId, 0x16C0) && MatchPid(deviceId, 0x05DF)) // Detects Objective Development VID & PID
            {
                deviceName = "BootloadHID";
                _devicesAvailable[(int)Chipset.BootloadHID] += connected ? 1 : -1;
            }
            else
            {
                return(false);
            }

            _printer.Print($"{deviceName} device {connectedString}: {instance.GetPropertyValue("Name")} -- {vid}:{pid}:{ver} {uni}", MessageType.Bootloader);
            return(true);
        }