Commit 154d9f12 authored by carlosperate's avatar carlosperate

Create built version of Arduino blocks and generator.

parent 6cd98de1
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -10,13 +10,13 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.io');
goog.provide('Blockly.Blocks.io');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.io.HUE = 250;
Blockly.Blocks.io.HUE = 250;
Blockly.Blocks['io_digitalwrite'] = {
/**
......@@ -25,7 +25,7 @@ Blockly.Blocks['io_digitalwrite'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField('set digital pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -54,7 +54,7 @@ Blockly.Blocks['io_digitalread'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalRead');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField('read digital pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -83,7 +83,7 @@ Blockly.Blocks['io_builtin_led'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DigitalWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('STATE')
.appendField('set LED')
.appendField(new Blockly.FieldDropdown(
......@@ -116,7 +116,7 @@ Blockly.Blocks['io_analogwrite'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogWrite');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendValueInput('NUM')
.appendField('set analogue pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -148,7 +148,7 @@ Blockly.Blocks['io_analogread'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/AnalogRead');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField('read analogue pin#')
.appendField(new Blockly.FieldDropdown(
......@@ -176,7 +176,7 @@ Blockly.Blocks['io_highlow'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Constants');
this.setColour(Blockly.Blocks.Arduino.io.HUE);
this.setColour(Blockly.Blocks.io.HUE);
this.appendDummyInput()
.appendField(
new Blockly.FieldDropdown([['HIGH', 'HIGH'], ['LOW', 'LOW']]),
......
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*
*/
/*
* @fileoverview Blocks use for the Ardublockly logo creation.
* These are not mean to used at all.
*
* Generator:
* var noCode = function(block) { return ''; };
* Blockly.Arduino['ardublockly_name_bottom'] = noCode;
* Blockly.Arduino['ardublockly_plus_top_large'] = noCode;
* Blockly.Arduino['ardublockly_plus_top_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_bottom_large'] = noCode;
* Blockly.Arduino['ardublockly_plus_bottom_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_both_small'] = noCode;
* Blockly.Arduino['ardublockly_plus_both_large'] = noCode;
* Blockly.Arduino['ardublockly_minus_large'] = noCode;
* Blockly.Arduino['ardublockly_minus_small'] = noCode;
*
* Toolbox:
* <sep></sep>
* <category name="Logo">
......@@ -20,15 +34,12 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.logo');
goog.require('Blockly.Arduino');
goog.provide('Blockly.Blocks.logo');
goog.require('Blockly.Blocks');
var noCode = function(block) { return ''; };
Blockly.Blocks.Arduino.variables.HUE = 180;
Blockly.Blocks.logo.HUE = 180;
/* Ardublockly block */
Blockly.Blocks['ardublockly_name_top'] = {
......@@ -36,22 +47,19 @@ Blockly.Blocks['ardublockly_name_top'] = {
this.appendDummyInput()
.appendField("Ardublockly");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_name_top'] = noCode;
Blockly.Blocks['ardublockly_name_bottom'] = {
init: function() {
this.appendDummyInput()
.appendField("Ardublockly");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
this.setTooltip('');
}
};
Blockly.Arduino['ardublockly_name_bottom'] = noCode;
/* Plus block */
Blockly.Blocks['ardublockly_plus_top_large'] = {
......@@ -59,40 +67,36 @@ Blockly.Blocks['ardublockly_plus_top_large'] = {
this.appendValueInput("NAME")
.appendField(" +");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_top_large'] = noCode;
Blockly.Blocks['ardublockly_plus_top_small'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_top_small'] = noCode;
Blockly.Blocks['ardublockly_plus_bottom_large'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_bottom_large'] = noCode;
Blockly.Blocks['ardublockly_plus_bottom_small'] = {
init: function() {
this.appendValueInput("NAME")
.appendField(" +");
this.setPreviousStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_bottom_small'] = noCode;
Blockly.Blocks['ardublockly_plus_both_small'] = {
init: function() {
......@@ -100,10 +104,9 @@ Blockly.Blocks['ardublockly_plus_both_small'] = {
.appendField(" +");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_both_small'] = noCode;
Blockly.Blocks['ardublockly_plus_both_large'] = {
init: function() {
......@@ -111,11 +114,9 @@ Blockly.Blocks['ardublockly_plus_both_large'] = {
.appendField(" +");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_plus_both_large'] = noCode;
/* Minus block */
Blockly.Blocks['ardublockly_minus_large'] = {
......@@ -124,10 +125,9 @@ Blockly.Blocks['ardublockly_minus_large'] = {
.appendField("- ");
this.setInputsInline(false);
this.setOutput(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_minus_large'] = noCode;
Blockly.Blocks['ardublockly_minus_small'] = {
init: function() {
......@@ -135,7 +135,6 @@ Blockly.Blocks['ardublockly_minus_small'] = {
.appendField("- ");
this.setInputsInline(false);
this.setOutput(true);
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.logo.HUE);
}
};
Blockly.Arduino['ardublockly_minus_small'] = noCode;
......@@ -10,14 +10,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.map');
goog.provide('Blockly.Blocks.map');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.map.HUE = 230;
Blockly.Blocks.map.HUE = 230;
Blockly.Blocks['base_map'] = {
/**
......@@ -26,7 +26,7 @@ Blockly.Blocks['base_map'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/map');
this.setColour(Blockly.Blocks.Arduino.map.HUE);
this.setColour(Blockly.Blocks.map.HUE);
this.appendValueInput('NUM')
.appendField('Map ')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles());
......
......@@ -10,13 +10,11 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.procedures');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.procedures.HUE = 290;
Blockly.Blocks.procedures.HUE = 290;
Blockly.Blocks['arduino_functions'] = {
/**
......@@ -31,7 +29,7 @@ Blockly.Blocks['arduino_functions'] = {
.appendField('Arduino loop forever:');
this.appendStatementInput('LOOP_FUNC');
this.setInputsInline(false);
this.setColour(Blockly.Blocks.Arduino.procedures.HUE);
this.setColour(Blockly.Blocks.procedures.HUE);
this.setTooltip('Defines the Arduino setup() and loop() functions.');
this.setHelpUrl('https://arduino.cc/en/Reference/Loop');
this.contextMenu = false;
......
......@@ -11,14 +11,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.serial');
goog.provide('Blockly.Blocks.serial');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.serial.HUE = 160;
Blockly.Blocks.serial.HUE = 160;
Blockly.Blocks['serial_setup'] = {
/**
......@@ -27,7 +27,7 @@ Blockly.Blocks['serial_setup'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Serial/Begin');
this.setColour(Blockly.Blocks.Arduino.serial.HUE);
this.setColour(Blockly.Blocks.serial.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(
......@@ -68,7 +68,7 @@ Blockly.Blocks['serial_print'] = {
*/
init: function() {
this.setHelpUrl('http://www.arduino.cc/en/Serial/Print');
this.setColour(Blockly.Blocks.Arduino.serial.HUE);
this.setColour(Blockly.Blocks.serial.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.serial), 'SERIAL_ID')
......
......@@ -10,14 +10,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.servo');
goog.provide('Blockly.Blocks.servo');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.servo.HUE = 60;
Blockly.Blocks.servo.HUE = 60;
Blockly.Blocks['servo_write'] = {
/**
......@@ -26,7 +26,7 @@ Blockly.Blocks['servo_write'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/ServoWrite');
this.setColour(Blockly.Blocks.Arduino.servo.HUE);
this.setColour(Blockly.Blocks.servo.HUE);
this.appendDummyInput()
.appendField('Set SERVO from Pin')
.appendField(new Blockly.FieldDropdown(
......@@ -59,7 +59,7 @@ Blockly.Blocks['servo_read'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/ServoRead');
this.setColour(Blockly.Blocks.Arduino.servo.HUE);
this.setColour(Blockly.Blocks.servo.HUE);
this.appendDummyInput()
.appendField('Read SERVO from PIN#')
.appendField(new Blockly.FieldDropdown(
......
......@@ -8,14 +8,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.spi');
goog.provide('Blockly.Blocks.spi');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.spi.HUE = 170;
Blockly.Blocks.spi.HUE = 170;
Blockly.Blocks['spi_setup'] = {
/**
......@@ -24,7 +24,7 @@ Blockly.Blocks['spi_setup'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/SPI');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(new Blockly.FieldDropdown(
......@@ -85,7 +85,7 @@ Blockly.Blocks['spi_transfer'] = {
Blockly.Arduino.Boards.selected.digitalPins);
this.setHelpUrl('http://arduino.cc/en/Reference/SPITransfer');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.spi), 'SPI_ID');
......@@ -182,7 +182,7 @@ Blockly.Blocks['spi_transfer_return'] = {
Blockly.Arduino.Boards.selected.digitalPins);
this.setHelpUrl('http://arduino.cc/en/Reference/SPITransfer');
this.setColour(Blockly.Blocks.Arduino.spi.HUE);
this.setColour(Blockly.Blocks.spi.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.spi), 'SPI_ID');
......
......@@ -8,34 +8,33 @@
* Additional functions apart from the normal generators have
* been added to be able to generate the 'set' drop down menu
* with all current instances of the Stepper class:
* Blockly.Blocks.Arduino.stepper.stepperInstances
* Blockly.Blocks.Arduino.stepper.FieldStepperInstance
* Blockly.Blocks.Arduino.stepper.stepperDropdownList
* Blockly.Blocks.stepper.stepperInstances
* Blockly.Blocks.stepper.FieldStepperInstance
* Blockly.Blocks.stepper.stepperDropdownList
*
* TODO: Still need to had some kind of handler to refresh the "set" drop down
* menu values if an instance in a 'configure' block is renamed.
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.stepper');
goog.provide('Blockly.Blocks.stepper');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
goog.require('Blockly.FieldDropdown');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.stepper.HUE = 80;
Blockly.Blocks.stepper.HUE = 80;
/** Strings for easy reference. */
Blockly.Blocks.Arduino.stepper.noInstance = 'No_Instances';
Blockly.Blocks.Arduino.stepper.noName = 'Empty_input_name';
Blockly.Blocks.stepper.noInstance = 'No_Instances';
Blockly.Blocks.stepper.noName = 'Empty_input_name';
/**
* Finds all user-created instances of the Stepper block config.
* @return {!Array.<string>} Array of instance names.
*/
Blockly.Blocks.Arduino.stepper.stepperInstances = function() {
Blockly.Blocks.stepper.stepperInstances = function() {
var stepperList = [];
var blocks = Blockly.mainWorkspace.getTopBlocks();
for (var x = 0; x < blocks.length; x++) {
......@@ -54,8 +53,8 @@ Blockly.Blocks.Arduino.stepper.stepperInstances = function() {
* Return a sorted list of instances names for set dropdown menu.
* @return {!Array.<string>} Array of stepper instances names.
*/
Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
var stepperList = Blockly.Blocks.Arduino.stepper.stepperInstances();
Blockly.Blocks.stepper.stepperDropdownList = function() {
var stepperList = Blockly.Blocks.stepper.stepperInstances();
var options = [];
if (stepperList.length > 0) {
stepperList.sort(goog.string.caseInsensitiveCompare);
......@@ -66,8 +65,8 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
}
} else {
// There are no config blocks in the work area
options[0] = [Blockly.Blocks.Arduino.stepper.noInstance,
Blockly.Blocks.Arduino.stepper.noInstance];
options[0] = [Blockly.Blocks.stepper.noInstance,
Blockly.Blocks.stepper.noInstance];
}
return options;
};
......@@ -77,12 +76,12 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
* @extends {Blockly.FieldDropdown}
* @constructor
*/
Blockly.Blocks.Arduino.stepper.FieldStepperInstance = function() {
Blockly.Blocks.Arduino.stepper.FieldStepperInstance.superClass_.constructor
.call(this, Blockly.Blocks.Arduino.stepper.stepperDropdownList);
Blockly.Blocks.stepper.FieldStepperInstance = function() {
Blockly.Blocks.stepper.FieldStepperInstance.superClass_.constructor
.call(this, Blockly.Blocks.stepper.stepperDropdownList);
};
goog.inherits(
Blockly.Blocks.Arduino.stepper.FieldStepperInstance, Blockly.FieldDropdown);
Blockly.Blocks.stepper.FieldStepperInstance, Blockly.FieldDropdown);
Blockly.Blocks['stepper_config'] = {
......@@ -93,7 +92,7 @@ Blockly.Blocks['stepper_config'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperConstructor');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.setColour(Blockly.Blocks.stepper.HUE);
this.appendDummyInput()
.appendField('Setup')
.appendField(new Blockly.FieldTextInput('MyStepper'), 'STEPPER_NAME')
......@@ -125,7 +124,7 @@ Blockly.Blocks['stepper_config'] = {
getStepperSetupInstance: function() {
var InstanceName = this.getFieldValue('STEPPER_NAME');
if (!InstanceName) {
InstanceName = Blockly.Blocks.Arduino.stepper.noName;
InstanceName = Blockly.Blocks.stepper.noName;
}
// Replace all spaces with underscores
return InstanceName.replace(/ /g, '_');
......@@ -135,9 +134,9 @@ Blockly.Blocks['stepper_config'] = {
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
Blockly.Boards.refreshBlockFieldDropdown(
this, 'STEPPER_PIN1', 'digitalPins');
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
Blockly.Boards.refreshBlockFieldDropdown(
this, 'STEPPER_PIN2', 'digitalPins');
}
};
......@@ -149,10 +148,10 @@ Blockly.Blocks['stepper_step'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperStep');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.setColour(Blockly.Blocks.stepper.HUE);
this.appendDummyInput()
.appendField('move stepper')
.appendField(new Blockly.Blocks.Arduino.stepper.FieldStepperInstance(),
.appendField(new Blockly.Blocks.stepper.FieldStepperInstance(),
'STEPPER_NAME');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles());
......@@ -170,7 +169,7 @@ Blockly.Blocks['stepper_step'] = {
{
"type": "field_dropdown",
"name": "STEPPER_NAME",
"options": Blockly.Blocks.Arduino.stepper.stepperDropdownList()
"options": Blockly.Blocks.stepper.stepperDropdownList()
},
{
"type": "input_value",
......@@ -181,7 +180,7 @@ Blockly.Blocks['stepper_step'] = {
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Blocks.Arduino.stepper.HUE,
"colour": Blockly.Blocks.stepper.HUE,
"tooltip": "Turns the stepper motor a specific number of steps.",
"helpUrl": "http://arduino.cc/en/Reference/StepperStep"
});*/
......@@ -196,14 +195,13 @@ Blockly.Blocks['stepper_step'] = {
if (!this.workspace) { return; } // Block has been deleted.
var currentDropdown = this.getFieldValue('STEPPER_NAME');
var instances = Blockly.Blocks.Arduino.stepper.stepperDropdownList();
var instances = Blockly.Blocks.stepper.stepperDropdownList();
// Check for configuration block presence
if (instances[0][0] === Blockly.Blocks.Arduino.stepper.noInstance) {
if (instances[0][0] === Blockly.Blocks.stepper.noInstance) {
// Ensure dropdown menu says there is no config block
if (currentDropdown !== Blockly.Blocks.Arduino.stepper.noInstance) {
this.setFieldValue(
Blockly.Blocks.Arduino.stepper.noInstance, 'STEPPER_NAME');
if (currentDropdown !== Blockly.Blocks.stepper.noInstance) {
this.setFieldValue(Blockly.Blocks.stepper.noInstance, 'STEPPER_NAME');
}
this.setWarningText(
'A STEPPER configuration block must be added to use this block!');
......@@ -212,9 +210,9 @@ Blockly.Blocks['stepper_step'] = {
var existingConfigSelected = false;
for (var x = 0; x < instances.length; x++) {
// Check if any of the config blocks does not have a name
if (instances[x][0] === Blockly.Blocks.Arduino.stepper.noName) {
if (instances[x][0] === Blockly.Blocks.stepper.noName) {
// If selected config has no name either, set warning and exit func
if (currentDropdown === Blockly.Blocks.Arduino.stepper.noName) {
if (currentDropdown === Blockly.Blocks.stepper.noName) {
this.setWarningText('A Name input must be added to the Stepper ' +
'configuration block!');
return;
......@@ -229,8 +227,8 @@ Blockly.Blocks['stepper_step'] = {
// All good, just remove any warnings and exit the function
this.setWarningText(null);
} else {
if ((currentDropdown === Blockly.Blocks.Arduino.stepper.noName) ||
(currentDropdown === Blockly.Blocks.Arduino.stepper.noInstance)) {
if ((currentDropdown === Blockly.Blocks.stepper.noName) ||
(currentDropdown === Blockly.Blocks.stepper.noInstance)) {
// Just pick the first config block
this.setFieldValue(instances[0][0], 'STEPPER_NAME');
this.setWarningText(null);
......
......@@ -8,14 +8,14 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.time');
goog.provide('Blockly.Blocks.time');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.time.HUE = 140;
Blockly.Blocks.time.HUE = 140;
Blockly.Blocks['time_delay'] = {
/**
......@@ -24,7 +24,7 @@ Blockly.Blocks['time_delay'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Delay');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MILI')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles())
.appendField('wait');
......@@ -44,7 +44,7 @@ Blockly.Blocks['time_delaymicros'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/DelayMicroseconds');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendValueInput('DELAY_TIME_MICRO')
.setCheck(Blockly.StaticTyping.BlocklyTypes.NUMBER.compatibles())
.appendField('wait');
......@@ -64,7 +64,7 @@ Blockly.Blocks['time_millis'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Millis');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('current elapsed Time (milliseconds)');
this.setOutput(true, Blockly.StaticTyping.BlocklyTypes.NUMBER.basicType);
......@@ -84,7 +84,7 @@ Blockly.Blocks['time_micros'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/Micros');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('current elapsed Time (microseconds)');
this.setOutput(true, Blockly.StaticTyping.BlocklyTypes.NUMBER.basicType);
......@@ -107,7 +107,7 @@ Blockly.Blocks['infinite_loop'] = {
*/
init: function() {
this.setHelpUrl('');
this.setColour(Blockly.Blocks.Arduino.time.HUE);
this.setColour(Blockly.Blocks.time.HUE);
this.appendDummyInput()
.appendField('wait forever (end program)');
this.setInputsInline(true);
......
......@@ -10,14 +10,12 @@
*/
'use strict';
goog.provide('Blockly.Blocks.Arduino.variables');
goog.require('Blockly.Arduino');
goog.require('Blockly.Blocks');
goog.require('Blockly.StaticTyping');
/** Common HSV hue for all blocks in this category. */
Blockly.Blocks.Arduino.variables.HUE = 330;
Blockly.Blocks.variables.HUE = 330;
Blockly.Blocks['variables_set_type'] = {
/**
......@@ -26,7 +24,7 @@ Blockly.Blocks['variables_set_type'] = {
*/
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/HomePage');
this.setColour(Blockly.Blocks.Arduino.variables.HUE);
this.setColour(Blockly.Blocks.variables.HUE);
this.appendValueInput('VARIABLE_SETTYPE_INPUT');
this.appendDummyInput()
.appendField('as')
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -30,6 +30,7 @@
#
# This script also generates:
# blocks_compressed.js: The compressed Blockly language blocks.
# arduino_compressed.js: The compressed Arduino generator.
# javascript_compressed.js: The compressed Javascript generator.
# python_compressed.js: The compressed Python generator.
# dart_compressed.js: The compressed Dart generator.
......@@ -40,7 +41,7 @@ if sys.version_info[0] != 2:
raise Exception("Blockly build only compatible with Python 2.x.\n"
"You are using: " + sys.version)
import errno, glob, httplib, json, os, re, subprocess, threading, urllib
import errno, glob, fnmatch, httplib, json, os, re, subprocess, threading, urllib
def import_path(fullpath):
......@@ -173,6 +174,7 @@ class Gen_compressed(threading.Thread):
def run(self):
self.gen_core()
self.gen_blocks()
self.gen_generator("arduino")
self.gen_generator("javascript")
self.gen_generator("python")
self.gen_generator("php")
......@@ -202,7 +204,7 @@ class Gen_compressed(threading.Thread):
params.append(("js_code", "".join(f.readlines())))
f.close()
self.do_compile(params, target_filename, filenames, "")
self.do_compile(params, target_filename, filenames, [])
def gen_blocks(self):
target_filename = "blocks_compressed.js"
......@@ -219,14 +221,18 @@ class Gen_compressed(threading.Thread):
# Read in all the source files.
# Add Blockly.Blocks to be compatible with the compiler.
params.append(("js_code", "goog.provide('Blockly.Blocks');"))
filenames = glob.glob(os.path.join("blocks", "*.js"))
params.append(("js_code", "goog.provide('Blockly.StaticTyping');"))
filenames = []
for root, folders, files in os.walk("blocks"):
for filename in fnmatch.filter(files, "*.js"):
filenames.append(os.path.join(root, filename))
for filename in filenames:
f = open(filename)
params.append(("js_code", "".join(f.readlines())))
f.close()
# Remove Blockly.Blocks to be compatible with Blockly.
remove = "var Blockly={Blocks:{}};"
remove = ["var Blockly={Blocks:{}};", "Blockly.StaticTyping={};"]
self.do_compile(params, target_filename, filenames, remove)
def gen_generator(self, language):
......@@ -254,7 +260,7 @@ class Gen_compressed(threading.Thread):
filenames.insert(0, "[goog.provide]")
# Remove Blockly.Generator to be compatible with Blockly.
remove = "var Blockly={Generator:{}};"
remove = ["var Blockly={Generator:{}};"]
self.do_compile(params, target_filename, filenames, remove)
def do_compile(self, params, target_filename, filenames, remove):
......@@ -309,7 +315,8 @@ class Gen_compressed(threading.Thread):
sys.exit(1)
code = HEADER + "\n" + json_data["compiledCode"]
code = code.replace(remove, "")
for code_statement in remove:
code = code.replace(code_statement, "")
# Trim down Google's Apache licences.
# The Closure Compiler used to preserve these until August 2015.
......
......@@ -40,6 +40,7 @@ goog.require('Blockly.FieldTextInput');
goog.require('Blockly.FieldVariable');
goog.require('Blockly.Generator');
goog.require('Blockly.Msg');
goog.require('Blockly.StaticTyping');
goog.require('Blockly.Procedures');
goog.require('Blockly.Toolbox');
goog.require('Blockly.WidgetDiv');
......
......@@ -14,12 +14,6 @@ goog.require('Blockly.Block');
goog.require('Blockly.Workspace');
/**
* Class for StaticTyping.
* @constructor
*/
Blockly.StaticTyping = function() {};
/**
* "Enum-like" object to create blockly variable types.
* The number type is used to set a general number from the number block, the
......@@ -354,8 +348,8 @@ Blockly.StaticTyping.manageTypeWarning = function(block, bType, vName, vType) {
* Iterates through the list of top level blocks and sets the function arguments
* types.
* @param {Blockly.Workspace} workspace Blockly Workspace to collect variables.
* @param {Array<Blockly.StaticTyping.Type>} Associative array with the variable
* names as the keys and the type as the values.
* @param {Array<Blockly.StaticTyping.Type>} varsWithTypes Associative array
* with the variable names as the keys and the type as the values.
*/
Blockly.StaticTyping.setProcedureArgs = function(workspace, varsWithTypes) {
var blocks = workspace.getTopBlocks();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment