Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e586dc7
a componentfieldvariable dropdown field that allows to filter
bmcage Apr 29, 2016
bb59cba
convert stepper to new componentfield
bmcage Apr 29, 2016
fc4cfee
step 2 stepper: generator
bmcage Apr 30, 2016
e258e1e
create a generic test if setup block of a component is present
bmcage Apr 30, 2016
8160857
Fix issues with menu generations: should be class method
bmcage Apr 30, 2016
64ff54a
Improvements: less code needed, better documentation
bmcage May 6, 2016
9494c22
Allow blocks to automatically set correct board.
bmcage May 5, 2016
4b68174
A warning message for blocks that set the board
bmcage May 5, 2016
30e234b
dutch translation of block
bmcage May 5, 2016
5dee899
Implementation of component block, starting with adaptation of the
bmcage May 7, 2016
deeff0d
Light components: normal LED leg and neopixel strip
bmcage May 8, 2016
61fbc59
servo as components
bmcage May 8, 2016
aa42403
component: new text strings
bmcage May 7, 2016
1910ef2
light translation strings
bmcage May 8, 2016
4d5bea2
servo component language strings
bmcage May 8, 2016
8437af2
Don't include strings of Blockly4Arduino
bmcage May 8, 2016
6fbf003
adaptation of GUI to expose the new blocks
bmcage May 8, 2016
a2da103
avoid double pinMode setting
bmcage May 9, 2016
834cbdf
Add generic analog sensor component
bmcage May 9, 2016
900eeab
reservePin must be done with numbers, not varnames
bmcage May 9, 2016
fb60ba4
component for a digital input
bmcage May 9, 2016
557b674
Add a button component, and a way to handle button presses
bmcage May 9, 2016
6bbd130
digital input translate strings
bmcage May 9, 2016
6106c34
add missing translation
bmcage May 9, 2016
b17babc
digital and pwm output components
bmcage May 9, 2016
9233d2b
bugfix: correct default pwm name
bmcage May 9, 2016
96a49d3
Update ardublockly GUI with the new components
bmcage May 9, 2016
8dbf15b
Language updates
bmcage May 9, 2016
4fea5df
bugfix: en translation
bmcage May 9, 2016
d43daf8
bugfix: correct remembering of pin blocks if mutator is changed
bmcage May 11, 2016
dabd7bf
bugfix: digitalread must be BOOLEAN
bmcage May 12, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions ardublockly/ardublockly_toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ Ardublockly.TOOLBOX_XML =
' <block type="math_number"></block>' +
' </value>'+
' </block>' +
' <block type="analogsensor_config_hub"></block>' +
' <block type="analogsensor_read"></block>' +
' <block type="digitalinput_config_hub"></block>' +
' <block type="digitalinput_read"></block>' +
' <block type="button_setup"></block>' +
' <block type="button_input"></block>' +
' <block type="digitaloutput_config_hub"></block>' +
' <block type="digitaloutput_write"></block>' +
' <block type="pwmoutput_config_hub"></block>' +
' <block type="pwmoutput_write"></block>' +
' </category>' +
' <sep></sep>' +
' <category id="catTime" name="Time">' +
Expand All @@ -172,6 +182,83 @@ Ardublockly.TOOLBOX_XML =
' <block type="infinite_loop"></block>' +
' </category>' +
' <sep></sep>' +
' <category id="catComponent" name="Components">' +
' <block type="core_hub_component"></block>' +
' <block type="led_config_hub"></block>' +
' <block type="neopixel_config_hub">' +
' <value name="NUMBER">' +
' <block type="math_number">' +
' <field name="NUM">1</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="analogsensor_config_hub"></block>' +
' <block type="digitalinput_config_hub"></block>' +
' <block type="button_setup"></block>' +
' <block type="digitaloutput_config_hub"></block>' +
' <block type="pwmoutput_config_hub"></block>' +
' <block type="servo_config_hub"></block>' +
' <block type="stepper_config_hub">' +
' <value name="STEPPER_STEPS">' +
' <block type="math_number">' +
' <field name="NUM">100</field>' +
' </block>' +
' </value>' +
' <value name="STEPPER_SPEED">' +
' <block type="math_number">' +
' <field name="NUM">10</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="led_digitalwrite_onoff"></block>' +
' <block type="led_digitalwrite">' +
' <value name="STATE">' +
' <shadow type="io_highlow"></shadow>' +
' </value>' +
' </block>' +
' <block type="neopixel_colourpick_write">' +
' <value name="LEDPIXEL">' +
' <block type="math_number">' +
' <field name="NUM">1</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="neopixel_colourpick_dim_write">' +
' <value name="LEDPIXEL">' +
' <block type="math_number">' +
' <field name="NUM">1</field>' +
' </block>' +
' </value>' +
' <value name="BRIGHTNESS">' +
' <block type="math_number">' +
' <field name="NUM">100</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="neopixel_write">' +
' <value name="LEDPIXEL">' +
' <block type="math_number">' +
' <field name="NUM">1</field>' +
' </block>' +
' </value>' +
' <value name="RED">' +
' <block type="math_number">' +
' <field name="NUM">255</field>' +
' </block>' +
' </value>' +
' <value name="GREEN">' +
' <block type="math_number">' +
' <field name="NUM">0</field>' +
' </block>' +
' </value>' +
' <value name="BLUE">' +
' <block type="math_number">' +
' <field name="NUM">0</field>' +
' </block>' +
' </value>' +
' </block>' +
' </category>' +
' <sep></sep>' +
' <category id="catMusic" name="Music">' +
' <block type="io_tone">' +
' <field name="TONEPIN">0</field>' +
Expand Down Expand Up @@ -214,6 +301,41 @@ Ardublockly.TOOLBOX_XML =
' </block>' +
' </value>' +
' </block>' +
' <block type="servo_config_hub"></block>' +
' <block type="stepper_config_hub">' +
' <value name="STEPPER_STEPS">' +
' <block type="math_number">' +
' <field name="NUM">100</field>' +
' </block>' +
' </value>' +
' <value name="STEPPER_SPEED">' +
' <block type="math_number">' +
' <field name="NUM">10</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="servohub_write">' +
' <value name="SERVO_ANGLE">' +
' <block type="math_number">' +
' <field name="NUM">90</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="servohub_write2">' +
' <value name="SERVO_SPEED">' +
' <block type="math_number">' +
' <field name="NUM">50</field>' +
' </block>' +
' </value>' +
' </block>' +
' <block type="servohub_read"></block>' +
' <block type="stepper_step">' +
' <value name="STEPPER_STEPS">' +
' <block type="math_number">' +
' <field name="NUM">10</field>' +
' </block>' +
' </value>' +
' </block>' +
' </category>' +
' <sep></sep>' +
' <category id="catComms" name="Comms">' +
Expand Down
7 changes: 7 additions & 0 deletions ardublockly/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="../blockly/arduino_compressed.js"></script>
<!-- To use the uncompressed version comment out the above and comment in the ones below -->
<!--script src="../blockly/blockly_uncompressed.js"></script>
<script src="../blockly/blocks/component_variable.js"></script>
<script src="../blockly/blocks/logic.js"></script>
<script src="../blockly/blocks/loops.js"></script>
<script src="../blockly/blocks/math.js"></script>
Expand All @@ -26,7 +27,10 @@
<script src="../blockly/blocks/colour.js"></script>
<script src="../blockly/blocks/variables.js"></script>
<script src="../blockly/blocks/procedures.js"></script>
<script src="../blockly/blocks/arduino/button.js"></script>
<script src="../blockly/blocks/arduino/components.js"></script>
<script src="../blockly/blocks/arduino/io.js"></script>
<script src="../blockly/blocks/arduino/light.js"></script>
<script src="../blockly/blocks/arduino/map.js"></script>
<script src="../blockly/blocks/arduino/procedures.js"></script>
<script src="../blockly/blocks/arduino/serial.js"></script>
Expand All @@ -38,6 +42,9 @@
<script src="../blockly/blocks/arduino/variables.js"></script>
<script src="../blockly/generators/arduino.js"></script>
<script src="../blockly/generators/arduino/boards.js"></script>
<script src="../blockly/generators/arduino/button.js"></script>
<script src="../blockly/generators/arduino/components.js"></script>
<script src="../blockly/generators/arduino/light.js"></script>
<script src="../blockly/generators/arduino/io.js"></script>
<script src="../blockly/generators/arduino/lists.js"></script>
<script src="../blockly/generators/arduino/logic.js"></script>
Expand Down
165 changes: 165 additions & 0 deletions blockly/blocks/arduino/button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/

/**
* @fileoverview Block for the Microduino functions.
* The Arduino built in functions syntax can be found at:
* https://arduino.cc/en/Reference/HomePage
*/
'use strict';

goog.provide('Blockly.Blocks.button');

goog.require('Blockly.Blocks');


/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.button.HUE = 250;


/** Attach a button block to the hub*/
Blockly.Blocks['button_setup'] = {
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldImage("../media/arduino/Button.png", 19, 19, "*"))
.appendField(Blockly.Msg.ARD_BUTTON_COMPONENT)
.appendField(new Blockly.Blocks.ComponentFieldVariable(
Blockly.Msg.ARD_BUTTON_DEFAULT_NAME, 'Button'), 'BUTTONNAME')
.appendField(Blockly.Msg.ARD_BUTTON_IFPUSHED)
.appendField(
new Blockly.FieldDropdown([[Blockly.Msg.ARD_HIGH, 'HIGH'], [Blockly.Msg.ARD_LOW, 'LOW']]),
'STATE');
this.setOutput(true, 'HUB_DIG');
this.setColour(Blockly.Blocks.button.HUE);
this.setTooltip(Blockly.Msg.ARD_BUTTON_TIP);
this.setHelpUrl('https://www.arduino.cc/en/Tutorial/Button');
},
/**
* Set the connection pins that the component connects to
* @param {array} array of the connections (as string, eg '1', 'SDA', 'A1', ...
* @this Blockly.Block
*/
setHubConnector: function(connector) {
this['connector'] = connector;
},
/**
* Return the name of the component defined in this block
* @return {!<string>} The name of the component
* @this Blockly.Block
*/
getComponentName: function() {
return 'Button';
},
/**
* Return all variables referenced by this block.
* @return {!Array.<string>} List of variable names.
* @this Blockly.Block
*/
getVars: function() {
return [this.getFieldValue('BUTTONNAME')];
},
/**
* Notification that a variable is renaming.
* If the name matches one of this block's variables, rename it.
* @param {string} oldName Previous name of variable.
* @param {string} newName Renamed variable.
* @this Blockly.Block
*/
renameVar: function(oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('BUTTONNAME'))) {
this.setFieldValue(newName, 'BUTTONNAME');
}
},
/**
* Gets the variable type required.
* @param {!string} varName Name of the variable selected in this block to
* check.
* @return {string} String to indicate the variable type.
*/
getVarType: function(varName) {
return Blockly.Types.NUMBER;
}
};


Blockly.Blocks['button_input'] = {
init: function() {
this.appendDummyInput()
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_IF)
.appendField(new Blockly.Blocks.ComponentFieldVariable(
Blockly.Msg.ARD_BUTTON_DEFAULT_NAME, 'Button'), 'BUTTONNAME')
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_CLICK);
this.appendStatementInput("CLICKINPUT")
.setCheck('ARD_BLOCK')
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_THEN);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_LONGCLICK);
this.appendStatementInput("LONGPRESSINPUT")
.setCheck('ARD_BLOCK')
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_THEN);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_PRESSED);
this.appendStatementInput("PRESSINPUT")
.setCheck('ARD_BLOCK')
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_THEN);
this.appendDummyInput()
.setAlign(Blockly.ALIGN_RIGHT)
.appendField(new Blockly.FieldCheckbox("TRUE"), "WAIT_INPUT")
.appendField(Blockly.Msg.ARD_BUTTON_INPUT_WAIT);
this.setPreviousStatement(true, 'ARD_BLOCK');
this.setNextStatement(true, 'ARD_BLOCK');
this.setColour(Blockly.Blocks.button.HUE);
this.setTooltip(Blockly.Msg.ARD_BUTTON_INPUT_TIP);
this.setHelpUrl('');
},
/**
* Return all variables referenced by this block.
* @return {!Array.<string>} List of variable names.
* @this Blockly.Block
*/
getVars: function() {
return [this.getFieldValue('BUTTONNAME')];
},
/**
* Notification that a variable is renaming.
* If the name matches one of this block's variables, rename it.
* @param {string} oldName Previous name of variable.
* @param {string} newName Renamed variable.
* @this Blockly.Block
*/
renameVar: function(oldName, newName) {
if (Blockly.Names.equals(oldName, this.getFieldValue('BUTTONNAME'))) {
this.setFieldValue(newName, 'BUTTONNAME');
}
},
/**
* Gets the variable type required.
* @param {!string} varName Name of the variable selected in this block to
* check.
* @return {string} String to indicate the variable type.
*/
getVarType: function(varName) {
return Blockly.Types.NUMBER;
},
/**
* Called whenever anything on the workspace changes.
* It checks the instances of the config block and attaches a warning to this
* block if not valid data is found.
* @this Blockly.Block
*/
onchange: function() {
if (!this.workspace) { return; } // Block has been deleted.

var currentDropdown = this.getFieldValue('BUTTONNAME');
if (Blockly.Blocks.ComponentFieldVariable.CheckSetupPresent(this.workspace, currentDropdown, 'Button')) {
this.setWarningText(null);
} else {
// Set a warning to select a valid config
this.setWarningText(Blockly.Msg.ARD_COMPONENT_WARN1.replace('%1', Blockly.Msg.ARD_BUTTON_COMPONENT).replace('%1', Blockly.Msg.ARD_BUTTON_COMPONENT));
}
}
};
Loading