TODO
2 ways:
Rendered link: https://flexibitworkshoptool-28j3.onrender.com/
If want to run on local machine ( for tests during development)
git clone https://github.com/xinyue-ash/FlexibitWorkshopTool.git
cd ardublockly
git submodule update --init --recursive
(the last command will run for a while, please allow enough time for it to finish, so that the submodule will be download in “closure-libaray” folder)
python ./start.py
. And go to http://127.0.0.1:5000/ in your browserA nice example from the original repo \build\blocks\groove or existing categories \build\blocks\Customization etc
Folder Setup for Categories To add a new category, follow these steps: 1) Create a Category Folder Navigate to \build\blocks\ and create a folder named after your desired category. This category name will appear in the menu (e.g., “Customization” or “Preset Behaviors”).
2) Inside the newly created category folder, include the following files:
To define a block:
Go to \build\blocks
.appendField()
Blockly.Blocks["block_123"] = {
init: function() {
// Block definitions go here
}
};
Define Code generator:
To generate Arduino code for your block:
Go to \build\blocksblock_123
should match the one in block defination) )
Blockly.Arduino[“block_123”]= function (block){
// add your code converter logic here
}
Add blocks' XML defination the Toolbox:
To add your blocks to the toolbox, update the following files with the necessary XML configurations:
_\Ardublockly\ardublocklytoolbox.js (as an XML string).
💡 If a block definition already exists in another category
You only need to add XML in the toolbox, there is no need to add block defination and code generator for this block in current catogory.💡 If you want to change a Category name:
If you want to change a category name, you need to change thecategoryName
,toolboxName
field, and theid
andname
attributes in the<category>
tag.
Test Changes:
Run python ./start.py
. And go to http://127.0.0.1:5000/ in your browser.
For your changes to take effect, perform a hard refresh:
F12
.flask
: the deloyment branch, everything pushed into this branch will automatically deloyed to Render server.master
: has all the up-to-data code, serve as a back-up branch for flask (deployment branch)Sample Arduino Sketch is in \Hardware\MultiControWithDelay.ino
A Target
struct stores the configuration a the atomic behavior. There are two kinds of configuration
A Sequence
is a sequence of one or more atomic behavior that defined by corresponding Target
struct
ServoController
Class
Manages behavior and states for each servo. Initialized with arrays of Target
, Sequence
, and Servo
instances and other state variables
Attach()
Update()
StartNewSequence()
SetRepeats()
ResetSequence()
setAngleDuration()
setAngleSpeed()
addDelayDuration()
addTargetToSequence()
:bulb: Tip: One ServoController is initialized for EACH servo.
This block initializes Target, Sequence, ServoControllers, and Arduino’s setup() and loop() methods. It also instantiates three ServoControllers:
The conversion logic for this block is in: _\build\blocks\Customization\generator_arduino.js
Blockly.Arduino['multi_servo_control']
)_Note: The block replaces __SERVO_PIN__
with the actual pin number when a behavior block is placed in a Flexibit slot.
These helper functions can be encapsulate in servo behavior blocks in _generatorarduino.js :
.setAngleDuration(int angle, int duration)
Move the servo to a specified angle over a duration (ms)..setAngleSpeed(int angle, int speed)
Move the servo to a specified angle at a speed (1 = slow, 10 = fast)..StartNewSequence()
Start a behavior sequence (must be called before setAngleDuration
or setAngleSpeed
)..SetRepeats(int repeatTime)
Set how many times the sequence will repeat (called after setAngleDuration
or setAngleSpeed
)..addDelayDuration(int duration)
Stop the servo for a specified duration (ms).Note: The servo reference inside the block must use the pattern servo__SERVO_PIN__
to allow the purple wrapper block to replace __SERVO_PIN__
with the correct pin number.
This project has been modified from https://github.com/carlosperate/ardublockly.
Blockly original source is Copyright of Google Inc. [https://developers.google.com/blockly/][1]. A list of changes to the Blockly fork can be found in the [Blockly subdirectory README][17] file.
Copyright (c) 2016 carlosperate https://github.com/carlosperate/
Unless stated otherwise, the source code of this projects is licensed under the Apache License, Version 2.0 (the "License"); you may not use any of the licensed files within this project except in compliance with the License.
The full document can be found in the [LICENSE][9] file.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.