Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
 private void clearSettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     connector.resetChannelSettings();
     startActiveMode();
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 8
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     startActiveMode();
 }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 11
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     startActiveMode();
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 15
0
 private void clearSettingsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     endActiveMode();
     currentSettings = null;
     connector.resetChannelSettings();
     startActiveMode();
 }