Andy Hernandez
Published © MIT

Automatic Pressure Cooker

Automatic Pressure Cooker For Those Who Never Cooked Before

AdvancedShowcase (no instructions)Over 4 days2,613
Automatic Pressure Cooker

Things used in this project

Story

Read more

Schematics

Don't Try This at Home!

This project deals with high amperage and high voltage, no schematics will be provided at this time. Email your request to RobotsAreCooking@Gmail.Com

Code

Public Class LetsCook

C#
This class is responsible for the entire cooking process. On every step the code looks at the SQLite Database for instructions, Images, Text-To-Speech and Ingredients.
using Windows.UI.Xaml.Controls;
using PuchyPot.Infrastructure.Services;
using PuchyPot.Infrastructure.VM;
using PuchyPot.Boards;
using Windows.UI.Xaml;
using Windows.Globalization;
using System.ComponentModel;
using Windows.ApplicationModel.Resources;
using System;
using Windows.Media.SpeechSynthesis;
using Windows.UI.Popups;
using Windows.UI.Xaml.Navigation;
using System.Diagnostics;


namespace PuchyPot.Pages
{
    public sealed partial class LetsCook : Page
    {
        private int _index;
        RecipeViewModel rec;
        DispatcherTimer stepTimer;
        DispatcherTimer cookTimer;

        int stepSecondsRemained;
        int waitingSecondsRemained;
        int cookSecondsRemained;
        string stepTimeString;
        string cookTimeString;

        bool speechEnded = true;
        VoiceInformation voice = TTS.GetFemaleVoiceForCulture(ApplicationLanguages.PrimaryLanguageOverride, ((App)Application.Current).Voice);

        FezBoard board = ((App)Application.Current).GetBoard();

        ResourceLoader resourceLoader = new ResourceLoader();
        public StepInfo TheStep;
        public class StepInfo : INotifyPropertyChanged
        {
            CookingProcessViewModel _current = null;
            public event PropertyChangedEventHandler PropertyChanged;
            public void OnPropertyChanged(string propertyName)
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }

            public CookingProcessViewModel Current { get { return _current; } set { _current = value; OnPropertyChanged("Current"); OnPropertyChanged("Image"); } }
        }
        public int Index
        {
            get
            {
                return _index;
            }
            set
            {
                _index = value;
                TheStep.Current = rec.Steps[value - 1];

                if (TheStep.Current.isCookedByPressure)
                {
                    board.setPointPid = 0.999f;
                }
                else
                {
                    board.setPointPid = (float)TheStep.Current.Temperature;
                }
                board.pidController.ControllerMode = ControllerMode.Automatic;

                txtCurrentStep.Text = string.Format(resourceLoader.GetString("StepCountTextBlock"), value, rec.Steps.Count);
                SpeakMessage(TheStep.Current.InStepText);
                stepTimer.Stop();
                stepSecondsRemained = int.Parse(TheStep.Current.CookTime) * 1;
                waitingSecondsRemained = stepSecondsRemained;
                stepTimer.Start();
            }
        }
        private async void SpeakMessage(string content)
        {
            using (var speech = new SpeechSynthesizer())
            {
                speech.Voice = voice;
                SpeechSynthesisStream stream = await speech.SynthesizeTextToStreamAsync(content);
                mediaElement.Stop();
                mediaElement.SetSource(stream, stream.ContentType);
                mediaElement.Play();
            }
        }

        public LetsCook()
        {
            this.InitializeComponent();
            Loaded += LetsCook_Loaded;

            TheStep = new StepInfo();
            DataContext = TheStep;
            cookTimer = new DispatcherTimer();
            stepTimer = new DispatcherTimer();
            cookTimer.Interval = new TimeSpan(0, 0, 1);
            stepTimer.Interval = new TimeSpan(0, 0, 1);
            cookTimer.Tick += CookTimer_Tick;
            stepTimer.Tick += StepTimer_Tick;
            stepTimeString = resourceLoader.GetString("MinutesLeftOnThisStep");
            cookTimeString = resourceLoader.GetString("MinutesLeftToFinishThisRecipe");
            mediaElement.MediaEnded += MediaElement_MediaEnded;
            mediaElement.MediaOpened += MediaElement_MediaOpened;
        }
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            ((App)Application.Current).AppFlagIsPotCooking = false;
        }
        private void MediaElement_MediaOpened(object sender, RoutedEventArgs e)
        {
            speechEnded = false;
        }

        private void MediaElement_MediaEnded(object sender, RoutedEventArgs e)
        {
            speechEnded = true;
        }

        void UpdateUI()
        {
            textBoxSetPointPid.Text = board.setPointPid.ToString("P2");
            textBoxAnalogPinA1RawValue.Text = board.analogPinA1RawValue.ToString("P2");
            textBoxActualPWM.Text = board.actualPWM.ToString("P2");
            textBoxHardwarePressureSwitch.Text = board.hardwarePressureSwitch.ToString();
        }

Credits

Andy Hernandez

Andy Hernandez

1 project • 1 follower

Comments