Recipe Mode Update #141
nebhead
started this conversation in
Show and tell
Replies: 2 comments
-
The development commit is here: 6e13eb6 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Recipe Architecture
This information is being provided to help anyone who might be interested, understand the current state of recipe mode and how it is implemented. It is very much under construction, and the WebUI has not been updated to include support for this mode yet.
File Changes for Recipe Support as of 11/11/2022
The following are the high level changes made to the different files to implement Recipe Mode.
control.py
In the main control loop, if control['mode'] = 'Recipes', goto to Recipe Function (_recipe_mode).
In _recipe_mode function:
4a. Setup all step data and write to control
4b. Start the recipe step by launching a _work_cycle
4c. If reignite is required, run a reignite cycle and retry current step
4c-2. Rerun current step
4d. If another mode was requested (or an error occurred) then exit recipe mode
4e. Continue to next step number
In _work_cycle function:
Pre-Loop:
Inside Loop:
End of Loop:
notifications.py
In check_notify():
In build_notification():
app.py
Moved cookfile/recipe file functions to separate python files for code re-use and easier management.
display_base_240x320.py
Running a Recipe
Running a recipe only requires the following control updates:
This is currently not implemented in the WebUI, so running a recipe currently requires either launching from the 'redis-cli' application or some other redis-db viewer (for test, I'm using RESP.app GUI for Redis on Ubuntu).
Pifire should run through the pre-programmed steps as instructed. If a pause is requested in a step, the step will continue to run as normal waiting for control['recipe']['step_data']['pause'] = false before continuing to the next step.
Other Important Notes
When building out the UI, it should take into account the following:
Recipe File Format v1.0.0
Uses a very similar format to the cookfile format such that many of the same functions can be re-used to manage the file. In fact, the cookfile functions that are shared, have been moved into new module files to both simplify the implementation and to share code. The below is a quick review of the new files that have been created to support both the cook file and recipe file formats.
file_common.py
read_json_file_data(filename, jsonfile, unpackassets) - Read a JSON file out of the compressed file. Also unpacks the assets when reading an asset JSON file, into a temporary folder.
update_json_file_data(filedata, filename, jsonfile) - Writes a specific JSON file back to the compressed file. Used to update specific JSON file in the compressed file structure. Cannot be used to update assets (images) in the file.
fixup_assets(filename, jsondata) - This function is used to fix missing or incorrect assets in the compressed file. Used if a file gets corrupted somehow.
file_cookfile.py
create_cookfile(historydata) - Creates a brand new cookfile and puts this into the history folder.
read_cookfile(filename)- Reads all JSON files in the compressed file and places those into a larger JSON structure. Also unpacks the assets into a temporary folder.
upgrade_cookfile(cookfilename) - Updates the compressed file to the newer format.
file_recipes.py
create_recipefile() - Creates a brand new recipe file and puts this into the history folder.
read_recipefile(filename) - Reads all JSON files in the compressed file and places those into a larger JSON structure. Also unpacks the assets into a temporary folder.
convert_recipe_units(recipe, units) - Used to convert units in a recipe between imperial and metric.
file_media.py
add_asset(filename, assetpath, assetfile) - Add an asset (image) to a compressed file.
rotate_image(filepath, asset_id, filetype) - Rotate an image (if needed) using EXIF data of the image.
create_thumbnail(filepath, asset_id, filetype, crop) - Create a smaller thumbnail image from the uploaded full size image.
set_thumbnail(filename, thumbfilename) - Set a thumbnail image in metadata JSON of the compressed file.
unpack_thumb(thumbname, filename) - Function used to uncompress the thumbnail only for a specific compressed file into a temporary folder. Used to display thumbs in a filelist without having to unpack ALL assets.
Compression
PiFire uses the standard pyzipfile module to compress and decompress files with the '.pfrecipe' extension. PiFire uses the standard ZIP compression method (using zip_deflated option in the python module).
File Structure
In broad strokes, the recipe file is a compressed zip formatted folder of files. The structure of the file looks like this:
Metadata
Recipe
['ingredients']
Human readable list of ingredients, with optional images.
['instructions']
Human readable list of instructions, with optional images.
['steps']
Machine readable list of steps for PiFire to follow for this recipe. Each step can have triggers, which will optionally fire a notification and optionally move to the next step in the list (unless pause is indicated). If no triggers and no pause is set, this step will continue until it completes (i.e. Startup & Shutdown) or will remain in that step until stopped/cancelled.
Comments
The comments file is used to store comments and notes about the recipe. This file may contain an empty list if no comments are added. (i.e. '[]')
assets: List of strings of filenames, of the images that are to be displayed with this comment. These images and their corresponding thumbnail images must be in the '/assets' and '/assets/thumbnails' folders.
date: String of the date that the comment was first entered. Format "YYYY-MM-DD".
edited: String of the date that the comment was edited last in the format "YYYY-MM-DD HH:MM".
id: (String) Unique ID for the comment.
rating: (float) [0-5] Scale for rating the recipe. (0.5 steps)
text: Raw string of the comment itself. The string can include line breaks with the '\n' null character.
time: String of the time the comment was first entered. Format "HH:MM".
username: (string) Username author of the comment.
Assets
The assets file stores pointers to all of the asset (image) files in the assets folder. If there are no assets in this file, the list may be empty (i.e. '[]'). Here is an example of the format.
filename: String of the filename for the asset/media that is stored in the '/assets' folder. [Required]
id: String of the unique id assigned to this asset. [Required]
type: String of the filetype for this asset. [Required]
Others notes about assets/media stored in the file.
Beta Was this translation helpful? Give feedback.
All reactions