Пример #1
0
 // Get connected temperature probes
 private void GetConnectedProbes_MessageReceived(Probes _probes)
 {
     probes = _probes;
 }
Пример #2
0
        // MainViewModel Class Constructor
        public MainViewModel()
        {
            // Creating new instance of model
            breweryCommand = new BreweryCommands();
            hardwareSettings = new HardwareSettings();
            brewery = new Brewery();
            process = new Process();
            probes = new Probes();
            userAlarm = new UserAlarm(); 

            // Initializing RelayCommand Instances
            ConnectionSetupClickCommand = new RelayCommand(connectionSetupClickCommand);
            HardwareSetupClickCommand = new RelayCommand(hardwareSetupClickCommand);
            StartBrewSessionClickCommand = new RelayCommand(startBrewSessionClickCommand);
            MainClosingCommand = new RelayCommand(mainClosing);
            LoadRecipeClickCommand = new RelayCommand(loadRecipeClickCommand);
            DebugDesignSessionClickCommand = new RelayCommand(debugDesignClickCommand);

            // Initializing Timers
            UpdateTempSensorTimer = new DispatcherTimer();
            UpdateVolSensorTimer = new DispatcherTimer();
            AlarmTimer = new DispatcherTimer();
            PrimingTimer = new DispatcherTimer();
            MashStepTimer = new DispatcherTimer();
            BoilTimer = new DispatcherTimer();

            // Initializing Sound Player
            Player = new MediaPlayer();

            // Initializing Machine State Variables
            MashStepComplete = false;
            FirstMashStep = true;
            FirstSparge = true;
            SpargeModeOn = false;
            BoilOverSent = false;
            BoilComplete = false;
            StepStartTime = new TimeSpan();
            RemainingTime = new TimeSpan();
            StepEndTime = new TimeSpan();

            // Initializing the brewery State
            breweryState = BreweryState.StandBy;
            RaisePropertyChanged(BreweryStateDisplayPropertyName);

            // Initializing Messenger Registers
            Messenger.Default.Register<NotificationMessage>(this, "BreweryCommand", BreweryCommand_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "ConnectionUpdate" , ConnectionUpdate_MessageReceived);
            Messenger.Default.Register<HardwareSettings>(this, "HardwareSettingsUpdate", HardwareSettings_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "TemperatureUpdate", TemperatureUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "VolumeUpdate", VolumeUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "HLTBurnerUpdate", HLTBurnerUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "MLTBurnerUpdate", MLTBurnerUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "BKBurnerUpdate", BKBurnerUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "Pump1Update", Pump1Update_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "Pump2Update", Pump2Update_MessageReceived);
            Messenger.Default.Register<string>(this, "SelectedcomPort", SelectedcomPort_MessageReceived);
            Messenger.Default.Register<Process>(this, Process_MessageReceived);
            Messenger.Default.Register<Probes>(this, "GetConnectedProbes", GetConnectedProbes_MessageReceived);
            Messenger.Default.Register<UserAlarm>(this, "UserAlarmReturn", UserAlarmReturn_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "HLTTempSetPointUpdate", HLTTempSetPointUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "MLTTempSetPointUpdate", MLTTempSetPointUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "BKTempSetPointUpdate", BKTempSetPointUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "HLTTempSetPointReachedUpdate", HLTTempSetPointReachedUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "MLTTempSetPointReachedUpdate", MLTTempSetPointReachedUpdate_MessageReceived);
            Messenger.Default.Register<Brewery>(this, "BKTempSetPointReachedUpdate", BKTempSetPointReachedUpdate_MessageReceived);
        }
Пример #3
0
        // Temperature update received
        private void TemperatureUpdate_MessageReceived(Probes probes)
        {
            // Set HLT temperature
            if(hardwareSettings.HLT_Temp_Probe.Address == probes.Yellow.Address) { brewery.HLT.Temp.Value = probes.Yellow.Temp; }
            if(hardwareSettings.HLT_Temp_Probe.Address == probes.Pink.Address) { brewery.HLT.Temp.Value = probes.Pink.Temp; }
            if(hardwareSettings.HLT_Temp_Probe.Address == probes.Orange.Address) { brewery.HLT.Temp.Value = probes.Orange.Temp; }
            if(hardwareSettings.HLT_Temp_Probe.Address == probes.YellowOrange.Address) { brewery.HLT.Temp.Value = probes.YellowOrange.Temp; }
            if(hardwareSettings.HLT_Temp_Probe.Address == probes.YellowPink.Address) { brewery.HLT.Temp.Value = probes.YellowPink.Temp; }

            // Set MLT temperature
            if (hardwareSettings.MLT_Temp_Probe.Address == probes.Yellow.Address) { brewery.MLT.Temp.Value = probes.Yellow.Temp; }
            if (hardwareSettings.MLT_Temp_Probe.Address == probes.Pink.Address) { brewery.MLT.Temp.Value = probes.Pink.Temp; }
            if (hardwareSettings.MLT_Temp_Probe.Address == probes.Orange.Address) { brewery.MLT.Temp.Value = probes.Orange.Temp; }
            if (hardwareSettings.MLT_Temp_Probe.Address == probes.YellowOrange.Address) { brewery.MLT.Temp.Value = probes.YellowOrange.Temp; }
            if (hardwareSettings.MLT_Temp_Probe.Address == probes.YellowPink.Address) { brewery.MLT.Temp.Value = probes.YellowPink.Temp; }

            // Set BK temperature
            if (hardwareSettings.BK_Temp_Probe.Address == probes.Yellow.Address) { brewery.BK.Temp.Value = probes.Yellow.Temp; }
            if (hardwareSettings.BK_Temp_Probe.Address == probes.Pink.Address) { brewery.BK.Temp.Value = probes.Pink.Temp; }
            if (hardwareSettings.BK_Temp_Probe.Address == probes.Orange.Address) { brewery.BK.Temp.Value = probes.Orange.Temp; }
            if (hardwareSettings.BK_Temp_Probe.Address == probes.YellowOrange.Address) { brewery.BK.Temp.Value = probes.YellowOrange.Temp; }
            if (hardwareSettings.BK_Temp_Probe.Address == probes.YellowPink.Address) { brewery.BK.Temp.Value = probes.YellowPink.Temp; }

            // Send temperature to main view model
            Messenger.Default.Send<Brewery>(brewery, "TemperatureUpdate");
        }
        private void Probes_MessageReceived(Probes probes)
        {
            ProbeColors.Clear(); 

            if (probes.Orange.IsConnected) { ProbeColors.Add(probes.Orange.Color); }
            if(probes.Pink.IsConnected) { ProbeColors.Add(probes.Pink.Color); }
            if(probes.Yellow.IsConnected) { ProbeColors.Add(probes.Yellow.Color); }
            if(probes.YellowOrange.IsConnected) { ProbeColors.Add(probes.YellowOrange.Color); }
            if (probes.YellowPink.IsConnected) { ProbeColors.Add(probes.YellowPink.Color); }  
        }
        // Apply changes from the edit dialog
        private void confirmSettingCommand()
        {
            switch (SelectedSetting.Name)
            {
                case "VolRefreshRate":
                    {
                        if(SelectedRefreshRate < 1000) { MessageBox.Show("The volume sensor refresh rate can't be smaller than 1000 milliseconds"); return; }
                        VolRefreshRate = SelectedRefreshRate;
                        hardwareSettings.VolResfreshRate = VolRefreshRate;
                        Messenger.Default.Send<NotificationMessage>(new NotificationMessage("CloseRefreshRateDialog"), "WindowOperation");
                        return;
                    }
                case "TempRefreshRate":
                    {
                        if(SelectedRefreshRate<2500) { MessageBox.Show("Temperature sensors refresh rate can't be smaller tahn 2500 milliseconds"); return; }
                        TempRefreshRate = SelectedRefreshRate;
                        hardwareSettings.TempRefreshRate = TempRefreshRate;
                        Messenger.Default.Send<NotificationMessage>(new NotificationMessage("CloseRefreshRateDialog"), "WindowOperation");
                        return;
                    }
                case "HLT_Vol_Pin":
                    {
                        HLT_Vol_Pin = SelectedPin;
                        hardwareSettings.HLT_Vol_Pin = HLT_Vol_Pin;
                        break;
                    }
                case "BK_Vol_Pin":
                    {
                        BK_Vol_Pin = SelectedPin;
                        hardwareSettings.BK_Vol_Pin = BK_Vol_Pin;
                        break;
                    }
                case "HLT_Burner_Pin":
                    {
                        HLT_Burner_Pin = SelectedPin;
                        hardwareSettings.HLT_Burner_Pin = HLT_Burner_Pin;
                        break;
                    }
                case "MLT_Burner_Pin":
                    {
                        MLT_Burner_Pin = SelectedPin;
                        hardwareSettings.MLT_Burner_Pin = MLT_Burner_Pin;
                        break;
                    }
                case "BK_Burner_Pin":
                    {
                        BK_Burner_Pin = SelectedPin;
                        hardwareSettings.BK_Burner_Pin = BK_Burner_Pin;
                        break;
                    }
                case "Pump1_Pin":
                    {
                        Pump1_Pin = SelectedPin;
                        hardwareSettings.Pump1_Pin = Pump1_Pin;
                        break;
                    }
                case "Pump2_Pin":
                    {
                        Pump2_Pin = SelectedPin;
                        hardwareSettings.Pump2_Pin = Pump2_Pin;
                        break;
                    }
                case "AirPump1_Pin":
                    {
                        AirPump1_Pin = SelectedPin;
                        hardwareSettings.AirPump1_Pin = AirPump1_Pin;
                        break;
                    }
                case "AirPump2_Pin":
                    {
                        AirPump2_Pin = SelectedPin;
                        hardwareSettings.AirPump2_Pin = AirPump2_Pin;
                        break;
                    }
                case "HLT_Temp_Probe":
                    {
                        Probes _probe = new Probes();

                        switch(SelectedProbeColor)
                        {
                            case "Yellow":
                                {
                                    HLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.HLT_Temp_Probe.Address = _probe.Yellow.Address;
                                    hardwareSettings.HLT_Temp_Probe.Color = _probe.Yellow.Color;
                                    hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Pink":
                                {
                                    HLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.HLT_Temp_Probe.Address = _probe.Pink.Address;
                                    hardwareSettings.HLT_Temp_Probe.Color = _probe.Pink.Color;
                                    hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Orange":
                                {
                                    HLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.HLT_Temp_Probe.Address = _probe.Orange.Address;
                                    hardwareSettings.HLT_Temp_Probe.Color = _probe.Orange.Color;
                                    hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Pink":
                                {
                                    HLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.HLT_Temp_Probe.Address = _probe.YellowPink.Address;
                                    hardwareSettings.HLT_Temp_Probe.Color = _probe.YellowPink.Color;
                                    hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Orange":
                                {
                                    HLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.HLT_Temp_Probe.Address = _probe.YellowOrange.Address;
                                    hardwareSettings.HLT_Temp_Probe.Color = _probe.YellowOrange.Color;
                                    hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                                    break;
                                }
                        }
                        break;
                    }

                case "MLT_Temp_Probe":
                    {
                        Probes _probe = new Probes();

                        switch (SelectedProbeColor)
                        {
                            case "Yellow":
                                {
                                    MLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.MLT_Temp_Probe.Address = _probe.Yellow.Address;
                                    hardwareSettings.MLT_Temp_Probe.Color = _probe.Yellow.Color;
                                    hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Pink":
                                {
                                    MLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.MLT_Temp_Probe.Address = _probe.Pink.Address;
                                    hardwareSettings.MLT_Temp_Probe.Color = _probe.Pink.Color;
                                    hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Orange":
                                {
                                    MLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.MLT_Temp_Probe.Address = _probe.Orange.Address;
                                    hardwareSettings.MLT_Temp_Probe.Color = _probe.Orange.Color;
                                    hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Pink":
                                {
                                    MLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.MLT_Temp_Probe.Address = _probe.YellowPink.Address;
                                    hardwareSettings.MLT_Temp_Probe.Color = _probe.YellowPink.Color;
                                    hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Orange":
                                {
                                    MLT_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.MLT_Temp_Probe.Address = _probe.YellowOrange.Address;
                                    hardwareSettings.MLT_Temp_Probe.Color = _probe.YellowOrange.Color;
                                    hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                                    break;
                                }
                        }
                        break;
                    }

                case "BK_Temp_Probe":
                    {
                        Probes _probe = new Probes();

                        switch (SelectedProbeColor)
                        {
                            case "Yellow":
                                {
                                    BK_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.BK_Temp_Probe.Address = _probe.Yellow.Address;
                                    hardwareSettings.BK_Temp_Probe.Color = _probe.Yellow.Color;
                                    hardwareSettings.BK_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Pink":
                                {
                                    BK_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.BK_Temp_Probe.Address = _probe.Pink.Address;
                                    hardwareSettings.BK_Temp_Probe.Color = _probe.Pink.Color;
                                    hardwareSettings.BK_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Orange":
                                {
                                    BK_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.BK_Temp_Probe.Address = _probe.Orange.Address;
                                    hardwareSettings.BK_Temp_Probe.Color = _probe.Orange.Color;
                                    hardwareSettings.BK_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Pink":
                                {
                                    BK_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.BK_Temp_Probe.Address = _probe.YellowPink.Address;
                                    hardwareSettings.BK_Temp_Probe.Color = _probe.YellowPink.Color;
                                    hardwareSettings.BK_Temp_Probe.IsConnected = true;
                                    break;
                                }

                            case "Yellow and Orange":
                                {
                                    BK_Temp_Probe = SelectedProbeColor;
                                    hardwareSettings.BK_Temp_Probe.Address = _probe.YellowOrange.Address;
                                    hardwareSettings.BK_Temp_Probe.Color = _probe.YellowOrange.Color;
                                    hardwareSettings.BK_Temp_Probe.IsConnected = true;
                                    break;
                                }
                        }
                        break;
                    }
            }

            Messenger.Default.Send<NotificationMessage>(new NotificationMessage("CloseAnalogPinDialog"), "WindowOperation");
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage("CloseDigitalPinDialog"), "WindowOperation");
            Messenger.Default.Send<NotificationMessage>(new NotificationMessage("CloseProbeColorsDiaglog"), "WindowOperation");
        }
        private void saveSettingClickCommand()
        {
            // Verify if pin configuration is possible (no multiple assignation)
            //To implement

            // Save Temperature Probes
            Probes _probe = new Probes();

            switch (HLT_Temp_Probe)
            {
                case "Yellow":
                    {
                        hardwareSettings.HLT_Temp_Probe.Address = _probe.Yellow.Address;
                        hardwareSettings.HLT_Temp_Probe.Color = _probe.Yellow.Color;
                        hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Pink":
                    {
                        hardwareSettings.HLT_Temp_Probe.Address = _probe.Pink.Address;
                        hardwareSettings.HLT_Temp_Probe.Color = _probe.Pink.Color;
                        hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Orange":
                    {
                        hardwareSettings.HLT_Temp_Probe.Address = _probe.Orange.Address;
                        hardwareSettings.HLT_Temp_Probe.Color = _probe.Orange.Color;
                        hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Pink":
                    {
                        hardwareSettings.HLT_Temp_Probe.Address = _probe.YellowPink.Address;
                        hardwareSettings.HLT_Temp_Probe.Color = _probe.YellowPink.Color;
                        hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Orange":
                    {
                        hardwareSettings.HLT_Temp_Probe.Address = _probe.YellowOrange.Address;
                        hardwareSettings.HLT_Temp_Probe.Color = _probe.YellowOrange.Color;
                        hardwareSettings.HLT_Temp_Probe.IsConnected = true;
                        break;
                    }
            }

            _probe = new Probes();

            switch (MLT_Temp_Probe)
            {
                case "Yellow":
                    {
                        hardwareSettings.MLT_Temp_Probe.Address = _probe.Yellow.Address;
                        hardwareSettings.MLT_Temp_Probe.Color = _probe.Yellow.Color;
                        hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Pink":
                    {
                        hardwareSettings.MLT_Temp_Probe.Address = _probe.Pink.Address;
                        hardwareSettings.MLT_Temp_Probe.Color = _probe.Pink.Color;
                        hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Orange":
                    {
                        hardwareSettings.MLT_Temp_Probe.Address = _probe.Orange.Address;
                        hardwareSettings.MLT_Temp_Probe.Color = _probe.Orange.Color;
                        hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Pink":
                    {
                        hardwareSettings.MLT_Temp_Probe.Address = _probe.YellowPink.Address;
                        hardwareSettings.MLT_Temp_Probe.Color = _probe.YellowPink.Color;
                        hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Orange":
                    {
                        hardwareSettings.MLT_Temp_Probe.Address = _probe.YellowOrange.Address;
                        hardwareSettings.MLT_Temp_Probe.Color = _probe.YellowOrange.Color;
                        hardwareSettings.MLT_Temp_Probe.IsConnected = true;
                        break;
                    }
            }

            _probe = new Probes();

            switch (BK_Temp_Probe)
            {
                case "Yellow":
                    {
                        hardwareSettings.BK_Temp_Probe.Address = _probe.Yellow.Address;
                        hardwareSettings.BK_Temp_Probe.Color = _probe.Yellow.Color;
                        hardwareSettings.BK_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Pink":
                    {
                        hardwareSettings.BK_Temp_Probe.Address = _probe.Pink.Address;
                        hardwareSettings.BK_Temp_Probe.Color = _probe.Pink.Color;
                        hardwareSettings.BK_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Orange":
                    {
                        hardwareSettings.BK_Temp_Probe.Address = _probe.Orange.Address;
                        hardwareSettings.BK_Temp_Probe.Color = _probe.Orange.Color;
                        hardwareSettings.BK_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Pink":
                    {
                        hardwareSettings.BK_Temp_Probe.Address = _probe.YellowPink.Address;
                        hardwareSettings.BK_Temp_Probe.Color = _probe.YellowPink.Color;
                        hardwareSettings.BK_Temp_Probe.IsConnected = true;
                        break;
                    }

                case "Yellow and Orange":
                    {
                        hardwareSettings.BK_Temp_Probe.Address = _probe.YellowOrange.Address;
                        hardwareSettings.BK_Temp_Probe.Color = _probe.YellowOrange.Color;
                        hardwareSettings.BK_Temp_Probe.IsConnected = true;
                        break;
                    }
            }

            // Send the new hardwaresettings to the arduinoCommands Class
            Messenger.Default.Send<HardwareSettings>(hardwareSettings, "HardwareSettingsUpdate");

            // Close the hardware settings window
            Messenger.Default.Send<NotificationMessageAction>(new NotificationMessageAction("CloseHardwareSettings", CloseHardwareSettings_CallBack), "WindowOperation");
        }