Commit dff25dd5 authored by carlosperate's avatar carlosperate

Adds first group of Grove module blocks.

parent a8cd6b82
{
"categories": {
"grove": {
"categoryName": "Grove",
"description": "Grove Modules.",
"languages": ["en", "es"],
"toolboxName": "Grove",
"toolbox": [
"<category>",
" <block type=\"grove_led\">",
" <field name=\"CONNECTOR\">2</field>",
" <value name=\"STATE\">",
" <block type=\"io_highlow\">",
" <field name=\"STATE\">HIGH</field>",
" </block>",
" </value>",
" </block>",
" <block type=\"grove_button\"></block>",
" <block type=\"grove_pir\"></block>",
" <block type=\"grove_lcd_rgb\">",
" <value name=\"LINE_1\">",
" <block type=\"text\">",
" <field name=\"TEXT\">Hello world!</field>",
" </block>",
" </value>",
" </block>",
"</category>"
],
"extensions": ["Blockly.Arduino.Groove.init"]
},
"test": {
"categoryName": "Test blocks",
"description": "Test blocks to demonstrate the feature.",
......
# Grove Module Blocks
This directory contains the blocks for the SeeedStudio Grove Modules.
[http://www.seeedstudio.com/wiki/Grove_System](http://www.seeedstudio.com/wiki/Grove_System)
These blocks are still under development and more will be added soon. These are the current modules included:
* [LED](http://www.seeedstudio.com/wiki/Grove_-_LED)
* [Button](http://www.seeedstudio.com/wiki/Grove_-_Button)
* [PIR Motion Sensor](http://www.seeedstudio.com/wiki/Grove_-_PIR_Motion_Sensor)
* [LCD RGB Backlight](http://www.seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight) (only basic functionality), requires [this library](https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight) to be installed
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview Ardublockly JavaScript for the Blockly resources and bindings.
*/
'use strict';
goog.provide('Blockly.Blocks.groove');
goog.require('Blockly.Blocks');
Blockly.Blocks.groove.HUE = 180;
Blockly.Blocks['grove_led'] = {
/**
* Grove LED module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://www.seeedstudio.com/wiki/Grove_-_LED');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendValueInput('STATE')
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/led.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_LED)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.groveDigital), 'CONNECTOR')
.setCheck(Blockly.Types.BOOLEAN.compatibles());
this.setInputsInline(false);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_LED_TIP);
},
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields: function() {
Blockly.Arduino.Boards.refreshBlockFieldDropdown(
this, 'CONNECTOR', 'groveDigital');
},
/**
* Returns a list with the connector used pins, either one or both.
* @this Blockly.Block
* @return {!Array<string>} List of used pins by this block.
*/
connectorPinUsage: function() {
return [this.getFieldValue('CONNECTOR')];
}
};
Blockly.Blocks['grove_button'] = {
/**
* Grove Button module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://www.seeedstudio.com/wiki/Grove_-_Button');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/button.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_BUTTON)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.groveDigital), 'CONNECTOR');
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_BUTTON_TIP);
},
/** Updates the content of the the pin related fields. */
updateFields: Blockly.Blocks['grove_led'].updateFields,
/** Returns a list with the connector used pins, either one or both. */
connectorPinUsage: Blockly.Blocks['grove_led'].connectorPinUsage,
};
Blockly.Blocks['grove_pir'] = {
/**
* Grove PIR Motion Sensor module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://seeedstudio.com/wiki/Grove_-_PIR_Motion_Sensor');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendDummyInput()
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/pir.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_PIR)
.appendField(new Blockly.FieldDropdown(
Blockly.Arduino.Boards.selected.groveDigital), 'CONNECTOR');
this.setOutput(true, Blockly.Types.BOOLEAN.basicType);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_PIR_TIP);
},
/** Updates the content of the the pin related fields. */
updateFields: Blockly.Blocks['grove_led'].updateFields,
/** Returns a list with the connector used pins, either one or both. */
connectorPinUsage: Blockly.Blocks['grove_led'].connectorPinUsage,
};
Blockly.Blocks['grove_lcd_rgb'] = {
/**
* Grove LCD RGB Backlight module block definition.
* @this Blockly.Block
*/
init: function() {
this.setHelpUrl('http://seeedstudio.com/wiki/Grove_-_LCD_RGB_Backlight');
this.setColour(Blockly.Blocks.groove.HUE);
this.appendValueInput('LINE_1')
.appendField(new Blockly.FieldImage(
'/blocks/grove/img/lcd_rgb.png', 32, 32))
.appendField(Blockly.Msg.BLOCKS_GROVE_LCD_RGB)
.setCheck(Blockly.Types.TEXT.compatibles());
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setTooltip(Blockly.Msg.BLOCKS_GROVE_LCD_RGB_TIP);
},
/**
* Returns a list with the connector used pins, in this case the I2C pins.
* @this Blockly.Block
* @return {!Array<string>} List of used pins by this block.
*/
connectorPinUsage: function() {
var groveI2cId = Blockly.Arduino.Boards.selected.groveI2c[1];
return Blockly.Arduino.Boards.selected.i2cPins[groveI2cId];
}
};
\ No newline at end of file
{
"categoryName": "Grove",
"description": "Grove Modules.",
"languages": ["en", "es"],
"toolboxName": "Grove",
"toolbox": [
"<category>",
" <block type=\"grove_led\">",
" <field name=\"CONNECTOR\">2</field>",
" <value name=\"STATE\">",
" <block type=\"io_highlow\">",
" <field name=\"STATE\">HIGH</field>",
" </block>",
" </value>",
" </block>",
" <block type=\"grove_button\"></block>",
" <block type=\"grove_pir\"></block>",
" <block type=\"grove_lcd_rgb\">",
" <value name=\"LINE_1\">",
" <block type=\"text\">",
" <field name=\"TEXT\">Hello world!</field>",
" </block>",
" </value>",
" </block>",
"</category>"
],
"extensions": ["Blockly.Arduino.Groove.init"]
}
<xml xmlns="http://www.w3.org/1999/xhtml">
<block type="arduino_functions" x="7" y="18">
<statement name="LOOP_FUNC">
<block type="controls_if">
<mutation else="1"></mutation>
<value name="IF0">
<block type="procedures_callreturn">
<mutation name="isPeopleDetected"></mutation>
</block>
</value>
<statement name="DO0">
<block type="grove_led">
<field name="CONNECTOR">4</field>
<value name="STATE">
<block type="io_highlow">
<field name="STATE">HIGH</field>
</block>
</value>
</block>
</statement>
<statement name="ELSE">
<block type="grove_led">
<field name="CONNECTOR">4</field>
<value name="STATE">
<block type="io_highlow">
<field name="STATE">LOW</field>
</block>
</value>
</block>
</statement>
</block>
</statement>
</block>
<block type="procedures_defreturn" x="12" y="317">
<field name="NAME">isPeopleDetected</field>
<statement name="STACK">
<block type="procedures_ifreturn">
<mutation value="1"></mutation>
<value name="CONDITION">
<block type="grove_pir">
<field name="CONNECTOR">2</field>
</block>
</value>
<value name="VALUE">
<block type="logic_boolean">
<field name="BOOL">TRUE</field>
</block>
</value>
</block>
</statement>
<value name="RETURN">
<block type="logic_boolean">
<field name="BOOL">FALSE</field>
</block>
</value>
</block>
</xml>
\ No newline at end of file
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview Extends Ardublockly functionality for the Grove blocks
*/
'use strict';
goog.provide('Blockly.Arduino.Groove');
goog.require('Blockly.Arduino');
goog.require('Blockly.Arduino.Boards');
/** Initialises all the Groove blocks Ardublockly extensions. */
Blockly.Arduino.Groove.init = function() {
Blockly.Arduino.Groove.extendBoards();
Blockly.Arduino.Groove.extendPinTypes();
};
Blockly.Arduino.Groove.genDigitalConnectors = function(pinStart, pinEnd) {
var connectorIo = [];
for (var i = pinStart; i < (pinEnd + 1); i++) {
connectorIo.push(['D' + i.toString(), i.toString()]);
}
return connectorIo;
};
/** Extends all the Arduino boards to include Grove connectors.*/
Blockly.Arduino.Groove.extendBoards = function() {
for (var boardName in Blockly.Arduino.Boards.profiles) {
var board = Blockly.Arduino.Boards.profiles[boardName];
board.groveDigital = Blockly.Arduino.Groove.genDigitalConnectors(2, 8);
board.groveAnalog = Blockly.Arduino.Boards.generateAnalogIo(0, 3);
board.groveI2c = ['I2C', 'Wire'];
board.groveUart = ['UART', 'Serial'];
}
};
/** Extends the pin types to include Grove modules. */
Blockly.Arduino.Groove.extendPinTypes = function() {
Blockly.Arduino.PinTypes.GROVE_LED = 'GROVE LED';
Blockly.Arduino.PinTypes.GROVE_BUTTON = 'GROVE BUTTON';
Blockly.Arduino.PinTypes.GROVE_JOYSTICK = 'GROVE JOYSTICK';
Blockly.Arduino.PinTypes.GROVE_PIR = 'GROVE PIR';
};
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview Code generator for the test 2 blocks.
*/
'use strict';
goog.provide('Blockly.Arduino.grove');
goog.require('Blockly.Arduino');
/**
* Function for setting the state (Y) of a Grove LED module (X).
* Connector uses only 1 pin.
* Arduino code: setup { pinMode(X, OUTPUT); }
* loop { digitalWrite(X, Y); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {string} Completed code.
*/
Blockly.Arduino['grove_led'] = function(block) {
var pins = block.connectorPinUsage();
var stateOutput = Blockly.Arduino.valueToCode(
block, 'STATE', Blockly.Arduino.ORDER_ATOMIC) || 'LOW';
Blockly.Arduino.reservePin(
block, pins[0], Blockly.Arduino.PinTypes.GROVE_LED, 'this Grove module');
var pinSetupCode = 'pinMode(' + pins[0] + ', OUTPUT);';
Blockly.Arduino.addSetup('grove_led' + pins[0], pinSetupCode, false);
var code = 'digitalWrite(' + pins[0] + ', ' + stateOutput + ');\n';
return code;
};
/**
* Function for reading Grove Button state. Connector uses only 1 pin.
* Arduino code: setup { pinMode(X, INPUT); }
* loop { digitalRead(X); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['grove_button'] = function(block) {
var pins = block.connectorPinUsage();
Blockly.Arduino.reservePin(block, pins[0],
Blockly.Arduino.PinTypes.GROVE_BUTTON, 'this Grove module');
var pinSetupCode = 'pinMode(' + pins[0] + ', INPUT);';
Blockly.Arduino.addSetup('grove_button_' + pins[0], pinSetupCode, false);
var code = 'digitalRead(' + pins[0] + ')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function for reading Grove PIR sensor state. Connector uses only 1 pin.
* Arduino code: setup { pinMode(X, INPUT); }
* loop { digitalRead(X); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['grove_pir'] = function(block) {
var pins = block.connectorPinUsage();
Blockly.Arduino.reservePin(
block, pins[0], Blockly.Arduino.PinTypes.GROVE_PIR, 'this Grove module');
var pinSetupCode = 'pinMode(' + pins[0] + ', INPUT);';
Blockly.Arduino.addSetup('grove_pir_' + pins[0], pinSetupCode, false);
var code = 'digitalRead(' + pins[0] + ')';
return [code, Blockly.Arduino.ORDER_ATOMIC];
};
/**
* Function setting a Grove LCD RGB Backlight message. Connector uses I2C.
* Arduino code: setup { pinMode(X, INPUT); }
* loop { digitalRead(X); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['grove_lcd_rgb'] = function(block) {
var i2cPins = block.connectorPinUsage();
var line1Text = Blockly.Arduino.valueToCode(
block, 'LINE_1', Blockly.Arduino.ORDER_ATOMIC) || '""';
// Reserve I2C pins SDA and SCL
for (var i = 0; i < i2cPins.length; i++) {
Blockly.Arduino.reservePin(block, i2cPins[i][1],
Blockly.Arduino.PinTypes.I2C, 'I2C ' + i2cPins[i][0]);
}
Blockly.Arduino.addInclude('grove_lcd_rgb', '#include <rgb_lcd.h>');
Blockly.Arduino.addDeclaration('grove_lcd_rgb', 'rgb_lcd lcd;', false);
Blockly.Arduino.addSetup('grove_lcd_rgb_init', 'lcd.begin(16, 2);', false);
Blockly.Arduino.addSetup('grove_lcd_rgb_colour', 'lcd.setRGB(0, 255, 0);');
var code = 'lcd.clear();\nlcd.print(' + line1Text + ');';
return code;
};
/**
* @license Licensed under the Apache License, Version 2.0 (the "License"):
* http://www.apache.org/licenses/LICENSE-2.0
*/
/**
* @fileoverview English strings for Grove module blocks. All names have the
* postfix BLOCKS_GROVE.
*/
'use strict';
goog.require('Blockly.Msg.en');
/**
* Due to the frequency of long strings, the 80-column wrap rule need not apply
* to message files.
*/
/// Toolbox category name
Blockly.Msg.BLOCKS_GROVE_CATEGORY = 'Grove';
/// LED block
Blockly.Msg.BLOCKS_GROVE_LED = 'set Grove LED on connector';
Blockly.Msg.BLOCKS_GROVE_LED_TIP = 'Turns the LED On (HIGH) or Off (LOW).';
/// Button block
Blockly.Msg.BLOCKS_GROVE_BUTTON = 'read Grove Button on connector';
Blockly.Msg.BLOCKS_GROVE_BUTTON_TIP = 'Set to HIGH when the button is pressed, otherwise LOW.';
/// PIR block
Blockly.Msg.BLOCKS_GROVE_PIR = 'read Grove PIR on connector';
Blockly.Msg.BLOCKS_GROVE_PIR_TIP = 'On motion sense it outputs HIGH, otherwise LOW.';
/// LCD RGB block
Blockly.Msg.BLOCKS_GROVE_LCD_RGB = 'set LCD RGB text to';
Blockly.Msg.BLOCKS_GROVE_LCD_RGB_TIP = 'Sets the text on the LCD display.';
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