コード例 #1
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        private async void Stop_Click(object sender, RoutedEventArgs e)
        {   //Send the stop command and save sample data to a csv file
            Stop.IsEnabled = false;
            Status.Text    = (await Oven.Stop()).ToString();

            try
            {
                var filename = $"{DateTime.Now:yyyy-MM-dd HHmmss}.csv";
                var file     = await DownloadsFolder.CreateFileAsync(filename);

                var lines = new List <string> {
                    "RealTime,RecipeTime (s),Temperature (°C),Ambient Temp (°C),Set Power (W)"
                };
                foreach (var sample in SampleData)
                {
                    lines.Add($"{sample.RealTime:yyyy-MM-dd HH:mm:ss},{sample.Time},{sample.Temperature},{sample.Ambient},{sample.Power}");
                }
                await FileIO.WriteLinesAsync(file, lines);

                await CachedFileManager.CompleteUpdatesAsync(file);
            }
            catch (Exception x)
            {
                await ShowError($"Error saving data file:{Environment.NewLine}{x.Message}");
            }

            Stop.IsEnabled = true;
        }
コード例 #2
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
 private async void Start_Click(object sender, RoutedEventArgs e)
 {   //Send Start command to oven
     Start.IsEnabled = false;
     Status.Text     = (await Oven.Start()).ToString();
     SampleData.Clear();
     Start.IsEnabled = true;
 }
コード例 #3
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        /*Operations*/
        private async void SamplePoll_Tick(object sender, object e)
        {   //Periodically poll for current data
            //Get current sample
            Sample sample = await Oven.GetCurrentSample();

            UpdateSampleUI(sample);

            //Add sample to graph
            if (sample != null)
            {
                SampleData.Add(sample);
            }

            //Get the oven's current status code
            var status = await Oven.GetStatus();

            if (status == OvenStatus.NotConnected && Oven.ErrorMessage != null)
            {
                Status.Text = Oven.ErrorMessage;
            }
            else
            {
                Status.Text = status.ToString();
            }
        }
コード例 #4
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        private async void RefreshPID_Click(object sender, RoutedEventArgs e)
        {   //Get Oven's current PID coefficients
            RefreshPID.IsEnabled = false;
            PID psoc = await Oven.GetPID();

            POven.Text           = psoc.Proportional.ToString();
            IOven.Text           = psoc.Integral.ToString();
            DOven.Text           = psoc.Derivative.ToString();
            RefreshPID.IsEnabled = true;
        }
コード例 #5
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        private async void SendAmbient_Click(object sender, RoutedEventArgs e)
        {   //Send set ambient temperature to the oven
            SendAmbient.IsEnabled = false;

            if (await Oven.SetAmbient(Ambient.ValueFloat()))
            {
                await ShowSuccess("Ambient temperature sent successfully.");
            }
            else
            {
                await ShowError($"Ambient temperature failed to send.{(Oven.ErrorMessage != null ? Environment.NewLine + Oven.ErrorMessage : "")}");
            }

            SendAmbient.IsEnabled = true;
        }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        /*Main Page*/
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            //Select the first step in the Recipe editor
            StepSelector.SelectedIndex = 0;

            //Get current oven status
            var status = await Oven.GetStatus();

            Status.Text = status.ToString();

            //Restart if the oven tells us to
            if (status == OvenStatus.NeedRestart)
            {
                ShutdownManager.BeginShutdown(ShutdownKind.Restart, TimeSpan.Zero);
                return;
            }

            //Start sample timer
            SamplePoll.Start();

            //Look for recipe files and populate recipe list
            var files = (await LocalFolder.GetFilesAsync())
                        .Where(x => x.Name.EndsWith(RecipeFilenameExtension));

            if (files.Any())
            {
                foreach (var filename in files
                         .Select(x => x.Name.Remove(x.Name.Length - RecipeFilenameExtension.Length)))
                {
                    RecipeFiles.Add(filename);
                }
            }

            //Read PID coefficients from stored settings
            if (Settings.ContainsKey(nameof(PID)) && Settings[nameof(PID)] is string pidString)
            {
                var pid = PID.FromString(pidString);
                PInput.Value = pid.Proportional;
                IInput.Value = pid.Integral;
                DInput.Value = pid.Derivative;
                SendPID_Click(this, new RoutedEventArgs());
            }
        }
コード例 #7
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        /*PID*/
        private async void SendPID_Click(object sender, RoutedEventArgs e)
        {   //Send PID coefficients to Oven
            SendPID.IsEnabled = false;

            PID hmi  = (PInput.ValueFloat(), IInput.ValueFloat(), DInput.ValueFloat());
            PID psoc = await Oven.SetPID(hmi);

            if (psoc == hmi)
            {
                POven.Text = psoc.Proportional.ToString();
                IOven.Text = psoc.Integral.ToString();
                DOven.Text = psoc.Derivative.ToString();
                await ShowSuccess("PID updated successfully");

                Settings[nameof(PID)] = psoc.ToString();
            }

            SendPID.IsEnabled = true;
        }
コード例 #8
0
ファイル: MainPage.xaml.cs プロジェクト: bauerslab/Oven
        private async void SendRecipe_Click(object sender, RoutedEventArgs e)
        {   //Send the current recipe to the oven
            SendRecipe.IsEnabled = false;
            if (Recipe.Steps.Count < MinSteps)
            {
                await ShowError($"Recipe has too few steps. Minimum is {MinSteps}.");

                SendRecipe.IsEnabled = true;
                return;
            }

            if (await Oven.SetRecipe(Recipe))
            {
                await ShowSuccess("Recipe sent successfully.");
            }
            else
            {
                await ShowError($"Recipe failed to send.{(Oven.ErrorMessage != null ? Environment.NewLine + Oven.ErrorMessage : "")}");
            }
            SendRecipe.IsEnabled = true;
        }