Creating New Blocks in BIPES
You are able to create custom blocks for your toolbox in BIPES.
Here is a link to the official documentation regarding the creation of new blocks:
https://bipes.net.br/docs/get-started/create-block.html
The following is a simplified tutorial for creating a new block for your BIPES toolbox.
Step 01: Block Definition
- Open up the Blockly Block Factory in a browser: https://blockly-demo.appspot.com/static/demos/blockfactory/index.html
- Create the desired connections for your new block using Block Factory.
- Go to Block Definition and select JavaScript.
- Copy the code stub located in that section.
- Navigate to the file BIPES-offline-master/ui/core/block-definitions.js and open it.
- Paste in the copied code stub at the bottom of this file.
NOTE: ENSURE THAT THE NAME OF YOUR BLOCK IS CONSISTENT FOR ALL OF THE STEPS!!!
Step 02: Generator Stub
- In the Block Factory, go to Generator Stub and select Python.
- Copy the code stub located in that section.
- Navigate to the file BIPES-offline-master/ui/core/generator-stubs.js and open it.
- Paste in the copied code stub at the bottom of this file.
- Inside
var code = '...\n';
, paste in the micropython code you want your custom block to run.
Reference the existing blocks in the file if you are making a complex custom block. Good luck! - Change
python.pythonGenerator.forBlock
toBlockly.Python
!!! This is an important step!
Step 03: Add to Toolbox
- Navigate to the file BIPES-offline-master/ui/toolbox/BOARD_NAME.xml* where BOARD_NAME is the board you want to add your block to its toolbox and open it.
- Create a category for your custom blocks by pasting in
<category name="CATEOGRY_NAME"><category/>
into this .xml file.
Your custom category can go anywhere, but ensure you are within the parent<xml><xml/>
tags. - Paste
<block type="BLOCK_NAME"></block>
within your custom category tag.
Ensure that BLOCK_NAME matches the name of your block as defined in the Block Definition and Generator Stub.
Step 04: Remake
- Open up a terminal and navigate to the BIPES-offline-master directory.
- Run
make offline
in this directory. - Once completed, the file BIPES-offline-master/ui/index_offline.html should be updated with your custom blocks (make sure you have the correct board selected).
This concludes a brief summary of how to create custom toolbox blocks for a board in BIPES.
Now, try to make some custom blocks on your own! Good luck!