Bake Mate - Pi Chef Blog #7 - Code Prep
Status Update:
I got back to working on the software, which is something I've been avoiding the past few weeks (I got distracted with the hardware!). I made pretty significant progress over the past few days, and I hope to get it working over the upcoming weekend. Once that is done, I'll focus on making the GUI nicer, and then move on to implementing more features.
Software:
Picking up from where I last left off (Bake Mate - Pi Chef Blog #3 - RPi3 setup & recipe JSON format), I did a lot more work on the Python application & figured out how I'll be integrating everything together.
Here's the plan:
This ended up being a lot more complicated than I originally envisioned at the time of my application, and is definitely the largest Python application ever built in the history of the universe by me, but it's been a fun & learning experience.
As I mentioned in Blog Post 3, the recipes are stored in a particular format in .json files, and are parsed accordingly.
Start Page:
This one is the simplest of all, and just contains a splash screen.
Menu Page:
This one isn't really needed at this point because I haven't started working on the part that lets the user create a recipe, which I hope to do soon. For now, the user presses on the button to "View Recipes"
Select Recipe
This page displays a list of all the recipes in the folder, along with a short description of the selected recipe.
Scale Page:
After selecting the recipe, the user gets an option to scale the quantity. The application will automatically handle the 'new' weights of every ingredient, which makes everything easier.
When this page is displayed, a Python module called "thisRecipe" gets initialized with a bunch of values which will be used to keep track of the progress as the recipe progresses. This module will be used as a global variable that can be accessed by all the classes (which contain data for each page of the GUI).
#thisrecipe.py file="s" name = "default name" description = "default description" scale_factor = 1.0 #default values, which get overwritten with values from the actual recipe servings = 14 cooktime = 14 nsteps = 1 cur_step = 0 zero_weight = 0; weight_done = 0; step_weight_to_add = 0; cur_step_type = "" next_step_type = ""
Now that the first few pages are done, we move on to the pages that will actually display each step of the recipe.
I've broken the steps down into the 4 more probable types: add measurable ingredient, add non-measurable ingredient, do (basic instructions like mixing etc.) & bake. These should be sufficient for baking, and I could always add more types if I ever encounter a recipe that needs it.
Each page will have a unique GUI and backend. The page for "add measureable ingredient" will need to access the data from the weighing scale using the HX711 library which I've already covered and tested, and the page for "bake " will contain a timer and will need to access oven temperature using the MAX31856 library. Each of these pages will also need to parse the required data from the step in the JSON file: weight or temperature. Naturally, all four of these pages have been designed as templates so that they can be reused: at each step the required data is parsed and displayed in the respective field.
To keep track of each step, I use variables that are declared in thisrecipe.py. Since the four 'step' pages might be required in any random order (since it depends entirely on the recipe), I decided to implement it in a manner that certain tasks are performed when the particular page is first called (the enter tasks) and when it is left (the exit tasks).
The first time a page is invoked, it'll look at the current instruction number (in thisrecipe.py) and parse the required data from that particular step (weight, text etc.).
Once the task of the page is done, the user presses on the "Next" button, which executes the exit tasks. The exit tasks basically increment the value of cur_step, and parse the instruction type of the next (upcoming step) from the JSON file. If the next step is a "addm", the next page that is called is of the "add measureable " type; if it is a "do", the next page will be a "do" type; and so on.
Have a look at the block diagram: the order in which the pages are invoked depends entirely on the recipe, and at the end of every step, the next page type is determined, and automatically invoked. Throughout the process, thisRecipe.py is used to keep track of the current step. Another parameter that needs to be tracked is the weight detected on the weighing scale so that the weight at each step can be calculated (similar to how tare works).
Here are the screen captures: the StartPage, the MenuPage, Select Recipe & Scale Page, Add Measureable Ingredient & The Bake Page:
Top Comments