Ejemplo n.º 1
0
 static void firmwareUpdate_OnFirmwareUpdateProgress(object sender, FirmwareUpdateProgressEventArgs e)
 {
     statusText += e.Message + " " + System.Environment.NewLine;
     statusTextbox.Invoke(new Action(() => statusTextbox.Text = statusText));
     statusTextbox.Invoke(new Action(() => statusTextbox.SelectionStart = statusTextbox.Text.Length));
     statusTextbox.Invoke(new Action(() => statusTextbox.ScrollToCaret()));
     progressBar.Invoke(new Action(() => progressBar.Value = (int)e.Percentage));
     if (e.Percentage == 100)
     {
         form1.Invoke(new Action(() => MessageBox.Show("Firmware Update Complete.\n\nYou can verify the version on the 'Currently-loaded Firmware Version' tab.","navX-Model Firmware Updater",
             MessageBoxButtons.OK, MessageBoxIcon.Information)));
     }
 }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!firmware_update_registered)
            {
                firmwareUpdate.OnFirmwareUpdateProgress += new FirmwareUpdateProgressEventHandler(firmwareUpdate_OnFirmwareUpdateProgress);
                firmware_update_registered = true;
            }
            FirmwareUpdateProgressEventArgs fupea;
            progressBar1.Maximum = 100;
            progressBar1.Step = 1;
            progressBar1.Value = 0;

            statusText = "";
            statusTextbox.Clear();
            progressBar1.Visible = true;
            Application.DoEvents();
            fupea = new FirmwareUpdateProgressEventArgs(0, "Detecting DFU Interface...", false);
            firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);

            if (port.IsOpen)
            {
                close_port();
            }

            bool is_dfu_available = false;
            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();
            try
            {
                is_dfu_available = firmwareUpdate.IsDFUDeviceFound();
            }
            catch (Exception ex)
            {
                fupea = new FirmwareUpdateProgressEventArgs(0, ex.Message, true);
                firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);
            }
            if (!is_dfu_available)
            {
                Cursor.Current = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                dialog_in_progress = true;
                MessageBox.Show("To update navX-Model Firmware, ensure the device is in Firmware Update Mode.\n\n" +
                                "1. Disconnect the device from the PC USB port.\n" +
                                "2. Ensure the device has completely powered down (the RED 3.3V LED must be off).\n" +
                                "3. While holding down the 'CAL' button, re-connect the device to the PC USB port.\n\n" +
                                "4. After the device has powered up, release the 'CAL' button.\n" + 
                                "When in DFU mode, only the RED power LED will be ON.",
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                dialog_in_progress = false;
                return;
            }
            String dfu_file_name = Path.GetTempPath() + "navx.dfu";
            bool converted = hex2dfu.ConvertHexToDFU(full_path_to_hex_file,
                                    dfu_file_name,
                                    theVid,
                                    thePid,
                                    theBcd);
            if (!converted)
            {
                Cursor.Current = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                dialog_in_progress = true;
                MessageBox.Show("Error converting " + navXHexFilePath.Text + " to DFU format.",
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }

            UInt16 VID;
            UInt16 PID;
            UInt16 Version;
 
            try
            {
                firmwareUpdate.ParseDFU_File(dfu_file_name, out VID, out PID, out Version);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                fupea = new FirmwareUpdateProgressEventArgs(0, "Error parsing DFU file. " + ex.Message, false);
                firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);
                dialog_in_progress = true;
                MessageBox.Show("Error parsing DFU file. " + ex.Message,
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }

            fupea = new FirmwareUpdateProgressEventArgs(0, ("Found VID: " + VID.ToString("X4") + " PID: " + PID.ToString("X4") + " Version: " + Version.ToString("X4")), false);
            firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);

            try
            {
                bool eraseEveything = false;
                bool exitDFUMode = true;

                firmwareUpdate.UpdateFirmware(dfu_file_name, eraseEveything, exitDFUMode);
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                fupea = new FirmwareUpdateProgressEventArgs(0, "Error deploying DFU file. " + ex.Message, true);
                firmwareUpdate_OnFirmwareUpdateProgress(this,fupea);
                dialog_in_progress = true;
                MessageBox.Show("Error deploying DFU file. " + ex.Message,
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }
            progressBar1.Visible = false;
            Cursor.Current = Cursors.Default;
        }