/// <summary>
        /// The constructor method.
        /// </summary>
        /// <param name="fuzzyModel">A instance of the FuzzyModel class</param>
        public FuzzyModelUtilityVC(FuzzyModel fuzzyModel)
        {
            this.View = new FuzzyModelUtilityView(this);
            this.fuzzyModel = fuzzyModel;

            setupOutlets();

            // Setup the combobox
            string[] portNames = SerialPort.GetPortNames();
            View.HRSensorComboBox.Items.AddRange(portNames);
            View.HRSensorComboBox.SelectedIndex = 0;

            subscribe();

            hrValueLabel.Text = View.hrTrackBar.Value.ToString();
            gsrValueLabel.Text = View.gsrTrackBar.Value.ToString();

            // Set the default sensor types
            fuzzyModel.hrSensor.type = HRSensor.Type.ManualInput;
            fuzzyModel.gsrSensor.type = GSRSensor.Type.ManualInput;

            // Makes sure that from the start a value is present (not being 0).
            fuzzyModel.hrSensor.sensorValue = View.hrTrackBar.Value;
            fuzzyModel.gsrSensor.sensorValue = View.gsrTrackBar.Value;

            sensorController = null;

            TimerCallback timerCallback = sensorTimerCallback;
            sensorTimer = new Timer(timerCallback, null, 1000, 1000);

            this.currentState = State.Uncalibrated;
        }
Пример #2
0
 public SensorView(SensorViewController controller)
 {
     InitializeComponent();
 }
        /// <summary>
        /// Action Method: When the sensorButton is clicked, a SensorView is created and the from is shown
        /// </summary>
        public void sensorButtonClicked()
        {
            if (sensorController == null || sensorController.View.IsDisposed)
            {
                sensorController = new SensorViewController(fuzzyModel.hrSensor, fuzzyModel.gsrSensor);

                sensorController.View.Show();
            }
        }
        /// <summary>
        /// Action method when the calibrate button is clicked.
        /// </summary>
        public void calibrateButtonClicked()
        {
            // When the button is first pressed, show the sensorForm and start calabration.
            if (currentState == State.Calibrated)
            {
                // The method does not proceed as long as this messagebox is open.
                var result = MessageBox.Show("Weet u zeker dat u nog maal wilt kalibreren?", "Kalibratie", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (result == DialogResult.Yes)
                {
                    currentState = State.Uncalibrated;
                }
            }
            if (currentState == State.Uncalibrated)
            {
                // Show the form
                if (sensorController == null || sensorController.View.IsDisposed)
                {
                    sensorController = new SensorViewController(fuzzyModel.hrSensor, fuzzyModel.gsrSensor);
                }

                sensorController.View.Show();

                // Setup the countdown calibration timer
                timeSpanCounter = new TimeSpan(0, 10, 0);
                timer = new System.Windows.Forms.Timer();
                timer.Tick += new EventHandler(timer_Tick);
                timer.Interval = 1000; // 1 second
                timer.Start();
                calibrateButton.Text = timeSpanCounter.ToString(@"%h\:mm\:ss");

                // Pass any manual input values for the first time,
                // they are passed on change.
                if (fuzzyModel.hrSensor.type == HRSensor.Type.ManualInput)
                {
                    fuzzyModel.hrSensor.sensorValue = View.hrTrackBar.Value;
                }
                if (fuzzyModel.gsrSensor.type == GSRSensor.Type.ManualInput)
                {
                    fuzzyModel.gsrSensor.sensorValue = View.gsrTrackBar.Value;
                }

                 // Start calibrating
                fuzzyModel.startCalibration();
                currentState = State.Calibrating;
                Console.WriteLine("Calibratie gestart");
            }
            // When the button is pressed for a second time, the calibration is stopped
            else if (currentState == State.Calibrating)
            {
                // Stop the countdown and set the form back to the original state
                timer.Stop();
                calibrateButton.Text = "Opnieuw kalibreren";

                fuzzyModel.stopCalibration();
                currentState = State.Calibrated;
                Console.WriteLine("Calibratie gestopt");
            }
        }