123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916 |
- 'use strict';
- goog.provide('Blockly.Blocks.mainwifi');
- goog.require('Blockly.Blocks');
- goog.require('Blockly.Types');
- Blockly.Blocks.mainwifi.HUE = "#b6415b";
- Blockly.Blocks['mainwifi_setup'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/main-wifi.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINWIFI_SETUP);
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- };
- /*send message from main_comtrol to wifi */
- Blockly.Blocks['mainwifi_sendMsg'] = {
- init: function () {
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINWIFI_SENDMSG)
- .appendField(new Blockly.FieldVariable("dataOut"), "dataVar");
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- return Blockly.Types.ARRAY;
- }
- };
- /*receive message from main_comtrol to wifi */
- Blockly.Blocks['mainwifi_receiveMsg'] = {
- init: function () {
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINWIFI_RECEIVEMSG)
- .appendField(new Blockly.FieldVariable("dataIn"), "dataVar");
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setOutput(true,Blockly.Types.BOOLEAN.output);
- this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- return Blockly.Types.ARRAY;
- }
- };
- /*check if sucessfully receive message from main_comtrol to wifi */
- Blockly.Blocks['mainwifi_receiveMsg_isSuccessed'] = {
- init: function () {
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINWIFI_RECEIVEMSG_ISSUCCESS);
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setOutput(true, Blockly.Types.BOOLEAN.output);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- };
- /*main easymode
- * wifi-2-main transfer
- * send msg from main to wifi
- */
- Blockly.Blocks['MainEasymode_transfer_send'] = {
- init: function () {
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
- .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- let vartype = Blockly.Types.ARRAY;
- return vartype;
- }
- }
- /*main easymode
- * main-2-wifi transfer
- * receive msg from wifi to main
- */
- Blockly.Blocks['MainEasymode_transfer_receive'] = {
- init: function () {
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
- .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- let vartype = Blockly.Types.ARRAY;
- return vartype;
- }
- }
- /********************************************
- * version 2
- *
- * ******************************************/
- /*wifi easymode
- * wifi-2-main transfer
- * send msg from wifi to main
- */
- Blockly.Blocks['MainEasymode_transfer2_send_old'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
- // .appendField(new Blockly.FieldDropdown([
- // ["txData", "txData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
- this.appendValueInput("ADD0")
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
- this.setColour(135);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
- },
- mutationToDom: function () {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parse XML to restore the inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this Blockly.Block
- */
- domToMutation: function (xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- /**
- * Populate the mutator's dialog with this block's components.
- * @param {!Blockly.Workspace} workspace Mutator's workspace.
- * @return {!Blockly.Block} Root block in mutator.
- * @this Blockly.Block
- */
- decompose: function (workspace) {
- var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- /**
- * Reconfigure this block based on the mutator dialog's components.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- compose: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- // Disconnect any children that don't belong.
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- /**
- * Store pointers to any connected child blocks.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- saveConnections: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- /**
- * Modify this block to have the correct number of inputs.
- * @private
- * @this Blockly.Block
- */
- updateShape_: function () {
- if (this.itemCount_ && this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
- this.appendDummyInput('EMPTY')
- .appendField(this.newQuote_(true))
- .appendField(this.newQuote_(false));
- }
- // Add new inputs.
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput('ADD' + i)
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- };
- Blockly.Blocks['MainEasymode_transfer_create_with_container'] = {
- /**
- * Mutator block for list container.
- * @this Blockly.Block
- */
- init: function () {
- this.setColour(135);
- this.appendDummyInput()
- .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
- this.appendStatementInput('STACK');
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['MainEasymode_transfer_create_with_item'] = {
- /**
- * Mutator bolck for adding items.
- * @this Blockly.Block
- */
- init: function () {
- this.setColour(135);
- this.appendDummyInput()
- .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- /*wifi easymode
- * wifi-2-main transfer
- * receive msg from main to wifi
- */
- Blockly.Blocks['MainEasymode_transfer2_receive_old'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
- .appendField(new Blockly.FieldDropdown([
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"],
- ["11", "11"],
- ["12", "12"],
- ]), "LENGTH");
- this.setColour(135);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- let vartype = Blockly.Types.ARRAY;
- return vartype;
- }
- }
- /*wifi easymode
- * wifi-2-main transfer
- * get data from dataMain
- * @param {dataMain} :where data tranferred stored in
- */
- Blockly.Blocks['MainEasymode_transfer2_receive_getValue_old'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN")
- .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"],
- ["11", "11"],
- ]), "INDEX")
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
- // .appendField(new Blockly.FieldDropdown([
- // ["String", ""],
- // ["Number", ".toInt()"],
- // ["Float", ".toFloat()"],
- // ]), "TYPE")
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
- this.setColour(135);
- this.setOutput(true)
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT;
- case ".toInt()":
- return Blockly.Types.NUMBER;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER;
- }
- return Blockly.Types.NUMBER;
- },
- getOutputType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT.output
- case ".toInt()":
- return Blockly.Types.NUMBER.output;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER.output;
- }
- return Blockly.Types.NUMBER.output;
- }
- }
- /********************************************
- * version 3
- *
- * ******************************************/
- /*wifi easymode
- * wifi-2-main transfer
- * send msg from wifi to main
- */
- Blockly.Blocks['MainEasymode_transfer2_send'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
- // .appendField(new Blockly.FieldDropdown([
- // ["txData", "txData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
- this.appendValueInput("ADD0")
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
- },
- mutationToDom: function () {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parse XML to restore the inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this Blockly.Block
- */
- domToMutation: function (xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- /**
- * Populate the mutator's dialog with this block's components.
- * @param {!Blockly.Workspace} workspace Mutator's workspace.
- * @return {!Blockly.Block} Root block in mutator.
- * @this Blockly.Block
- */
- decompose: function (workspace) {
- var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- /**
- * Reconfigure this block based on the mutator dialog's components.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- compose: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- // Disconnect any children that don't belong.
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- /**
- * Store pointers to any connected child blocks.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- saveConnections: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- /**
- * Modify this block to have the correct number of inputs.
- * @private
- * @this Blockly.Block
- */
- updateShape_: function () {
- if (this.itemCount_ && this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
- this.appendDummyInput('EMPTY')
- .appendField(this.newQuote_(true))
- .appendField(this.newQuote_(false));
- }
- // Add new inputs.
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput('ADD' + i)
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- };
- /*wifi easymode
- * wifi-2-main transfer
- * send msg from wifi to main
- */
- Blockly.Blocks['AiEasymode_transfer2_send'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
- // .appendField(new Blockly.FieldDropdown([
- // ["txData", "txData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
- this.appendValueInput("ADD0")
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
- this.setColour("#435592");
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- this.itemCount_ = 1;
- this.updateShape_();
- this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
- },
- mutationToDom: function () {
- var container = document.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parse XML to restore the inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this Blockly.Block
- */
- domToMutation: function (xmlElement) {
- this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_();
- },
- /**
- * Populate the mutator's dialog with this block's components.
- * @param {!Blockly.Workspace} workspace Mutator's workspace.
- * @return {!Blockly.Block} Root block in mutator.
- * @this Blockly.Block
- */
- decompose: function (workspace) {
- var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
- containerBlock.initSvg();
- var connection = containerBlock.getInput('STACK').connection;
- for (var i = 0; i < this.itemCount_; i++) {
- var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
- itemBlock.initSvg();
- connection.connect(itemBlock.previousConnection);
- connection = itemBlock.nextConnection;
- }
- return containerBlock;
- },
- /**
- * Reconfigure this block based on the mutator dialog's components.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- compose: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- // Count number of inputs.
- var connections = [];
- while (itemBlock) {
- connections.push(itemBlock.valueConnection_);
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- // Disconnect any children that don't belong.
- for (var i = 0; i < this.itemCount_; i++) {
- var connection = this.getInput('ADD' + i).connection.targetConnection;
- if (connection && connections.indexOf(connection) == -1) {
- connection.disconnect();
- }
- }
- this.itemCount_ = connections.length;
- this.updateShape_();
- // Reconnect any child blocks.
- for (var i = 0; i < this.itemCount_; i++) {
- Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
- }
- },
- /**
- * Store pointers to any connected child blocks.
- * @param {!Blockly.Block} containerBlock Root block in mutator.
- * @this Blockly.Block
- */
- saveConnections: function (containerBlock) {
- var itemBlock = containerBlock.getInputTargetBlock('STACK');
- var i = 0;
- while (itemBlock) {
- var input = this.getInput('ADD' + i);
- itemBlock.valueConnection_ = input && input.connection.targetConnection;
- i++;
- itemBlock = itemBlock.nextConnection &&
- itemBlock.nextConnection.targetBlock();
- }
- },
- /**
- * Modify this block to have the correct number of inputs.
- * @private
- * @this Blockly.Block
- */
- updateShape_: function () {
- if (this.itemCount_ && this.getInput('EMPTY')) {
- this.removeInput('EMPTY');
- } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
- this.appendDummyInput('EMPTY')
- .appendField(this.newQuote_(true))
- .appendField(this.newQuote_(false));
- }
- // Add new inputs.
- for (var i = 0; i < this.itemCount_; i++) {
- if (!this.getInput('ADD' + i)) {
- var input = this.appendValueInput('ADD' + i)
- .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
- }
- }
- while (this.getInput('ADD' + i)) {
- this.removeInput('ADD' + i);
- i++;
- }
- },
- };
- Blockly.Blocks['MainEasymode_transfer_create_with_container'] = {
- /**
- * Mutator block for list container.
- * @this Blockly.Block
- */
- init: function () {
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
- this.appendStatementInput('STACK');
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- Blockly.Blocks['MainEasymode_transfer_create_with_item'] = {
- /**
- * Mutator bolck for adding items.
- * @this Blockly.Block
- */
- init: function () {
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.appendDummyInput()
- .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
- this.setPreviousStatement(true);
- this.setNextStatement(true);
- this.setTooltip('');
- this.contextMenu = false;
- }
- };
- /*wifi easymode
- * wifi-2-main transfer
- * receive msg from main to wifi
- */
- Blockly.Blocks['MainEasymode_transfer2_receive'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
- .appendField(new Blockly.FieldDropdown([
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"],
- ["11", "11"],
- ["12", "12"],
- ]), "LENGTH");
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- let vartype = Blockly.Types.ARRAY;
- return vartype;
- }
- }
- /*wifi easymode
- * wifi-2-main transfer
- * receive msg from main to wifi
- */
- Blockly.Blocks['AiEasymode_transfer2_receive'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
- .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
- // this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN");
- this.appendDummyInput()
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
- .appendField(new Blockly.FieldDropdown([
- ["1", "1"],
- ["2", "2"],
- ["3", "3"],
- ["4", "4"],
- ["5", "5"],
- ["6", "6"],
- ["7", "7"],
- ["8", "8"],
- ["9", "9"],
- ["10", "10"],
- ["11", "11"],
- ["12", "12"],
- ]), "LENGTH");
- this.setColour("#435592");
- this.setPreviousStatement(true, null);
- this.setNextStatement(true, null);
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getVarType: function (varName) {
- let vartype = Blockly.Types.ARRAY;
- return vartype;
- }
- }
- /*wifi easymode
- * wifi-2-main transfer
- * get data from dataMain
- * @param {dataMain} :where data tranferred stored in
- */
- Blockly.Blocks['MainEasymode_transfer2_receive_getValue'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN")
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ]), "INDEX")
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
- // .appendField(new Blockly.FieldDropdown([
- // ["String", ""],
- // ["Number", ".toInt()"],
- // ["Float", ".toFloat()"],
- // ]), "TYPE")
- //.appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
- this.setColour(Blockly.Blocks.mainwifi.HUE);
- this.setOutput(true)
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT;
- case ".toInt()":
- return Blockly.Types.NUMBER;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER;
- }
- return Blockly.Types.NUMBER;
- },
- getOutputType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT.output
- case ".toInt()":
- return Blockly.Types.NUMBER.output;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER.output;
- }
- return Blockly.Types.NUMBER.output;
- }
- }
- /*wifi easymode
- * wifi-2-main transfer
- * get data from dataMain
- * @param {dataMain} :where data tranferred stored in
- */
- Blockly.Blocks['AiEasymode_transfer2_receive_getValue'] = {
- init: function () {
- this.appendDummyInput()
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
- // .appendField(new Blockly.FieldDropdown([
- // ["rxData", "rxData"]
- // ]), "DATAMAIN")
- .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
- .appendField(new Blockly.FieldDropdown([
- ["0", "0"],
- ["1", "1"],
- ["2", "2"],
- ]), "INDEX")
- // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
- // .appendField(new Blockly.FieldDropdown([
- // ["String", ""],
- // ["Number", ".toInt()"],
- // ["Float", ".toFloat()"],
- // ]), "TYPE")
- //.appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
- this.setColour("#435592");
- this.setOutput(true)
- // this.setInputsInline(true);
- this.setTooltip("");
- this.setHelpUrl("");
- },
- getBlockType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT;
- case ".toInt()":
- return Blockly.Types.NUMBER;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER;
- }
- return Blockly.Types.NUMBER;
- },
- getOutputType: function () {
- var type = this.getFieldValue("TYPE");
- switch (type) {
- case "":
- return Blockly.Types.TEXT.output
- case ".toInt()":
- return Blockly.Types.NUMBER.output;
- case ".toFloat()":
- return Blockly.Types.LARGE_NUMBER.output;
- }
- return Blockly.Types.NUMBER.output;
- }
- }
|