Beispiel #1
0
        //
        // PUBLIC COM INTERFACE ISafetyMonitor IMPLEMENTATION
        //

        #region Common properties and methods.

        /// <summary>
        /// Displays the Setup Dialog form.
        /// If the user clicks the OK button to dismiss the form, then
        /// the new settings are saved, otherwise the old values are reloaded.
        /// THIS IS THE ONLY PLACE WHERE SHOWING USER INTERFACE IS ALLOWED!
        /// </summary>
        public void SetupDialog()
        {
            // consider only showing the setup dialog if not connected
            // or call a different dialog if connected
            if (wisesafetooperate.Connected)
            {
                System.Windows.Forms.MessageBox.Show("Already connected, just press OK");
            }

            using (SafeToOperateSetupDialogForm F = new SafeToOperateSetupDialogForm())
            {
                var result = F.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    wisesafetooperate.WriteProfile(); // Persist device configuration values to the ASCOM Profile store
                }
            }
        }
Beispiel #2
0
        private void cmdOK_Click(object sender, EventArgs e) // OK button event handler
        {
            bool  valid      = true;
            Color errorColor = Color.Red;
            int   i;

            // Place any validation constraint checks here
            // Update the state variables with results from the dialogue
            i = Convert.ToInt32(textBoxAge.Text);
            if (i < 0)
            {
                textBoxAge.ForeColor = errorColor;
                valid = false;
            }
            else
            {
                WiseSafeToOperate.ageMaxSeconds = i;
            }

            i = Convert.ToInt32(textBoxRestoreSafety.Text);
            if (i < 0)
            {
                textBoxRestoreSafety.ForeColor = errorColor;
                valid = false;
            }
            else
            {
                WiseSafeToOperate._stabilizationPeriod = new TimeSpan(0, Convert.ToInt32(textBoxRestoreSafety.Text), 0);
            }

            WiseSafeToOperate.cloudsSensor.MaxAsString = textBoxCloudCoverPercent.Text;
            WiseSafeToOperate.rainSensor.MaxAsString   = textBoxRain.Text;

            i = Convert.ToInt32(textBoxHumidity.Text);
            if (i >= 0 && i <= 100)
            {
                WiseSafeToOperate.humiditySensor.MaxAsString = i.ToString();
            }
            else
            {
                textBoxHumidity.ForeColor = errorColor;
                valid = false;
            }

            i = Convert.ToInt32(textBoxWind.Text);
            if (i >= 0)
            {
                WiseSafeToOperate.windSensor.MaxAsString = i.ToString();
            }
            else
            {
                textBoxWind.ForeColor = errorColor;
                valid = false;
            }

            double deg = Convert.ToDouble(textBoxSunElevation.Text);

            if (deg > 0 || deg < -20)
            {
                textBoxSunElevation.ForeColor = errorColor;
                valid = false;
            }
            else
            {
                WiseSafeToOperate.sunSensor.MaxAsString = deg.ToString();
            }

            if (!valid)
            {
                return;
            }

            foreach (Sensor s in WiseSafeToOperate._cumulativeSensors)
            {
                s.Enabled = false;
            }

            WiseSafeToOperate.cloudsSensor._repeats        = Convert.ToInt32(textBoxCloudRepeats.Text);
            WiseSafeToOperate.cloudsSensor._intervalMillis = Convert.ToInt32(textBoxCloudIntervalSeconds.Text) * 1000;
            WiseSafeToOperate.cloudsSensor.Enabled         = checkBoxCloud.Checked;

            WiseSafeToOperate.windSensor._repeats        = Convert.ToInt32(textBoxWindRepeats.Text);
            WiseSafeToOperate.windSensor._intervalMillis = Convert.ToInt32(textBoxWindIntervalSeconds.Text) * 1000;
            WiseSafeToOperate.windSensor.Enabled         = checkBoxWind.Checked;

            WiseSafeToOperate.humiditySensor._repeats        = Convert.ToInt32(textBoxHumidityRepeats.Text);
            WiseSafeToOperate.humiditySensor._intervalMillis = Convert.ToInt32(textBoxHumidityIntervalSeconds.Text) * 1000;
            WiseSafeToOperate.humiditySensor.Enabled         = checkBoxHumidity.Checked;

            WiseSafeToOperate.sunSensor._intervalMillis = Convert.ToInt32(textBoxSunIntervalSeconds.Text) * 1000;
            WiseSafeToOperate.sunSensor.Enabled         = checkBoxSun.Checked;

            WiseSafeToOperate.rainSensor._repeats        = Convert.ToInt32(textBoxRainRepeats.Text);
            WiseSafeToOperate.rainSensor._intervalMillis = Convert.ToInt32(textBoxRainIntervalSeconds.Text) * 1000;
            WiseSafeToOperate.rainSensor.Enabled         = checkBoxRain.Checked;

            WiseSafeToOperate.doorLockSensor.MaxAsString = textBoxDoorLockDelay.Text;

            wisesafetooperate.WriteProfile();

            foreach (Sensor s in WiseSafeToOperate._cumulativeSensors)
            {
                s.Restart(5000);
            }

            Close();
        }