public ActionResult Post([FromBody] string value) { try { SmokerMode newMode = (SmokerMode)Enum.Parse(typeof(SmokerMode), value, true); bool success = _smoker.SetMode(newMode); if (!success) { return(StatusCode(403)); } return(Accepted()); } catch { return(BadRequest()); } }
private async Task FireMinderLoop() { Debug.WriteLine("Starting Fire Minder thread."); while (true) { try { if (_smoker.Mode.IsCookingMode() && _smoker.Temps.GrillTemp < _ignitionTemp && !_fireStarted) { if (!_igniter.IsOn) { _igniter.On(); _igniterOnTime = DateTime.Now; } } else { _igniter.Off(); } if (_igniter.IsOn && DateTime.Now - _igniterOnTime > _igniterTimeout) { string errorText = "Igniter timeout. Setting error mode."; Debug.WriteLine(errorText); Console.WriteLine(errorText); _igniter.Off(); _smoker.SetMode(SmokerMode.Error); } if (_smoker.Mode.IsCookingMode()) { if (_smoker.Temps.GrillTemp >= _ignitionTemp) { _fireStarted = true; } if (_fireStarted && _smoker.Temps.GrillTemp < GetFireCheckTemp() && !_fireCheck) { _fireCheck = true; _fireCheckTime = DateTime.Now; } else if (_fireCheck && _smoker.Temps.GrillTemp >= GetFireCheckTemp()) { _fireCheck = false; } else if (_fireCheck && DateTime.Now - _fireCheckTime > _fireTimeout) { string errorText = "Fire timeout. Setting error mode."; Debug.WriteLine(errorText); Console.WriteLine(errorText); _smoker.SetMode(SmokerMode.Error); } } await Task.Delay(TimeSpan.FromSeconds(1)); } catch (Exception ex) { string errorText = $"Fire Minder loop exception! {ex} {ex.StackTrace}"; Console.WriteLine(errorText); Debug.WriteLine(errorText); } } }