mainwifi.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. 'use strict';
  2. goog.provide('Blockly.Blocks.mainwifi');
  3. goog.require('Blockly.Blocks');
  4. goog.require('Blockly.Types');
  5. Blockly.Blocks.mainwifi.HUE = "#b6415b";
  6. Blockly.Blocks['mainwifi_setup'] = {
  7. init: function () {
  8. this.appendDummyInput()
  9. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  10. .appendField(new Blockly.FieldImage("./../blockly/media/main-wifi.png", 50, 40, "0"));
  11. this.appendDummyInput()
  12. .appendField(Blockly.Msg.MAINWIFI_SETUP);
  13. this.setColour(Blockly.Blocks.mainwifi.HUE);
  14. this.setTooltip("");
  15. this.setHelpUrl("");
  16. },
  17. };
  18. /*send message from main_comtrol to wifi */
  19. Blockly.Blocks['mainwifi_sendMsg'] = {
  20. init: function () {
  21. this.appendDummyInput()
  22. .appendField(Blockly.Msg.MAINWIFI_SENDMSG)
  23. .appendField(new Blockly.FieldVariable("dataOut"), "dataVar");
  24. this.setColour(Blockly.Blocks.mainwifi.HUE);
  25. this.setPreviousStatement(true, null);
  26. this.setNextStatement(true, null);
  27. this.setInputsInline(true);
  28. this.setTooltip("");
  29. this.setHelpUrl("");
  30. },
  31. getVarType: function (varName) {
  32. return Blockly.Types.ARRAY;
  33. }
  34. };
  35. /*receive message from main_comtrol to wifi */
  36. Blockly.Blocks['mainwifi_receiveMsg'] = {
  37. init: function () {
  38. this.appendDummyInput()
  39. .appendField(Blockly.Msg.MAINWIFI_RECEIVEMSG)
  40. .appendField(new Blockly.FieldVariable("dataIn"), "dataVar");
  41. this.setColour(Blockly.Blocks.mainwifi.HUE);
  42. this.setPreviousStatement(true, null);
  43. this.setNextStatement(true, null);
  44. // this.setOutput(true,Blockly.Types.BOOLEAN.output);
  45. this.setInputsInline(true);
  46. this.setTooltip("");
  47. this.setHelpUrl("");
  48. },
  49. getVarType: function (varName) {
  50. return Blockly.Types.ARRAY;
  51. }
  52. };
  53. /*check if sucessfully receive message from main_comtrol to wifi */
  54. Blockly.Blocks['mainwifi_receiveMsg_isSuccessed'] = {
  55. init: function () {
  56. this.appendDummyInput()
  57. .appendField(Blockly.Msg.MAINWIFI_RECEIVEMSG_ISSUCCESS);
  58. this.setColour(Blockly.Blocks.mainwifi.HUE);
  59. this.setOutput(true, Blockly.Types.BOOLEAN.output);
  60. // this.setInputsInline(true);
  61. this.setTooltip("");
  62. this.setHelpUrl("");
  63. },
  64. };
  65. /*main easymode
  66. * wifi-2-main transfer
  67. * send msg from main to wifi
  68. */
  69. Blockly.Blocks['MainEasymode_transfer_send'] = {
  70. init: function () {
  71. this.appendDummyInput()
  72. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
  73. .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
  74. this.appendDummyInput()
  75. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
  76. this.setColour(Blockly.Blocks.mainwifi.HUE);
  77. this.setPreviousStatement(true, null);
  78. this.setNextStatement(true, null);
  79. // this.setInputsInline(true);
  80. this.setTooltip("");
  81. this.setHelpUrl("");
  82. },
  83. getVarType: function (varName) {
  84. let vartype = Blockly.Types.ARRAY;
  85. return vartype;
  86. }
  87. }
  88. /*main easymode
  89. * main-2-wifi transfer
  90. * receive msg from wifi to main
  91. */
  92. Blockly.Blocks['MainEasymode_transfer_receive'] = {
  93. init: function () {
  94. this.appendDummyInput()
  95. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
  96. this.appendDummyInput()
  97. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
  98. .appendField(new Blockly.FieldVariable("dataMain"), "DATAMAIN");
  99. this.setColour(Blockly.Blocks.mainwifi.HUE);
  100. this.setPreviousStatement(true, null);
  101. this.setNextStatement(true, null);
  102. // this.setInputsInline(true);
  103. this.setTooltip("");
  104. this.setHelpUrl("");
  105. },
  106. getVarType: function (varName) {
  107. let vartype = Blockly.Types.ARRAY;
  108. return vartype;
  109. }
  110. }
  111. /********************************************
  112. * version 2
  113. *
  114. * ******************************************/
  115. /*wifi easymode
  116. * wifi-2-main transfer
  117. * send msg from wifi to main
  118. */
  119. Blockly.Blocks['MainEasymode_transfer2_send_old'] = {
  120. init: function () {
  121. this.appendDummyInput()
  122. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  123. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  124. // this.appendDummyInput()
  125. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
  126. // .appendField(new Blockly.FieldDropdown([
  127. // ["txData", "txData"]
  128. // ]), "DATAMAIN");
  129. this.appendDummyInput()
  130. .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
  131. this.appendValueInput("ADD0")
  132. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
  133. this.setColour(135);
  134. this.setPreviousStatement(true, null);
  135. this.setNextStatement(true, null);
  136. // this.setInputsInline(true);
  137. this.setTooltip("");
  138. this.setHelpUrl("");
  139. this.itemCount_ = 1;
  140. this.updateShape_();
  141. this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
  142. },
  143. mutationToDom: function () {
  144. var container = document.createElement('mutation');
  145. container.setAttribute('items', this.itemCount_);
  146. return container;
  147. },
  148. /**
  149. * Parse XML to restore the inputs.
  150. * @param {!Element} xmlElement XML storage element.
  151. * @this Blockly.Block
  152. */
  153. domToMutation: function (xmlElement) {
  154. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  155. this.updateShape_();
  156. },
  157. /**
  158. * Populate the mutator's dialog with this block's components.
  159. * @param {!Blockly.Workspace} workspace Mutator's workspace.
  160. * @return {!Blockly.Block} Root block in mutator.
  161. * @this Blockly.Block
  162. */
  163. decompose: function (workspace) {
  164. var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
  165. containerBlock.initSvg();
  166. var connection = containerBlock.getInput('STACK').connection;
  167. for (var i = 0; i < this.itemCount_; i++) {
  168. var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
  169. itemBlock.initSvg();
  170. connection.connect(itemBlock.previousConnection);
  171. connection = itemBlock.nextConnection;
  172. }
  173. return containerBlock;
  174. },
  175. /**
  176. * Reconfigure this block based on the mutator dialog's components.
  177. * @param {!Blockly.Block} containerBlock Root block in mutator.
  178. * @this Blockly.Block
  179. */
  180. compose: function (containerBlock) {
  181. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  182. // Count number of inputs.
  183. var connections = [];
  184. while (itemBlock) {
  185. connections.push(itemBlock.valueConnection_);
  186. itemBlock = itemBlock.nextConnection &&
  187. itemBlock.nextConnection.targetBlock();
  188. }
  189. // Disconnect any children that don't belong.
  190. for (var i = 0; i < this.itemCount_; i++) {
  191. var connection = this.getInput('ADD' + i).connection.targetConnection;
  192. if (connection && connections.indexOf(connection) == -1) {
  193. connection.disconnect();
  194. }
  195. }
  196. this.itemCount_ = connections.length;
  197. this.updateShape_();
  198. // Reconnect any child blocks.
  199. for (var i = 0; i < this.itemCount_; i++) {
  200. Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
  201. }
  202. },
  203. /**
  204. * Store pointers to any connected child blocks.
  205. * @param {!Blockly.Block} containerBlock Root block in mutator.
  206. * @this Blockly.Block
  207. */
  208. saveConnections: function (containerBlock) {
  209. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  210. var i = 0;
  211. while (itemBlock) {
  212. var input = this.getInput('ADD' + i);
  213. itemBlock.valueConnection_ = input && input.connection.targetConnection;
  214. i++;
  215. itemBlock = itemBlock.nextConnection &&
  216. itemBlock.nextConnection.targetBlock();
  217. }
  218. },
  219. /**
  220. * Modify this block to have the correct number of inputs.
  221. * @private
  222. * @this Blockly.Block
  223. */
  224. updateShape_: function () {
  225. if (this.itemCount_ && this.getInput('EMPTY')) {
  226. this.removeInput('EMPTY');
  227. } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
  228. this.appendDummyInput('EMPTY')
  229. .appendField(this.newQuote_(true))
  230. .appendField(this.newQuote_(false));
  231. }
  232. // Add new inputs.
  233. for (var i = 0; i < this.itemCount_; i++) {
  234. if (!this.getInput('ADD' + i)) {
  235. var input = this.appendValueInput('ADD' + i)
  236. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
  237. }
  238. }
  239. while (this.getInput('ADD' + i)) {
  240. this.removeInput('ADD' + i);
  241. i++;
  242. }
  243. },
  244. };
  245. Blockly.Blocks['MainEasymode_transfer_create_with_container'] = {
  246. /**
  247. * Mutator block for list container.
  248. * @this Blockly.Block
  249. */
  250. init: function () {
  251. this.setColour(135);
  252. this.appendDummyInput()
  253. .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
  254. this.appendStatementInput('STACK');
  255. this.setTooltip('');
  256. this.contextMenu = false;
  257. }
  258. };
  259. Blockly.Blocks['MainEasymode_transfer_create_with_item'] = {
  260. /**
  261. * Mutator bolck for adding items.
  262. * @this Blockly.Block
  263. */
  264. init: function () {
  265. this.setColour(135);
  266. this.appendDummyInput()
  267. .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
  268. this.setPreviousStatement(true);
  269. this.setNextStatement(true);
  270. this.setTooltip('');
  271. this.contextMenu = false;
  272. }
  273. };
  274. /*wifi easymode
  275. * wifi-2-main transfer
  276. * receive msg from main to wifi
  277. */
  278. Blockly.Blocks['MainEasymode_transfer2_receive_old'] = {
  279. init: function () {
  280. this.appendDummyInput()
  281. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  282. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  283. this.appendDummyInput()
  284. .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
  285. // this.appendDummyInput()
  286. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
  287. // .appendField(new Blockly.FieldDropdown([
  288. // ["rxData", "rxData"]
  289. // ]), "DATAMAIN");
  290. this.appendDummyInput()
  291. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
  292. .appendField(new Blockly.FieldDropdown([
  293. ["1", "1"],
  294. ["2", "2"],
  295. ["3", "3"],
  296. ["4", "4"],
  297. ["5", "5"],
  298. ["6", "6"],
  299. ["7", "7"],
  300. ["8", "8"],
  301. ["9", "9"],
  302. ["10", "10"],
  303. ["11", "11"],
  304. ["12", "12"],
  305. ]), "LENGTH");
  306. this.setColour(135);
  307. this.setPreviousStatement(true, null);
  308. this.setNextStatement(true, null);
  309. // this.setInputsInline(true);
  310. this.setTooltip("");
  311. this.setHelpUrl("");
  312. },
  313. getVarType: function (varName) {
  314. let vartype = Blockly.Types.ARRAY;
  315. return vartype;
  316. }
  317. }
  318. /*wifi easymode
  319. * wifi-2-main transfer
  320. * get data from dataMain
  321. * @param {dataMain} :where data tranferred stored in
  322. */
  323. Blockly.Blocks['MainEasymode_transfer2_receive_getValue_old'] = {
  324. init: function () {
  325. this.appendDummyInput()
  326. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
  327. // .appendField(new Blockly.FieldDropdown([
  328. // ["rxData", "rxData"]
  329. // ]), "DATAMAIN")
  330. .appendField("Old " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
  331. .appendField(new Blockly.FieldDropdown([
  332. ["0", "0"],
  333. ["1", "1"],
  334. ["2", "2"],
  335. ["3", "3"],
  336. ["4", "4"],
  337. ["5", "5"],
  338. ["6", "6"],
  339. ["7", "7"],
  340. ["8", "8"],
  341. ["9", "9"],
  342. ["10", "10"],
  343. ["11", "11"],
  344. ]), "INDEX")
  345. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
  346. // .appendField(new Blockly.FieldDropdown([
  347. // ["String", ""],
  348. // ["Number", ".toInt()"],
  349. // ["Float", ".toFloat()"],
  350. // ]), "TYPE")
  351. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
  352. this.setColour(135);
  353. this.setOutput(true)
  354. // this.setInputsInline(true);
  355. this.setTooltip("");
  356. this.setHelpUrl("");
  357. },
  358. getBlockType: function () {
  359. var type = this.getFieldValue("TYPE");
  360. switch (type) {
  361. case "":
  362. return Blockly.Types.TEXT;
  363. case ".toInt()":
  364. return Blockly.Types.NUMBER;
  365. case ".toFloat()":
  366. return Blockly.Types.LARGE_NUMBER;
  367. }
  368. return Blockly.Types.NUMBER;
  369. },
  370. getOutputType: function () {
  371. var type = this.getFieldValue("TYPE");
  372. switch (type) {
  373. case "":
  374. return Blockly.Types.TEXT.output
  375. case ".toInt()":
  376. return Blockly.Types.NUMBER.output;
  377. case ".toFloat()":
  378. return Blockly.Types.LARGE_NUMBER.output;
  379. }
  380. return Blockly.Types.NUMBER.output;
  381. }
  382. }
  383. /********************************************
  384. * version 3
  385. *
  386. * ******************************************/
  387. /*wifi easymode
  388. * wifi-2-main transfer
  389. * send msg from wifi to main
  390. */
  391. Blockly.Blocks['MainEasymode_transfer2_send'] = {
  392. init: function () {
  393. this.appendDummyInput()
  394. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  395. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  396. // this.appendDummyInput()
  397. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
  398. // .appendField(new Blockly.FieldDropdown([
  399. // ["txData", "txData"]
  400. // ]), "DATAMAIN");
  401. this.appendDummyInput()
  402. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
  403. this.appendValueInput("ADD0")
  404. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
  405. this.setColour(Blockly.Blocks.mainwifi.HUE);
  406. this.setPreviousStatement(true, null);
  407. this.setNextStatement(true, null);
  408. // this.setInputsInline(true);
  409. this.setTooltip("");
  410. this.setHelpUrl("");
  411. this.itemCount_ = 1;
  412. this.updateShape_();
  413. this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
  414. },
  415. mutationToDom: function () {
  416. var container = document.createElement('mutation');
  417. container.setAttribute('items', this.itemCount_);
  418. return container;
  419. },
  420. /**
  421. * Parse XML to restore the inputs.
  422. * @param {!Element} xmlElement XML storage element.
  423. * @this Blockly.Block
  424. */
  425. domToMutation: function (xmlElement) {
  426. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  427. this.updateShape_();
  428. },
  429. /**
  430. * Populate the mutator's dialog with this block's components.
  431. * @param {!Blockly.Workspace} workspace Mutator's workspace.
  432. * @return {!Blockly.Block} Root block in mutator.
  433. * @this Blockly.Block
  434. */
  435. decompose: function (workspace) {
  436. var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
  437. containerBlock.initSvg();
  438. var connection = containerBlock.getInput('STACK').connection;
  439. for (var i = 0; i < this.itemCount_; i++) {
  440. var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
  441. itemBlock.initSvg();
  442. connection.connect(itemBlock.previousConnection);
  443. connection = itemBlock.nextConnection;
  444. }
  445. return containerBlock;
  446. },
  447. /**
  448. * Reconfigure this block based on the mutator dialog's components.
  449. * @param {!Blockly.Block} containerBlock Root block in mutator.
  450. * @this Blockly.Block
  451. */
  452. compose: function (containerBlock) {
  453. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  454. // Count number of inputs.
  455. var connections = [];
  456. while (itemBlock) {
  457. connections.push(itemBlock.valueConnection_);
  458. itemBlock = itemBlock.nextConnection &&
  459. itemBlock.nextConnection.targetBlock();
  460. }
  461. // Disconnect any children that don't belong.
  462. for (var i = 0; i < this.itemCount_; i++) {
  463. var connection = this.getInput('ADD' + i).connection.targetConnection;
  464. if (connection && connections.indexOf(connection) == -1) {
  465. connection.disconnect();
  466. }
  467. }
  468. this.itemCount_ = connections.length;
  469. this.updateShape_();
  470. // Reconnect any child blocks.
  471. for (var i = 0; i < this.itemCount_; i++) {
  472. Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
  473. }
  474. },
  475. /**
  476. * Store pointers to any connected child blocks.
  477. * @param {!Blockly.Block} containerBlock Root block in mutator.
  478. * @this Blockly.Block
  479. */
  480. saveConnections: function (containerBlock) {
  481. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  482. var i = 0;
  483. while (itemBlock) {
  484. var input = this.getInput('ADD' + i);
  485. itemBlock.valueConnection_ = input && input.connection.targetConnection;
  486. i++;
  487. itemBlock = itemBlock.nextConnection &&
  488. itemBlock.nextConnection.targetBlock();
  489. }
  490. },
  491. /**
  492. * Modify this block to have the correct number of inputs.
  493. * @private
  494. * @this Blockly.Block
  495. */
  496. updateShape_: function () {
  497. if (this.itemCount_ && this.getInput('EMPTY')) {
  498. this.removeInput('EMPTY');
  499. } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
  500. this.appendDummyInput('EMPTY')
  501. .appendField(this.newQuote_(true))
  502. .appendField(this.newQuote_(false));
  503. }
  504. // Add new inputs.
  505. for (var i = 0; i < this.itemCount_; i++) {
  506. if (!this.getInput('ADD' + i)) {
  507. var input = this.appendValueInput('ADD' + i)
  508. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
  509. }
  510. }
  511. while (this.getInput('ADD' + i)) {
  512. this.removeInput('ADD' + i);
  513. i++;
  514. }
  515. },
  516. };
  517. /*wifi easymode
  518. * wifi-2-main transfer
  519. * send msg from wifi to main
  520. */
  521. Blockly.Blocks['AiEasymode_transfer2_send'] = {
  522. init: function () {
  523. this.appendDummyInput()
  524. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  525. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  526. // this.appendDummyInput()
  527. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_SEND)
  528. // .appendField(new Blockly.FieldDropdown([
  529. // ["txData", "txData"]
  530. // ]), "DATAMAIN");
  531. this.appendDummyInput()
  532. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_LINE2);
  533. this.appendValueInput("ADD0")
  534. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + "0");
  535. this.setColour("#435592");
  536. this.setPreviousStatement(true, null);
  537. this.setNextStatement(true, null);
  538. // this.setInputsInline(true);
  539. this.setTooltip("");
  540. this.setHelpUrl("");
  541. this.itemCount_ = 1;
  542. this.updateShape_();
  543. this.setMutator(new Blockly.Mutator(['MainEasymode_transfer_create_with_item']));
  544. },
  545. mutationToDom: function () {
  546. var container = document.createElement('mutation');
  547. container.setAttribute('items', this.itemCount_);
  548. return container;
  549. },
  550. /**
  551. * Parse XML to restore the inputs.
  552. * @param {!Element} xmlElement XML storage element.
  553. * @this Blockly.Block
  554. */
  555. domToMutation: function (xmlElement) {
  556. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  557. this.updateShape_();
  558. },
  559. /**
  560. * Populate the mutator's dialog with this block's components.
  561. * @param {!Blockly.Workspace} workspace Mutator's workspace.
  562. * @return {!Blockly.Block} Root block in mutator.
  563. * @this Blockly.Block
  564. */
  565. decompose: function (workspace) {
  566. var containerBlock = workspace.newBlock('MainEasymode_transfer_create_with_container');
  567. containerBlock.initSvg();
  568. var connection = containerBlock.getInput('STACK').connection;
  569. for (var i = 0; i < this.itemCount_; i++) {
  570. var itemBlock = workspace.newBlock('MainEasymode_transfer_create_with_item');
  571. itemBlock.initSvg();
  572. connection.connect(itemBlock.previousConnection);
  573. connection = itemBlock.nextConnection;
  574. }
  575. return containerBlock;
  576. },
  577. /**
  578. * Reconfigure this block based on the mutator dialog's components.
  579. * @param {!Blockly.Block} containerBlock Root block in mutator.
  580. * @this Blockly.Block
  581. */
  582. compose: function (containerBlock) {
  583. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  584. // Count number of inputs.
  585. var connections = [];
  586. while (itemBlock) {
  587. connections.push(itemBlock.valueConnection_);
  588. itemBlock = itemBlock.nextConnection &&
  589. itemBlock.nextConnection.targetBlock();
  590. }
  591. // Disconnect any children that don't belong.
  592. for (var i = 0; i < this.itemCount_; i++) {
  593. var connection = this.getInput('ADD' + i).connection.targetConnection;
  594. if (connection && connections.indexOf(connection) == -1) {
  595. connection.disconnect();
  596. }
  597. }
  598. this.itemCount_ = connections.length;
  599. this.updateShape_();
  600. // Reconnect any child blocks.
  601. for (var i = 0; i < this.itemCount_; i++) {
  602. Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
  603. }
  604. },
  605. /**
  606. * Store pointers to any connected child blocks.
  607. * @param {!Blockly.Block} containerBlock Root block in mutator.
  608. * @this Blockly.Block
  609. */
  610. saveConnections: function (containerBlock) {
  611. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  612. var i = 0;
  613. while (itemBlock) {
  614. var input = this.getInput('ADD' + i);
  615. itemBlock.valueConnection_ = input && input.connection.targetConnection;
  616. i++;
  617. itemBlock = itemBlock.nextConnection &&
  618. itemBlock.nextConnection.targetBlock();
  619. }
  620. },
  621. /**
  622. * Modify this block to have the correct number of inputs.
  623. * @private
  624. * @this Blockly.Block
  625. */
  626. updateShape_: function () {
  627. if (this.itemCount_ && this.getInput('EMPTY')) {
  628. this.removeInput('EMPTY');
  629. } else if (!this.itemCount_ && !this.getInput('EMPTY')) {
  630. this.appendDummyInput('EMPTY')
  631. .appendField(this.newQuote_(true))
  632. .appendField(this.newQuote_(false));
  633. }
  634. // Add new inputs.
  635. for (var i = 0; i < this.itemCount_; i++) {
  636. if (!this.getInput('ADD' + i)) {
  637. var input = this.appendValueInput('ADD' + i)
  638. .appendField(Blockly.Msg.MAINEASYMODE_TRANSFER_SEND_VALUE + i);
  639. }
  640. }
  641. while (this.getInput('ADD' + i)) {
  642. this.removeInput('ADD' + i);
  643. i++;
  644. }
  645. },
  646. };
  647. Blockly.Blocks['MainEasymode_transfer_create_with_container'] = {
  648. /**
  649. * Mutator block for list container.
  650. * @this Blockly.Block
  651. */
  652. init: function () {
  653. this.setColour(Blockly.Blocks.mainwifi.HUE);
  654. this.appendDummyInput()
  655. .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_CONTAINER_TITLE_ADD);
  656. this.appendStatementInput('STACK');
  657. this.setTooltip('');
  658. this.contextMenu = false;
  659. }
  660. };
  661. Blockly.Blocks['MainEasymode_transfer_create_with_item'] = {
  662. /**
  663. * Mutator bolck for adding items.
  664. * @this Blockly.Block
  665. */
  666. init: function () {
  667. this.setColour(Blockly.Blocks.mainwifi.HUE);
  668. this.appendDummyInput()
  669. .appendField(Blockly.Msg.THINGSPEAK_CREATE_WITH_ITEM_TITLE);
  670. this.setPreviousStatement(true);
  671. this.setNextStatement(true);
  672. this.setTooltip('');
  673. this.contextMenu = false;
  674. }
  675. };
  676. /*wifi easymode
  677. * wifi-2-main transfer
  678. * receive msg from main to wifi
  679. */
  680. Blockly.Blocks['MainEasymode_transfer2_receive'] = {
  681. init: function () {
  682. this.appendDummyInput()
  683. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  684. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  685. this.appendDummyInput()
  686. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
  687. // this.appendDummyInput()
  688. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
  689. // .appendField(new Blockly.FieldDropdown([
  690. // ["rxData", "rxData"]
  691. // ]), "DATAMAIN");
  692. this.appendDummyInput()
  693. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
  694. .appendField(new Blockly.FieldDropdown([
  695. ["1", "1"],
  696. ["2", "2"],
  697. ["3", "3"],
  698. ["4", "4"],
  699. ["5", "5"],
  700. ["6", "6"],
  701. ["7", "7"],
  702. ["8", "8"],
  703. ["9", "9"],
  704. ["10", "10"],
  705. ["11", "11"],
  706. ["12", "12"],
  707. ]), "LENGTH");
  708. this.setColour(Blockly.Blocks.mainwifi.HUE);
  709. this.setPreviousStatement(true, null);
  710. this.setNextStatement(true, null);
  711. // this.setInputsInline(true);
  712. this.setTooltip("");
  713. this.setHelpUrl("");
  714. },
  715. getVarType: function (varName) {
  716. let vartype = Blockly.Types.ARRAY;
  717. return vartype;
  718. }
  719. }
  720. /*wifi easymode
  721. * wifi-2-main transfer
  722. * receive msg from main to wifi
  723. */
  724. Blockly.Blocks['AiEasymode_transfer2_receive'] = {
  725. init: function () {
  726. this.appendDummyInput()
  727. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/cocomod_blockly_wifi.png", 140, 40, "0"));
  728. .appendField(new Blockly.FieldImage("./../blockly/media/transfer-1.png", 50, 40, "0"));
  729. this.appendDummyInput()
  730. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE)
  731. // this.appendDummyInput()
  732. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE2)
  733. // .appendField(new Blockly.FieldDropdown([
  734. // ["rxData", "rxData"]
  735. // ]), "DATAMAIN");
  736. this.appendDummyInput()
  737. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_LINE3)
  738. .appendField(new Blockly.FieldDropdown([
  739. ["1", "1"],
  740. ["2", "2"],
  741. ["3", "3"],
  742. ["4", "4"],
  743. ["5", "5"],
  744. ["6", "6"],
  745. ["7", "7"],
  746. ["8", "8"],
  747. ["9", "9"],
  748. ["10", "10"],
  749. ["11", "11"],
  750. ["12", "12"],
  751. ]), "LENGTH");
  752. this.setColour("#435592");
  753. this.setPreviousStatement(true, null);
  754. this.setNextStatement(true, null);
  755. // this.setInputsInline(true);
  756. this.setTooltip("");
  757. this.setHelpUrl("");
  758. },
  759. getVarType: function (varName) {
  760. let vartype = Blockly.Types.ARRAY;
  761. return vartype;
  762. }
  763. }
  764. /*wifi easymode
  765. * wifi-2-main transfer
  766. * get data from dataMain
  767. * @param {dataMain} :where data tranferred stored in
  768. */
  769. Blockly.Blocks['MainEasymode_transfer2_receive_getValue'] = {
  770. init: function () {
  771. this.appendDummyInput()
  772. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
  773. // .appendField(new Blockly.FieldDropdown([
  774. // ["rxData", "rxData"]
  775. // ]), "DATAMAIN")
  776. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
  777. .appendField(new Blockly.FieldDropdown([
  778. ["0", "0"],
  779. ["1", "1"],
  780. ["2", "2"],
  781. ]), "INDEX")
  782. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
  783. // .appendField(new Blockly.FieldDropdown([
  784. // ["String", ""],
  785. // ["Number", ".toInt()"],
  786. // ["Float", ".toFloat()"],
  787. // ]), "TYPE")
  788. //.appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
  789. this.setColour(Blockly.Blocks.mainwifi.HUE);
  790. this.setOutput(true)
  791. // this.setInputsInline(true);
  792. this.setTooltip("");
  793. this.setHelpUrl("");
  794. },
  795. getBlockType: function () {
  796. var type = this.getFieldValue("TYPE");
  797. switch (type) {
  798. case "":
  799. return Blockly.Types.TEXT;
  800. case ".toInt()":
  801. return Blockly.Types.NUMBER;
  802. case ".toFloat()":
  803. return Blockly.Types.LARGE_NUMBER;
  804. }
  805. return Blockly.Types.NUMBER;
  806. },
  807. getOutputType: function () {
  808. var type = this.getFieldValue("TYPE");
  809. switch (type) {
  810. case "":
  811. return Blockly.Types.TEXT.output
  812. case ".toInt()":
  813. return Blockly.Types.NUMBER.output;
  814. case ".toFloat()":
  815. return Blockly.Types.LARGE_NUMBER.output;
  816. }
  817. return Blockly.Types.NUMBER.output;
  818. }
  819. }
  820. /*wifi easymode
  821. * wifi-2-main transfer
  822. * get data from dataMain
  823. * @param {dataMain} :where data tranferred stored in
  824. */
  825. Blockly.Blocks['AiEasymode_transfer2_receive_getValue'] = {
  826. init: function () {
  827. this.appendDummyInput()
  828. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET)
  829. // .appendField(new Blockly.FieldDropdown([
  830. // ["rxData", "rxData"]
  831. // ]), "DATAMAIN")
  832. .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE2)
  833. .appendField(new Blockly.FieldDropdown([
  834. ["0", "0"],
  835. ["1", "1"],
  836. ["2", "2"],
  837. ]), "INDEX")
  838. // .appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE3)
  839. // .appendField(new Blockly.FieldDropdown([
  840. // ["String", ""],
  841. // ["Number", ".toInt()"],
  842. // ["Float", ".toFloat()"],
  843. // ]), "TYPE")
  844. //.appendField(" " + Blockly.Msg.MAINEASYMODE_TRANSFER_RECEIVE_GET_LINE4)
  845. this.setColour("#435592");
  846. this.setOutput(true)
  847. // this.setInputsInline(true);
  848. this.setTooltip("");
  849. this.setHelpUrl("");
  850. },
  851. getBlockType: function () {
  852. var type = this.getFieldValue("TYPE");
  853. switch (type) {
  854. case "":
  855. return Blockly.Types.TEXT;
  856. case ".toInt()":
  857. return Blockly.Types.NUMBER;
  858. case ".toFloat()":
  859. return Blockly.Types.LARGE_NUMBER;
  860. }
  861. return Blockly.Types.NUMBER;
  862. },
  863. getOutputType: function () {
  864. var type = this.getFieldValue("TYPE");
  865. switch (type) {
  866. case "":
  867. return Blockly.Types.TEXT.output
  868. case ".toInt()":
  869. return Blockly.Types.NUMBER.output;
  870. case ".toFloat()":
  871. return Blockly.Types.LARGE_NUMBER.output;
  872. }
  873. return Blockly.Types.NUMBER.output;
  874. }
  875. }