示例#1
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();

            try
            {
                diag.Multiselect     = false;
                diag.CheckFileExists = true;
                diag.Filter          = "PWM preset files (*.pwm)|*.pwm|All files (*.*)|*.*";
                DialogResult choice = diag.ShowDialog();

                endActiveMode();
                if (choice == System.Windows.Forms.DialogResult.OK)
                {
                    loadFile(diag.FileName);
                }

                //diag.Dispose();
                startActiveMode();
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, "Incompatible PWM settings file.\n\nError:\n" + exc.Message, "Could not load file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                endActiveMode();
                currentSettings = null;
                startActiveMode();
            }
            finally
            {
                diag.Dispose();
            }
        }
示例#2
0
 private void clearSettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     connector.resetChannelSettings();
     startActiveMode();
 }
示例#3
0
        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            connector.Stop();
            currentSettings = saveSettingsToObject();
            lastMode        = currentSettings.ControlMode;
            endActiveMode();

            OptionsForm frm = new OptionsForm();

            //frm.Owner = this;
            frm.ShowDialog(this);
            frm.Dispose();

            // If the generationmode was changed, don't use the old settings
            if (lastMode != Properties.Settings.Default.GenerationMode)
            {
                connector.resetChannelSettings();
            }

            if (currentSettings != null)
            {
                currentSettings.sampleRate = Properties.Settings.Default.SampleRate;
            }

            startActiveMode();
        }
示例#4
0
        private void loadFile(String path)
        {
            XmlSerializer       serializer     = new XmlSerializer(typeof(PwmSettingsTemplate));
            TextReader          textreader     = new StreamReader(path);
            PwmSettingsTemplate loadedSettings = (PwmSettingsTemplate)serializer.Deserialize(textreader);

            Properties.Settings.Default.SampleRate     = loadedSettings.sampleRate;
            Properties.Settings.Default.GenerationMode = loadedSettings.ControlMode;
            currentSettings = loadedSettings;
            textreader.Close();
        }
示例#5
0
        private PwmSettingsTemplate saveSettingsToObject()
        {
            XmlElement          sets     = mainControl.saveSettings();
            PwmSettingsTemplate template = new PwmSettingsTemplate();

            template.ControlMode        = Properties.Settings.Default.GenerationMode;
            template.sampleRate         = Properties.Settings.Default.SampleRate;
            template.ControllerSettings = sets;

            return(template);
        }
示例#6
0
        private void loadControlComponent()
        {
            connector.SampleRate = Properties.Settings.Default.SampleRate;
            controlMode          = Properties.Settings.Default.GenerationMode;

            switch (controlMode)
            {
            case PwmControlMode.GenericAsync:
                mainControl = new GenericPwmControl(PwmGeneratorModes.Asynchronous);
                this.Text   = ApplicationTitle + "  [ASynchronous mode]";
                break;

            case PwmControlMode.GenericSync:
                mainControl = new GenericPwmControl(PwmGeneratorModes.Synchronous);
                this.Text   = ApplicationTitle + "  [Synchronous mode]";
                break;

            case PwmControlMode.RCControl:
                mainControl = new RcPwmControl();
                this.Text   = ApplicationTitle + "  [R/C control mode]";
                break;

            default:
                MessageBox.Show("This mode is not supported yet");
                endActiveMode();
                return;
            }


            mainControl.ShowRealValueToolTips = Properties.Settings.Default.ShowRealValueToolTips;
            mainControl.ColoredBorders        = Properties.Settings.Default.ColoredChannelBorders;
            mainControl.initialize(connector);
            mainControlPanel.Controls.Add((Control)mainControl);

            this.Size = new System.Drawing.Size(((Control)mainControl).Size.Width + 10, ((Control)mainControl).Size.Height + 100);

            startPwmButton.Enabled = connector.Connected;


            // If there are settings to be loaded
            if (currentSettings != null)
            {
                if (Properties.Settings.Default.GenerationMode == currentSettings.ControlMode)
                {
                    mainControl.loadSettings(currentSettings.ControllerSettings);
                }
                else
                {
                    currentSettings = null;
                }
            }
        }
示例#7
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog diag = new SaveFileDialog();

            diag.FileName        = "PWM_Presets.pwm";
            diag.Filter          = "PWM preset files (*.pwm)|*.pwm|All files (*.*)|*.*";
            diag.OverwritePrompt = true;
            DialogResult choice = diag.ShowDialog();

            if (choice == System.Windows.Forms.DialogResult.OK)
            {
                PwmSettingsTemplate template   = saveSettingsToObject();
                TextWriter          textWriter = new StreamWriter(diag.FileName);
                XmlSerializer       serializer = new XmlSerializer(typeof(PwmSettingsTemplate));
                serializer.Serialize(textWriter, template);
                textWriter.Close();
            }
        }
示例#8
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     startActiveMode();
 }
示例#9
0
        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            connector.Stop();
            currentSettings = saveSettingsToObject();
            lastMode = currentSettings.ControlMode;
            endActiveMode();

            OptionsForm frm = new OptionsForm();
            //frm.Owner = this;
            frm.ShowDialog(this);
            frm.Dispose();

            // If the generationmode was changed, don't use the old settings
            if (lastMode != Properties.Settings.Default.GenerationMode)
            {
                connector.resetChannelSettings();
            }

            if (currentSettings != null)
            {
                currentSettings.sampleRate = Properties.Settings.Default.SampleRate;
            }

            startActiveMode();
        }
示例#10
0
        private PwmSettingsTemplate saveSettingsToObject()
        {
            XmlElement sets = mainControl.saveSettings();
            PwmSettingsTemplate template = new PwmSettingsTemplate();
            template.ControlMode = Properties.Settings.Default.GenerationMode;
            template.sampleRate = Properties.Settings.Default.SampleRate;
            template.ControllerSettings = sets;

            return template;
        }
示例#11
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     startActiveMode();
 }
示例#12
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog diag = new OpenFileDialog();
            try
            {
                diag.Multiselect = false;
                diag.CheckFileExists = true;
                diag.Filter = "PWM preset files (*.pwm)|*.pwm|All files (*.*)|*.*";
                DialogResult choice = diag.ShowDialog();

                endActiveMode();
                if (choice == System.Windows.Forms.DialogResult.OK)
                {

                    loadFile(diag.FileName);
                }

                //diag.Dispose();
                startActiveMode();
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, "Incompatible PWM settings file.\n\nError:\n" + exc.Message, "Could not load file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                endActiveMode();
                currentSettings = null;
                startActiveMode();
            }
            finally
            {
                diag.Dispose();
            }
        }
示例#13
0
        private void loadFile(String path)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PwmSettingsTemplate));
            TextReader textreader = new StreamReader(path);
            PwmSettingsTemplate loadedSettings = (PwmSettingsTemplate)serializer.Deserialize(textreader);

            Properties.Settings.Default.SampleRate = loadedSettings.sampleRate;
            Properties.Settings.Default.GenerationMode = loadedSettings.ControlMode;
            currentSettings = loadedSettings;
            textreader.Close();
        }
示例#14
0
        private void loadControlComponent()
        {
            connector.SampleRate = Properties.Settings.Default.SampleRate;
            controlMode = Properties.Settings.Default.GenerationMode;

            switch (controlMode)
            {
                case PwmControlMode.GenericAsync:
                    mainControl = new GenericPwmControl( PwmGeneratorModes.Asynchronous);
                    this.Text = ApplicationTitle + "  [ASynchronous mode]";
                    break;
                case PwmControlMode.GenericSync:
                    mainControl = new GenericPwmControl( PwmGeneratorModes.Synchronous);
                    this.Text = ApplicationTitle + "  [Synchronous mode]";
                    break;
                case PwmControlMode.RCControl:
                    mainControl = new RcPwmControl();
                    this.Text = ApplicationTitle + "  [R/C control mode]";
                    break;
                default:
                    MessageBox.Show("This mode is not supported yet");
                    endActiveMode();
                    return;
            }

            mainControl.ShowRealValueToolTips = Properties.Settings.Default.ShowRealValueToolTips;
            mainControl.ColoredBorders = Properties.Settings.Default.ColoredChannelBorders;
            mainControl.initialize(connector);
            mainControlPanel.Controls.Add((Control)mainControl);

            this.Size = new System.Drawing.Size(((Control)mainControl).Size.Width + 10, ((Control)mainControl).Size.Height + 100);

            startPwmButton.Enabled = connector.Connected;

            // If there are settings to be loaded
            if (currentSettings != null)
            {
                if (Properties.Settings.Default.GenerationMode == currentSettings.ControlMode)
                {
                    mainControl.loadSettings(currentSettings.ControllerSettings);
                }
                else
                {
                    currentSettings = null;
                }
            }
        }
示例#15
0
 private void clearSettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     connector.resetChannelSettings();
     startActiveMode();
 }