예제 #1
0
        private async Task PIDTask()
        {
            var pid = new PIDController(
                (float)BrewProfileSettings.Instance.PIDKp,
                (float)BrewProfileSettings.Instance.PIDKi,
                (float)BrewProfileSettings.Instance.PIDKd,
                100f,
                0f);

            long previousMillisec = StartupTimer.Instance.Millis();

            while (IsRunning)
            {
                if (CurrentStep == null)
                {
                    await Task.Delay(10);

                    continue;
                }

                bool isBoiling = CurrentStep.Type == Objects.StepType.Boil;

                pid.SetPoint        = (float)CurrentStep.Temperature;
                pid.ProcessVariable = (float)TemperatureController.Instance.Controller.Temperature;
                float output = pid.ControlVariable(StartupTimer.Instance.Millis() - previousMillisec);
                previousMillisec = StartupTimer.Instance.Millis();

                //Check the output and see if we need to trigger the heater on or off
                if (output >= 100 || isBoiling)
                {
                    _ssrHeaterHandler.Switch(SSRState.On);
                }
                else
                {
                    _ssrHeaterHandler.Switch(SSRState.Off);
                }

                if (Utilities.IsDesktopComputer())
                {
                    (TemperatureController.Instance.Controller as TemperatureSensorMock)?
                    .MockMode(_ssrHeaterHandler.State == SSRState.On ? SensorMockMode.Increase : SensorMockMode.Decrease);
                }

                //Debug.WriteLine($"PID output: {output}, temperature: {pid.SetPoint}");

                await Task.Delay(500);
            }
        }
예제 #2
0
        public void ActivateBuzzer(CancellationToken cancelToken)
        {
            if (IsBuzzing || _buzzerHandler == null)
            {
                return;
            }

            new Task(async() =>
            {
                IsBuzzing = true;
                _buzzerHandler.Switch(SSRState.On);
                await Task.Delay(5000, cancelToken);
                _buzzerHandler.Switch(SSRState.Off);
                IsBuzzing = false;
            }).Start();
        }
예제 #3
0
        public void Pump()
        {
            if (_ssrPumpHandler == null)
            {
                _ssrPumpHandler = new SolidStateRelayHandler(BrewProfileSettings.Instance.SSRPumpGPIO);
            }

            _ssrPumpHandler?.Switch();
        }