Пример #1
0
        // Draw usage bar and show info in console
        private void memoryUsageBar(MemTypeFile file, PictureBox pic, int availableSpace)
        {
            bool outOfSpace = file.size > availableSpace;

            // Info
            if (file.size != Avrsize.INVALID && file.location != "")
            {
                float perc = 0;
                if (availableSpace > 0)
                    perc = ((float)file.size / availableSpace) * 100;
                string fmt = "{0}: {1:#,#0} / {2:#,#0} Bytes ({3:0.00}%){4}{5}";
                string outOfSpaceStr = outOfSpace ? " [!]" : "";
                Util.consoleWrite(String.Format(fmt, Path.GetFileName(file.location), file.size, availableSpace, perc, outOfSpaceStr, Environment.NewLine));
            }

            Bitmap bmp = (Bitmap)pic.Image;

            int usageWidth;
            Color barColour = Color.Red;

            if (outOfSpace)
                usageWidth = bmp.Width;
            else if (availableSpace > 0 && file.size != Avrsize.INVALID)
                usageWidth = (int)(bmp.Width * ((float)file.size / availableSpace));
            else
                usageWidth = 0;

            // Blue gradient thing
            byte startColour = 128;
            byte endColour = 192;
            float colourDiff = (float)(endColour - startColour) / usageWidth;

            // Fill in used space pixels
            for (int i = 0; i < usageWidth; i++)
            {
                if (!outOfSpace)
                    barColour = Color.FromArgb(0x00, startColour + (byte)(colourDiff * i), 0xFF);

                for (byte h = 0; h < bmp.Height; h++)
                    bmp.SetPixel(i, h, barColour);
            }

            // Fill in available space pixels
            for (int i = usageWidth; i < bmp.Width; i++)
            {
                for (byte h = 0; h < bmp.Height; h++)
                    bmp.SetPixel(i, h, Color.Transparent);
            }

            pic.Image = bmp;
        }
Пример #2
0
        // Draw usage bar and show info in console
        private void memoryUsageBar(MemTypeFile file, PictureBox pic, int availableSpace)
        {
            bool outOfSpace = file.size > availableSpace;

            // Info
            if (file.size != Avrsize.INVALID && file.location != "")
            {
                float perc = 0;
                if (availableSpace > 0)
                {
                    perc = ((float)file.size / availableSpace) * 100;
                }
                string fmt           = "{0}: {1:#,#0} / {2:#,#0} Bytes ({3:0.00}%){4}{5}";
                string outOfSpaceStr = outOfSpace ? " [!]" : "";
                Util.consoleWrite(String.Format(fmt, Path.GetFileName(file.location), file.size, availableSpace, perc, outOfSpaceStr, Environment.NewLine));
            }

            Bitmap bmp = (Bitmap)pic.Image;

            int   usageWidth;
            Color barColour = Color.Red;

            if (outOfSpace)
            {
                usageWidth = bmp.Width;
            }
            else if (availableSpace > 0 && file.size != Avrsize.INVALID)
            {
                usageWidth = (int)(bmp.Width * ((float)file.size / availableSpace));
            }
            else
            {
                usageWidth = 0;
            }

            // Blue gradient thing
            byte  startColour = 128;
            byte  endColour   = 192;
            float colourDiff  = (float)(endColour - startColour) / usageWidth;

            // Fill in used space pixels
            for (int i = 0; i < usageWidth; i++)
            {
                if (!outOfSpace)
                {
                    barColour = Color.FromArgb(0x00, startColour + (byte)(colourDiff * i), 0xFF);
                }

                for (byte h = 0; h < bmp.Height; h++)
                {
                    bmp.SetPixel(i, h, barColour);
                }
            }

            // Fill in available space pixels
            for (int i = usageWidth; i < bmp.Width; i++)
            {
                for (byte h = 0; h < bmp.Height; h++)
                {
                    bmp.SetPixel(i, h, Color.Transparent);
                }
            }

            pic.Image = bmp;
        }
Пример #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Load saved configuration
            Config.Prop.load();

            cmdLine = new CmdLine(this);
            avrdude = new Avrdude();
            avrsize = new Avrsize();

            avrdude.OnProcessStart += avrdude_OnProcessStart;
            avrdude.OnProcessEnd += avrdude_OnProcessEnd;
            avrdude.OnVersionChange += avrdude_OnVersionChange;
            avrdude.OnDetectedMCU += avrdude_OnDetectedMCU;

            avrdude.load();
            avrsize.load();

            // Setup memory files/usage bars
            // Flash
            fileFlash = new MemTypeFile(txtFlashFile, avrsize);
            fileFlash.sizeChanged += fileFlash_sizeChanged;
            pbFlashUsage.Width = txtFlashFile.Width;
            pbFlashUsage.Height = 3;
            pbFlashUsage.Location = new Point(txtFlashFile.Location.X, txtFlashFile.Location.Y - pbFlashUsage.Height);
            pbFlashUsage.Image = new Bitmap(pbFlashUsage.Width, pbFlashUsage.Height);
            memoryUsageBar(fileFlash, pbFlashUsage, 0);

            // EEPROM
            fileEEPROM = new MemTypeFile(txtEEPROMFile, avrsize);
            fileEEPROM.sizeChanged += fileEEPROM_sizeChanged;
            pbEEPROMUsage.Width = txtEEPROMFile.Width;
            pbEEPROMUsage.Height = 3;
            pbEEPROMUsage.Location = new Point(txtEEPROMFile.Location.X, txtEEPROMFile.Location.Y - pbEEPROMUsage.Height);
            pbEEPROMUsage.Image = new Bitmap(pbEEPROMUsage.Width, pbEEPROMUsage.Height);
            memoryUsageBar(fileEEPROM, pbEEPROMUsage, 0);

            enableClientAreaDrag(Controls);

            // Update serial ports etc
            cmbPort.DropDown += cbPort_DropDown;

            // Drag and drop flash file
            gbFlashFile.AllowDrop = true;
            gbFlashFile.DragEnter += event_DragEnter;
            gbFlashFile.DragDrop += event_DragDrop;

            // Drag and drop EEPROM file
            gbEEPROMFile.AllowDrop = true;
            gbEEPROMFile.DragEnter += event_DragEnter;
            gbEEPROMFile.DragDrop += event_DragDrop;

            // Flash file
            openFileDialog1.Filter = "Hex files (*.hex)|*.hex";
            openFileDialog1.Filter += "|EEPROM files (*.eep)|*.eep";
            openFileDialog1.Filter += "|All files (*.*)|*.*";
            openFileDialog1.CheckFileExists = false;
            openFileDialog1.FileName = "";
            openFileDialog1.Title = "Open flash file";

            // EEPROM file
            openFileDialog2.Filter = "EEPROM files (*.eep)|*.eep";
            openFileDialog2.Filter += "|Hex files (*.hex)|*.hex";
            openFileDialog2.Filter += "|All files (*.*)|*.*";
            openFileDialog2.CheckFileExists = false;
            openFileDialog2.FileName = "";
            openFileDialog2.Title = "Open EEPROM file";

            // MCU & programmer combo box data source
            setComboBoxDataSource(cmbMCU, avrdude.mcus, "fullName");
            cmbMCU.SelectedIndexChanged += cmbMCU_SelectedIndexChanged;
            setComboBoxDataSource(cmbProg, avrdude.programmers, "fullName");
            cmbProg.SelectedIndexChanged += cmbProg_SelectedIndexChanged;

            // USBasp frequency settings
            cmbUSBaspFreq.Hide();
            setComboBoxDataSource(cmbUSBaspFreq, Avrdude.USBaspFreqs, "name");
            cmbUSBaspFreq.Width = txtBitClock.Width;
            cmbUSBaspFreq.Left = txtBitClock.Left;
            cmbUSBaspFreq.Top = txtBitClock.Top;

            // Flash & EEPROM file formats
            setComboBoxDataSource(cmbFlashFormat, Avrdude.fileFormats, "fullName");
            setComboBoxDataSource(cmbEEPROMFormat, Avrdude.fileFormats, "fullName");

            // Verbosity levels
            cmdVerbose.Items.Clear();
            for (byte i=0;i<5;i++)
                cmdVerbose.Items.Add(i);
            cmdVerbose.SelectedIndex = 0;

            // Tool tips
            ToolTips = new ToolTip();
            ToolTips.ReshowDelay = 100;
            ToolTips.UseAnimation = false;
            ToolTips.UseFading = false;
            ToolTips.SetToolTip(cmbProg, "Programmer");
            ToolTips.SetToolTip(cmbMCU, "MCU to program");
            ToolTips.SetToolTip(cmbPort, "Set COM/LTP/USB port");
            ToolTips.SetToolTip(txtBaudRate, "Port baud rate");
            ToolTips.SetToolTip(txtBitClock, "Bit clock period (us)");
            ToolTips.SetToolTip(txtFlashFile, "Hex file (.hex)" + Environment.NewLine + "You can also drag and drop files here");
            ToolTips.SetToolTip(pFlashOp, "");
            ToolTips.SetToolTip(txtEEPROMFile, "EEPROM file (.eep)" + Environment.NewLine + "You can also drag and drop files here");
            ToolTips.SetToolTip(pEEPROMOp, "");
            ToolTips.SetToolTip(cbForce, "Skip signature check");
            ToolTips.SetToolTip(cbNoVerify, "Don't verify after writing");
            ToolTips.SetToolTip(cbDisableFlashErase, "Don't erase flash before writing");
            ToolTips.SetToolTip(cbEraseFlashEEPROM, "Erase both flash and EEPROM");
            ToolTips.SetToolTip(cbDoNotWrite, "Don't write anything, used for debugging AVRDUDE");
            ToolTips.SetToolTip(txtLFuse, "Low fuse");
            ToolTips.SetToolTip(txtHFuse, "High fuse");
            ToolTips.SetToolTip(txtEFuse, "Extended fuse");
            ToolTips.SetToolTip(txtLock, "Lock bits");
            ToolTips.SetToolTip(btnFlashGo, "Only write/read/verify flash");
            ToolTips.SetToolTip(btnEEPROMGo, "Only write/read/verify EEPROM");
            ToolTips.SetToolTip(btnWriteFuses, "Write fuses now");
            ToolTips.SetToolTip(btnWriteLock, "Write lock now");
            ToolTips.SetToolTip(cbSetFuses, "Write fuses when programming");
            ToolTips.SetToolTip(cbSetLock, "Write lock when programming");

            // Load saved presets
            presets = new Presets(this);
            presets.load();
            presets.setDataSource(cmbPresets);

            // Enable/disable tool tips based on saved config
            ToolTips.Active = Config.Prop.toolTips;

            ready = true;

            // If a preset has not been specified by the command line then use the last used preset
            // Credits:
            // Uwe Tanger (specifing preset in command line)
            // neptune (sticky presets)
            if (presetToLoad == null)
                presetToLoad = Config.Prop.preset;

            // Load preset
            PresetData p = presets.presets.Find(s => s.name == presetToLoad);
            cmbPresets.SelectedItem = (p != null) ? p : presets.presets.Find(s => s.name == "Default");

            // Check for updates
            UpdateCheck.check.checkNow();
        }
Пример #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Load saved configuration
            Config.Prop.load();

            // Persist window location across sessions
            // Credits:
            // gl.tter
            if (Config.Prop.windowLocation != null && Config.Prop.windowLocation != new Point(0, 0))
            {
                Location = Config.Prop.windowLocation;
            }

            cmdLine = new CmdLine(this);
            avrdude = new Avrdude();
            avrsize = new Avrsize();

            avrdude.OnProcessStart  += avrdude_OnProcessStart;
            avrdude.OnProcessEnd    += avrdude_OnProcessEnd;
            avrdude.OnVersionChange += avrdude_OnVersionChange;
            avrdude.OnDetectedMCU   += avrdude_OnDetectedMCU;

            avrdude.load();
            avrsize.load();

            // Setup memory files/usage bars
            // Flash
            fileFlash              = new MemTypeFile(txtFlashFile, avrsize);
            fileFlash.sizeChanged += fileFlash_sizeChanged;
            pbFlashUsage.Width     = txtFlashFile.Width;
            pbFlashUsage.Height    = 3;
            pbFlashUsage.Location  = new Point(txtFlashFile.Location.X, txtFlashFile.Location.Y - pbFlashUsage.Height);
            pbFlashUsage.Image     = new Bitmap(pbFlashUsage.Width, pbFlashUsage.Height);
            memoryUsageBar(fileFlash, pbFlashUsage, 0);

            // EEPROM
            fileEEPROM              = new MemTypeFile(txtEEPROMFile, avrsize);
            fileEEPROM.sizeChanged += fileEEPROM_sizeChanged;
            pbEEPROMUsage.Width     = txtEEPROMFile.Width;
            pbEEPROMUsage.Height    = 3;
            pbEEPROMUsage.Location  = new Point(txtEEPROMFile.Location.X, txtEEPROMFile.Location.Y - pbEEPROMUsage.Height);
            pbEEPROMUsage.Image     = new Bitmap(pbEEPROMUsage.Width, pbEEPROMUsage.Height);
            memoryUsageBar(fileEEPROM, pbEEPROMUsage, 0);

            enableClientAreaDrag(Controls);

            // Update serial ports etc
            cmbPort.DropDown += cbPort_DropDown;

            // Drag and drop flash file
            gbFlashFile.AllowDrop  = true;
            gbFlashFile.DragEnter += event_DragEnter;
            gbFlashFile.DragDrop  += event_DragDrop;

            // Drag and drop EEPROM file
            gbEEPROMFile.AllowDrop  = true;
            gbEEPROMFile.DragEnter += event_DragEnter;
            gbEEPROMFile.DragDrop  += event_DragDrop;

            // Flash file
            openFileDialog1.Filter          = "Hex files (*.hex)|*.hex";
            openFileDialog1.Filter         += "|EEPROM files (*.eep)|*.eep";
            openFileDialog1.Filter         += "|All files (*.*)|*.*";
            openFileDialog1.CheckFileExists = false;
            openFileDialog1.FileName        = "";
            openFileDialog1.Title           = "Open flash file";

            // EEPROM file
            openFileDialog2.Filter          = "EEPROM files (*.eep)|*.eep";
            openFileDialog2.Filter         += "|Hex files (*.hex)|*.hex";
            openFileDialog2.Filter         += "|All files (*.*)|*.*";
            openFileDialog2.CheckFileExists = false;
            openFileDialog2.FileName        = "";
            openFileDialog2.Title           = "Open EEPROM file";

            // MCU & programmer combo box data source
            setComboBoxDataSource(cmbMCU, avrdude.mcus, "fullName");
            cmbMCU.SelectedIndexChanged += cmbMCU_SelectedIndexChanged;
            setComboBoxDataSource(cmbProg, avrdude.programmers, "fullName");
            cmbProg.SelectedIndexChanged += cmbProg_SelectedIndexChanged;

            // USBasp frequency settings
            cmbUSBaspFreq.Hide();
            setComboBoxDataSource(cmbUSBaspFreq, Avrdude.USBaspFreqs, "name");
            cmbUSBaspFreq.Width = txtBitClock.Width;
            cmbUSBaspFreq.Left  = txtBitClock.Left;
            cmbUSBaspFreq.Top   = txtBitClock.Top;

            // Flash & EEPROM file formats
            setComboBoxDataSource(cmbFlashFormat, Avrdude.fileFormats, "fullName");
            setComboBoxDataSource(cmbEEPROMFormat, Avrdude.fileFormats, "fullName");

            // Verbosity levels
            cmdVerbose.Items.Clear();
            for (byte i = 0; i < 5; i++)
            {
                cmdVerbose.Items.Add(i);
            }
            cmdVerbose.SelectedIndex = 0;

            // Tool tips
            ToolTips              = new ToolTip();
            ToolTips.ReshowDelay  = 100;
            ToolTips.UseAnimation = false;
            ToolTips.UseFading    = false;
            ToolTips.SetToolTip(cmbProg, "Programmer");
            ToolTips.SetToolTip(cmbMCU, "MCU to program");
            ToolTips.SetToolTip(cmbPort, "Set COM/LTP/USB port");
            ToolTips.SetToolTip(txtBaudRate, "Port baud rate");
            ToolTips.SetToolTip(txtBitClock, "Bit clock period (us)");
            ToolTips.SetToolTip(txtFlashFile, "Hex file (.hex)" + Environment.NewLine + "You can also drag and drop files here");
            ToolTips.SetToolTip(pFlashOp, "");
            ToolTips.SetToolTip(txtEEPROMFile, "EEPROM file (.eep)" + Environment.NewLine + "You can also drag and drop files here");
            ToolTips.SetToolTip(pEEPROMOp, "");
            ToolTips.SetToolTip(cbForce, "Skip signature check");
            ToolTips.SetToolTip(cbNoVerify, "Don't verify after writing");
            ToolTips.SetToolTip(cbDisableFlashErase, "Don't erase flash before writing" + Environment.NewLine + "Use this if you only want to update EEPROM");
            ToolTips.SetToolTip(cbEraseFlashEEPROM, "Erase both flash and EEPROM");
            ToolTips.SetToolTip(cbDoNotWrite, "Don't write anything, used for debugging AVRDUDE");
            ToolTips.SetToolTip(txtLFuse, "Low fuse");
            ToolTips.SetToolTip(txtHFuse, "High fuse");
            ToolTips.SetToolTip(txtEFuse, "Extended fuse");
            ToolTips.SetToolTip(txtLock, "Lock bits");
            ToolTips.SetToolTip(btnFlashGo, "Only write/read/verify flash");
            ToolTips.SetToolTip(btnEEPROMGo, "Only write/read/verify EEPROM");
            ToolTips.SetToolTip(btnWriteFuses, "Write fuses now");
            ToolTips.SetToolTip(btnWriteLock, "Write lock now");
            ToolTips.SetToolTip(btnReadFuses, "Read fuses now");
            ToolTips.SetToolTip(btnReadLock, "Read lock now");
            ToolTips.SetToolTip(cbSetFuses, "Write fuses when programming");
            ToolTips.SetToolTip(cbSetLock, "Write lock when programming");

            // Load saved presets
            presets = new Presets(this);
            presets.load();
            presets.setDataSource(cmbPresets);

            // Enable/disable tool tips based on saved config
            ToolTips.Active = Config.Prop.toolTips;

            ready = true;

            // If a preset has not been specified by the command line then use the last used preset
            // Credits:
            // Uwe Tanger (specifing preset in command line)
            // neptune (sticky presets)
            if (presetToLoad == null)
            {
                presetToLoad = Config.Prop.preset;
            }

            // Load preset
            PresetData p = presets.presets.Find(s => s.name == presetToLoad);

            cmbPresets.SelectedItem = (p != null) ? p : presets.presets.Find(s => s.name == "Default");

            // Check for updates
            UpdateCheck.check.checkNow();
        }