Exemplo n.º 1
0
        public async void Start(IPidRepository pidRepo)
        {
            _pidRepo = pidRepo;
            Log.Debug($"{DateTime.Now}: Starting Worker");
            _pid0 = new PID(0, "Pid 1", _brewIO, Outputs.Pid1Output, _pidRepo);
            _pid1 = new PID(1, "Pid 2", _brewIO, Outputs.Pid2Output, _pidRepo);
            while (true)
            {
                await Task.Run(() =>
                {
                    var newTemp = _tempReader.ReadTemp();
                    _pid0.Calculate(newTemp);
                    _pid1.Calculate(newTemp);

                    _hubContext.Clients.All.SendAsync("HarwareStatus", new HardwareStatusDto
                    {
                        Pids          = new [] { _pid0.Status, _pid1.Status }.ToArray(),
                        ComputedTime  = DateTime.Now,
                        ManualOutputs = _brewIO.SupportedOutputs.Where(x => !x.Automatic).ToArray()
                    });

                    System.Threading.Thread.Sleep(500);
                });
            }
        }
Exemplo n.º 2
0
        public PID(int pidId, string pidName, BrewIO brewIO, Outputs output, IPidRepository pidRepo)
        {
            _pidId   = pidId;
            _pidName = pidName;
            _brewIO  = brewIO;
            _output  = output;
            _heater  = new HeaterController(_brewIO, output);
            _heater.Start();

            PidConfig = pidRepo.GetPidConfig(pidId);
            if (PidConfig == null)
            {
                PidConfig = new PidConfig
                {
                    PidId = pidId,
                    PIDKp = DefaultPIDKp,
                    PIDKi = DefaultPIDKi,
                    PIDKd = DefaultPIDKd
                };
                pidRepo.AddPidConfig(PidConfig);
            }

            _pidRegulator = new PIDRegulator3(PidConfig.PIDKp, PidConfig.PIDKi, PidConfig.PIDKd);
            Status        = new PidStatusDto
            {
                PidId   = _pidId,
                PidName = _pidName
            };
        }