Exemple #1
0
        public async Task Should_start_print_successfully()
        {
            _fakeMigo
            .ReplyMode(FakeMigoMode.RequestReply)
            .ReplyPrintStarted(_gCodeFileName);

            var result = await _migo.StartPrint(GCodeFile)
                         .ConfigureAwait(false);

            result.PrintStarted.Should().BeTrue();
            result.Success.Should().BeTrue();
        }
Exemple #2
0
        public async Task <StartPrintResult> Execute(CancellationToken token)
        {
            _logger.LogInformation($"Executing scenario {nameof(PreheatAndPrint)}");
            if (_preheat.HasValue)
            {
                var preheat = _preheat.Value;
                _logger.LogInformation($"Preheating bed to {preheat.ToString("F0")}...");

                await SetBedTemperature(preheat)
                .ConfigureAwait(false);

                CancellationCheck(token);

                var cts = new CancellationTokenSource();

                double lastReportedTemperature = 0.0;
                double reportThreshold         = 30;

                await foreach (var state in _migo.GetStateStream(cts.Token))
                {
                    CancellationCheck(token);

                    double temperature = state.BedTemp;
                    if (state.BedTemp > preheat - Tolerance)
                    {
                        cts.Cancel();
                    }

                    if (temperature - lastReportedTemperature < reportThreshold)
                    {
                        continue;
                    }

                    double target = preheat - Tolerance;
                    _logger.LogInformation($"{temperature.ToString("F0")} of {target.ToString("F0")}");
                    lastReportedTemperature = temperature;

                    if (temperature > 100)
                    {
                        reportThreshold = 5;
                    }
                }

                _logger.LogInformation("Preheating completed");
            }

            _logger.LogInformation($"Starting print of {_fileName} ...");

            CancellationCheck(token);

            var result = await _migo.StartPrint(_fileName)
                         .ConfigureAwait(false);

            _logger.LogInformation("Scenario completed");

            return(result);
        }