blynk.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. 'use strict';
  2. goog.provide('Blockly.Blocks.blynk');
  3. goog.require('Blockly.Blocks');
  4. Blockly.Blocks.blynk.hue="#3a545a";
  5. Blockly.Blocks['blynk_setup'] = {
  6. init: function() {
  7. this.appendDummyInput()
  8. .appendField(new Blockly.FieldImage("./../blockly/media/blynk_header.png", 150, 60, "15"));
  9. this.appendDummyInput()
  10. .appendField(Blockly.Msg.BLYNK_SETUP)
  11. this.appendDummyInput()
  12. .appendField(Blockly.Msg.BLYNK_AUTH)
  13. .appendField(new Blockly.FieldTextInput("YourAuthToken"),"AUTH")
  14. this.appendDummyInput()
  15. .appendField(Blockly.Msg.BLYNK_WIFI)
  16. this.appendDummyInput()
  17. .appendField(Blockly.Msg.BLYNK_SSID)
  18. .appendField(new Blockly.FieldTextInput("CocoRobo"),"SSID")
  19. this.appendDummyInput()
  20. .appendField(Blockly.Msg.BLYNK_PW)
  21. .appendField(new Blockly.FieldTextInput("CocoRobo"),"PW")
  22. this.setColour(Blockly.Blocks.blynk.hue);
  23. this.setTooltip("");
  24. this.setHelpUrl("");
  25. },
  26. onchange: function() {
  27. let len = this.getFieldValue("PW").length;
  28. if (len > 0) {
  29. if (len > 20) {
  30. this.setWarningText(Blockly.Msg.WIFINETWORK_PW_WARN, 'blynk_pw');
  31. } else {
  32. this.setWarningText(null, 'blynk_pw');
  33. }
  34. } else if (len == 0) {
  35. if (len == 0) this.setFieldValue("cocorobo", "PW");
  36. }
  37. /** set limitation of AUTH input length */
  38. var text_content = this.getFieldValue("AUTH");
  39. if (text_content.length > 50) {
  40. this.setFieldValue(text_content.substring(0,50),"AUTH")
  41. }
  42. /** set limitation of SSID input length */
  43. var text_content = this.getFieldValue("SSID");
  44. if (text_content.length > 20) {
  45. this.setFieldValue(text_content.substring(0,20),"SSID")
  46. }
  47. /** set limitation of PW input length */
  48. var text_content = this.getFieldValue("PW");
  49. if (text_content.length > 20) {
  50. this.setFieldValue(text_content.substring(0,20),"PW")
  51. }
  52. }
  53. };
  54. /**
  55. *
  56. */
  57. Blockly.Blocks['blynk_write'] = {
  58. /**
  59. * Block for creating a digtial pin selector.
  60. * @this Blockly.Block
  61. */
  62. init: function() {
  63. this.appendDummyInput()
  64. .appendField(new Blockly.FieldImage("./../blockly/media/blynk_header_down.png", 150, 60, "15"));
  65. // this.appendDummyInput()
  66. // .appendField("BLYNK WRITE")
  67. this.appendDummyInput()
  68. .appendField(" "+ Blockly.Msg.BLYNK_SELECT)
  69. .appendField(new Blockly.FieldDropdown([
  70. ["Button","Button"],
  71. ["Slider","Slider"],
  72. ["Joystick","Joystick"],
  73. ["zeRGBa","zeRGBa"],
  74. ["Step","Step"],
  75. ["Light(sensor)","Light"],
  76. ["Gravity(sensor)","Gravity"],
  77. ["Accelerometer(sensor)","Accelerometer"],
  78. ["GPS(sensor)","GPS"],
  79. ]),"MOD")
  80. this.appendDummyInput()
  81. .appendField(" "+Blockly.Msg.BLYNK_WRITE)
  82. .appendField(new Blockly.FieldDropdown([
  83. ["V0","V0"],
  84. ["V1","V1"],
  85. ["V2","V2"],
  86. ["V3","V3"],
  87. ["V4","V4"],
  88. ["V5","V5"],
  89. ["V6","V6"],
  90. ["V7","V7"],
  91. ["V8","V8"],
  92. ["V9","V9"],
  93. ["V10","V10"],
  94. ["V11","V11"]
  95. ]),"PIN")
  96. .appendField(Blockly.Msg.BLYNK_WRITE1)
  97. this.appendStatementInput("STATEMENT");
  98. this.setColour(Blockly.Blocks.blynk.hue);
  99. this.setTooltip("");
  100. this.setHelpUrl("");
  101. },
  102. };
  103. Blockly.Blocks['blynk_write_getData'] = {
  104. init: function() {
  105. this.appendDummyInput("SELECT")
  106. .appendField(Blockly.Msg.BLYNK_GET_DATANAME)
  107. .appendField(new Blockly.FieldDropdown([
  108. ["Button","Button"],
  109. ["Slider","Slider"],
  110. // ["Joystick","Joystick"],
  111. // ["zeRGBa","zeRGBa"],
  112. ["Step","Step"],
  113. ["Light(sensor)","Light"],
  114. ]),"MOD")
  115. // .appendField(Blockly.Msg.BLYNK_GET_DATANAME1)
  116. .appendField(Blockly.Msg.BLYNK_GET_OF)
  117. this.setInputsInline(true)
  118. this.setColour(Blockly.Blocks.blynk.hue);
  119. this.setOutput(true,"Number");
  120. this.setTooltip("");
  121. this.setHelpUrl("");
  122. },
  123. getBlockType: function() {
  124. var numString = '1';
  125. return Blockly.Types.identifyNumber(numString);
  126. },
  127. // onchange:function() {
  128. // var mod = this.getFieldValue("MOD");
  129. // if (mod == "zeRGBa") {
  130. // if (this.getInput("INDEX2")) this.removeInput("INDEX2")
  131. // if (this.getInput("INDEX3")) this.removeInput("INDEX3")
  132. // if (!this.getInput("INDEX1")) {
  133. // this.appendDummyInput("INDEX1")
  134. // .appendField(Blockly.Msg.BLYNK_GET_OF1)
  135. // .appendField(new Blockly.FieldDropdown([
  136. // ["R", "0"],
  137. // ["G", "1"],
  138. // ["B", "2"]
  139. // ]),"SELINDEX")
  140. // .appendField(Blockly.Msg.BLYNK_GET_OF2)
  141. // }
  142. // } else if (mod == "Joystick") {
  143. // if (this.getInput("INDEX1")) this.removeInput("INDEX1")
  144. // if (this.getInput("INDEX3")) this.removeInput("INDEX3")
  145. // if (!this.getInput("INDEX2")) {
  146. // this.appendDummyInput("INDEX2")
  147. // .appendField(Blockly.Msg.BLYNK_GET_OF1)
  148. // .appendField(new Blockly.FieldDropdown([
  149. // ["X", "0"],
  150. // ["Y", "1"]
  151. // ]),"SELINDEX")
  152. // .appendField(Blockly.Msg.BLYNK_GET_OF2)
  153. // }
  154. // } else {
  155. // if (this.getInput("INDEX1")) this.removeInput("INDEX1");
  156. // if (this.getInput("INDEX2")) this.removeInput("INDEX2")
  157. // if (!this.getInput("INDEX3")) {
  158. // this.appendDummyInput("INDEX3")
  159. // .appendField(Blockly.Msg.BLYNK_GET_OF)
  160. // }
  161. // }
  162. // }
  163. };
  164. Blockly.Blocks['blynk_write_getData_joystick'] = {
  165. init: function() {
  166. this.appendDummyInput("SELECT")
  167. .appendField(Blockly.Msg.BLYNK_GET_DATANAME)
  168. .appendField(new Blockly.FieldDropdown([
  169. ["Joystick","Joystick"],
  170. ]),"MOD")
  171. this.appendDummyInput("INDEX2")
  172. .appendField(Blockly.Msg.BLYNK_GET_OF1)
  173. .appendField(new Blockly.FieldDropdown([
  174. ["X", "0"],
  175. ["Y", "1"]
  176. ]),"SELINDEX")
  177. .appendField(Blockly.Msg.BLYNK_GET_OF2)
  178. // .appendField(Blockly.Msg.BLYNK_GET_DATANAME1)
  179. this.setInputsInline(true)
  180. this.setColour(Blockly.Blocks.blynk.hue);
  181. this.setOutput(true,"Number");
  182. this.setTooltip("");
  183. this.setHelpUrl("");
  184. },
  185. getBlockType: function() {
  186. var numString = '1';
  187. return Blockly.Types.identifyNumber(numString);
  188. },
  189. };
  190. Blockly.Blocks['blynk_write_getData_zeRGBa'] = {
  191. init: function() {
  192. this.appendDummyInput("SELECT")
  193. .appendField(Blockly.Msg.BLYNK_GET_DATANAME)
  194. .appendField(new Blockly.FieldDropdown([
  195. ["zeRGBa","zeRGBa"],
  196. ]),"MOD")
  197. this.appendDummyInput("INDEX1")
  198. .appendField(Blockly.Msg.BLYNK_GET_OF1)
  199. .appendField(new Blockly.FieldDropdown([
  200. ["R", "0"],
  201. ["G", "1"],
  202. ["B", "2"]
  203. ]),"SELINDEX")
  204. .appendField(Blockly.Msg.BLYNK_GET_OF2)
  205. // .appendField(Blockly.Msg.BLYNK_GET_DATANAME1)
  206. this.setInputsInline(true)
  207. this.setColour(Blockly.Blocks.blynk.hue);
  208. this.setOutput(true,"Number");
  209. this.setTooltip("");
  210. this.setHelpUrl("");
  211. },
  212. getBlockType: function() {
  213. var numString = '1';
  214. return Blockly.Types.identifyNumber(numString);
  215. },
  216. };
  217. Blockly.Blocks['blynk_write_getData_GraOrAcc'] = {
  218. init: function() {
  219. this.appendDummyInput("SELECT")
  220. .appendField(Blockly.Msg.BLYNK_GET_DATANAME)
  221. .appendField(new Blockly.FieldDropdown([
  222. ["Gravity(sensor)","Gravity"],
  223. ["Accelerometer(sensor)","Accelerometer"],
  224. ]),"MOD")
  225. this.appendDummyInput("INDEX1")
  226. .appendField(Blockly.Msg.BLYNK_GET_OF1)
  227. .appendField(new Blockly.FieldDropdown([
  228. ["X", "0"],
  229. ["Y", "1"],
  230. ["Z", "2"]
  231. ]),"SELINDEX")
  232. .appendField(Blockly.Msg.BLYNK_GET_OF2)
  233. // .appendField(Blockly.Msg.BLYNK_GET_DATANAME1)
  234. this.setInputsInline(true)
  235. this.setColour(Blockly.Blocks.blynk.hue);
  236. this.setOutput(true,"Number");
  237. this.setTooltip("");
  238. this.setHelpUrl("");
  239. },
  240. getBlockType: function() {
  241. var numString = '1.000';
  242. return Blockly.Types.identifyNumber(numString);
  243. },
  244. };
  245. Blockly.Blocks['blynk_write_getData_GPS'] = {
  246. init: function() {
  247. this.appendDummyInput("SELECT")
  248. .appendField(Blockly.Msg.BLYNK_GET_DATANAME)
  249. .appendField(new Blockly.FieldDropdown([
  250. ["GPS(sensor)","GPS"],
  251. ]),"MOD")
  252. this.appendDummyInput("INDEX1")
  253. .appendField(Blockly.Msg.BLYNK_GET_OF1)
  254. .appendField(new Blockly.FieldDropdown([
  255. [Blockly.Msg.BLYNK_GPS_LATITUDE, "0"],
  256. [Blockly.Msg.BLYNK_GPS_LONGITUDE, "1"],
  257. [Blockly.Msg.BLYNK_GPS_ALTITUDE, "2"],
  258. [Blockly.Msg.BLYNK_GPS_SPEED, "3"],
  259. ]),"SELINDEX")
  260. .appendField(Blockly.Msg.BLYNK_GET_OF2)
  261. // .appendField(Blockly.Msg.BLYNK_GET_DATANAME1)
  262. this.setInputsInline(true)
  263. this.setColour(Blockly.Blocks.blynk.hue);
  264. this.setOutput(true,"Number");
  265. this.setTooltip("");
  266. this.setHelpUrl("");
  267. },
  268. getBlockType: function() {
  269. var numString = '1.000';
  270. return Blockly.Types.identifyNumber(numString);
  271. },
  272. };
  273. /**
  274. *
  275. */
  276. Blockly.Blocks['blynk_read'] = {
  277. /**
  278. * Block for creating a digtial pin selector.
  279. * @this Blockly.Block
  280. */
  281. init: function() {
  282. this.appendDummyInput()
  283. .appendField(new Blockly.FieldImage("./../blockly/media/blynk_header_up.png", 150, 60, "15"));
  284. this.appendDummyInput()
  285. .appendField(" "+ Blockly.Msg.BLYNK_SELECT)
  286. .appendField(new Blockly.FieldDropdown([
  287. ["Value Display","VD"],
  288. ["Label Dispaly","LD"],
  289. ["Gauge","GA"],
  290. ["Level","LE"],
  291. ]),"SELECT")
  292. this.appendDummyInput()
  293. .appendField(" "+Blockly.Msg.BLYNK_READ)
  294. .appendField(new Blockly.FieldDropdown([
  295. ["V0","V0"],
  296. ["V1","V1"],
  297. ["V2","V2"],
  298. ["V3","V3"],
  299. ["V4","V4"],
  300. ["V5","V5"],
  301. ["V6","V6"],
  302. ["V7","V7"],
  303. ["V8","V8"],
  304. ["V9","V9"],
  305. ["V10","V10"],
  306. ["V11","V11"]
  307. ]),"PIN")
  308. .appendField(Blockly.Msg.BLYNK_READ1)
  309. this.appendValueInput("ADD0")
  310. .appendField(Blockly.Msg.BLYNK_DATA+"01")
  311. .setAlign(Blockly.ALIGN_RIGHT)
  312. this.setColour(Blockly.Blocks.blynk.hue);
  313. this.setPreviousStatement(true);
  314. this.setNextStatement(true);
  315. this.itemCount_ = 1;
  316. this.updateShape_();
  317. this.setMutator(new Blockly.Mutator(['blynk_create_with_item']));
  318. this.setTooltip("");
  319. this.setHelpUrl("");
  320. },
  321. mutationToDom: function() {
  322. var container = document.createElement('mutation');
  323. container.setAttribute('items', this.itemCount_);
  324. return container;
  325. },
  326. /**
  327. * Parse XML to restore the inputs.
  328. * @param {!Element} xmlElement XML storage element.
  329. * @this Blockly.Block
  330. */
  331. domToMutation: function(xmlElement) {
  332. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  333. this.updateShape_();
  334. },
  335. /**
  336. * Populate the mutator's dialog with this block's components.
  337. * @param {!Blockly.Workspace} workspace Mutator's workspace.
  338. * @return {!Blockly.Block} Root block in mutator.
  339. * @this Blockly.Block
  340. */
  341. decompose: function(workspace) {
  342. var containerBlock = workspace.newBlock('blynk_create_with_container');
  343. containerBlock.initSvg();
  344. var connection = containerBlock.getInput('STACK').connection;
  345. for (var i = 0; i < this.itemCount_; i++) {
  346. var itemBlock = workspace.newBlock('blynk_create_with_item');
  347. itemBlock.initSvg();
  348. connection.connect(itemBlock.previousConnection);
  349. connection = itemBlock.nextConnection;
  350. }
  351. return containerBlock;
  352. },
  353. /**
  354. * Reconfigure this block based on the mutator dialog's components.
  355. * @param {!Blockly.Block} containerBlock Root block in mutator.
  356. * @this Blockly.Block
  357. */
  358. compose: function(containerBlock) {
  359. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  360. // Count number of inputs.
  361. var connections = [];
  362. while (itemBlock) {
  363. connections.push(itemBlock.valueConnection_);
  364. itemBlock = itemBlock.nextConnection &&
  365. itemBlock.nextConnection.targetBlock();
  366. }
  367. // Disconnect any children that don't belong.
  368. for (var i = 0; i < this.itemCount_; i++) {
  369. var connection = this.getInput('ADD' + i).connection.targetConnection;
  370. if (connection && connections.indexOf(connection) == -1) {
  371. connection.disconnect();
  372. }
  373. }
  374. this.itemCount_ = connections.length;
  375. this.updateShape_();
  376. // Reconnect any child blocks.
  377. for (var i = 0; i < this.itemCount_; i++) {
  378. Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
  379. }
  380. },
  381. /**
  382. * Store pointers to any connected child blocks.
  383. * @param {!Blockly.Block} containerBlock Root block in mutator.
  384. * @this Blockly.Block
  385. */
  386. saveConnections: function(containerBlock) {
  387. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  388. var i = 0;
  389. while (itemBlock) {
  390. var input = this.getInput('ADD' + i);
  391. itemBlock.valueConnection_ = input && input.connection.targetConnection;
  392. i++;
  393. itemBlock = itemBlock.nextConnection &&
  394. itemBlock.nextConnection.targetBlock();
  395. }
  396. },
  397. /**
  398. * Modify this block to have the correct number of inputs.
  399. * @private
  400. * @this Blockly.Block
  401. */
  402. updateShape_: function() {
  403. // Add new inputs.
  404. for (var i = 0; i < this.itemCount_; i++) {
  405. if (!this.getInput('ADD' + i)) {
  406. var input = this.appendValueInput('ADD' + i)
  407. .appendField(Blockly.Msg.BLYNK_DATA+"0"+(i+1))
  408. .setAlign(Blockly.ALIGN_RIGHT)
  409. }
  410. }
  411. while (this.getInput('ADD' + i)) {
  412. this.removeInput('ADD' + i);
  413. i++;
  414. }
  415. },
  416. };
  417. Blockly.Blocks['blynk_create_with_container'] = {
  418. /**
  419. * Mutator block for list container.
  420. * @this Blockly.Block
  421. */
  422. init: function() {
  423. this.setColour(Blockly.Blocks.blynk.hue);
  424. this.appendDummyInput()
  425. .appendField(Blockly.Msg.BLYNK_CREATE_WITH_CONTAINER_TITLE_ADD);
  426. this.appendStatementInput('STACK');
  427. this.setTooltip('');
  428. this.contextMenu = false;
  429. }
  430. };
  431. Blockly.Blocks['blynk_create_with_item'] = {
  432. /**
  433. * Mutator bolck for adding items.
  434. * @this Blockly.Block
  435. */
  436. init: function() {
  437. this.setColour(Blockly.Blocks.blynk.hue);
  438. this.appendDummyInput()
  439. .appendField(Blockly.Msg.BLYNK_CREATE_WITH_ITEM_TITLE);
  440. this.setPreviousStatement(true);
  441. this.setNextStatement(true);
  442. this.setTooltip('');
  443. this.contextMenu = false;
  444. }
  445. };
  446. Blockly.Blocks['blynk_virtualWrite'] = {
  447. init: function() {
  448. this.appendDummyInput()
  449. .appendField(Blockly.Msg.BLYNK_VIRTUALWRITE)
  450. .appendField(new Blockly.FieldDropdown([
  451. ["V1","V1"],
  452. ["V2","V2"],
  453. ["V3","V3"],
  454. ["V4","V4"],
  455. ["V5","V5"],
  456. ["V6","V6"],
  457. ["V7","V7"],
  458. ["V8","V8"],
  459. ["V9","V9"],
  460. ["V10","V10"],
  461. ["V11","V11"],
  462. ]),"PIN")
  463. this.appendValueInput("ADD0")
  464. .appendField(Blockly.Msg.BLYNK_DATA+"01")
  465. .setAlign(Blockly.ALIGN_RIGHT)
  466. this.setColour(Blockly.Blocks.blynk.hue);
  467. this.setPreviousStatement(true);
  468. this.setNextStatement(true);
  469. this.itemCount_ = 1;
  470. this.updateShape_();
  471. this.setMutator(new Blockly.Mutator(['blynk_create_with_item']));
  472. this.setTooltip("");
  473. this.setHelpUrl("");
  474. },
  475. mutationToDom: function() {
  476. var container = document.createElement('mutation');
  477. container.setAttribute('items', this.itemCount_);
  478. return container;
  479. },
  480. /**
  481. * Parse XML to restore the inputs.
  482. * @param {!Element} xmlElement XML storage element.
  483. * @this Blockly.Block
  484. */
  485. domToMutation: function(xmlElement) {
  486. this.itemCount_ = parseInt(xmlElement.getAttribute('items'), 10);
  487. this.updateShape_();
  488. },
  489. /**
  490. * Populate the mutator's dialog with this block's components.
  491. * @param {!Blockly.Workspace} workspace Mutator's workspace.
  492. * @return {!Blockly.Block} Root block in mutator.
  493. * @this Blockly.Block
  494. */
  495. decompose: function(workspace) {
  496. var containerBlock = workspace.newBlock('blynk_create_with_container');
  497. containerBlock.initSvg();
  498. var connection = containerBlock.getInput('STACK').connection;
  499. for (var i = 0; i < this.itemCount_; i++) {
  500. var itemBlock = workspace.newBlock('blynk_create_with_item');
  501. itemBlock.initSvg();
  502. connection.connect(itemBlock.previousConnection);
  503. connection = itemBlock.nextConnection;
  504. }
  505. return containerBlock;
  506. },
  507. /**
  508. * Reconfigure this block based on the mutator dialog's components.
  509. * @param {!Blockly.Block} containerBlock Root block in mutator.
  510. * @this Blockly.Block
  511. */
  512. compose: function(containerBlock) {
  513. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  514. // Count number of inputs.
  515. var connections = [];
  516. while (itemBlock) {
  517. connections.push(itemBlock.valueConnection_);
  518. itemBlock = itemBlock.nextConnection &&
  519. itemBlock.nextConnection.targetBlock();
  520. }
  521. // Disconnect any children that don't belong.
  522. for (var i = 0; i < this.itemCount_; i++) {
  523. var connection = this.getInput('ADD' + i).connection.targetConnection;
  524. if (connection && connections.indexOf(connection) == -1) {
  525. connection.disconnect();
  526. }
  527. }
  528. this.itemCount_ = connections.length;
  529. this.updateShape_();
  530. // Reconnect any child blocks.
  531. for (var i = 0; i < this.itemCount_; i++) {
  532. Blockly.Mutator.reconnect(connections[i], this, 'ADD' + i);
  533. }
  534. },
  535. /**
  536. * Store pointers to any connected child blocks.
  537. * @param {!Blockly.Block} containerBlock Root block in mutator.
  538. * @this Blockly.Block
  539. */
  540. saveConnections: function(containerBlock) {
  541. var itemBlock = containerBlock.getInputTargetBlock('STACK');
  542. var i = 0;
  543. while (itemBlock) {
  544. var input = this.getInput('ADD' + i);
  545. itemBlock.valueConnection_ = input && input.connection.targetConnection;
  546. i++;
  547. itemBlock = itemBlock.nextConnection &&
  548. itemBlock.nextConnection.targetBlock();
  549. }
  550. },
  551. /**
  552. * Modify this block to have the correct number of inputs.
  553. * @private
  554. * @this Blockly.Block
  555. */
  556. updateShape_: function() {
  557. // Add new inputs.
  558. for (var i = 0; i < this.itemCount_; i++) {
  559. if (!this.getInput('ADD' + i)) {
  560. var input = this.appendValueInput('ADD' + i)
  561. .appendField(Blockly.Msg.BLYNK_DATA+"0"+(i+1))
  562. .setAlign(Blockly.ALIGN_RIGHT)
  563. }
  564. }
  565. while (this.getInput('ADD' + i)) {
  566. this.removeInput('ADD' + i);
  567. i++;
  568. }
  569. },
  570. };
  571. Blockly.Blocks['blynk_timer'] = {
  572. init: function() {
  573. this.appendDummyInput()
  574. .appendField(new Blockly.FieldImage("./../blockly/media/blynk_time.png", 150, 60, "15"));
  575. this.appendDummyInput()
  576. .appendField(Blockly.Msg.BLYNK_TIME_SETTING)
  577. .appendField(new Blockly.FieldDropdown([
  578. ["1","1000"],
  579. ["2","2000"],
  580. ["3","3000"],
  581. ["4","4000"],
  582. ["5","5000"],
  583. ["6","6000"],
  584. ["7","7000"],
  585. ["8","8000"],
  586. ["9","9000"],
  587. ["10","10000"],
  588. ["15","11000"],
  589. ["30","30000"],
  590. ]),"TIME")
  591. .appendField(Blockly.Msg.BLYNK_TIME_SECOND)
  592. this.appendStatementInput("DO")
  593. .appendField(Blockly.Msg.BLYNK_TIME_DO)
  594. this.setColour(Blockly.Blocks.blynk.hue);
  595. // this.setPreviousStatement(true);
  596. // this.setNextStatement(true);
  597. this.setTooltip("");
  598. this.setHelpUrl("");
  599. }
  600. }
  601. //not used now
  602. Blockly.Blocks['blynk_connect'] = {
  603. /**
  604. * Block for creating a digtial pin selector.
  605. * @this Blockly.Block
  606. */
  607. init: function() {
  608. this.appendDummyInput()
  609. .appendField(new Blockly.FieldImage("./../blockly/media/blynk_header.png", 150, 60, "15"));
  610. this.appendDummyInput()
  611. .appendField(Blockly.Msg.BLYNK_CONNECT);
  612. this.appendStatementInput("STATEMENT");
  613. this.setColour(Blockly.Blocks.blynk.hue);
  614. this.setTooltip("");
  615. this.setHelpUrl("");
  616. },
  617. };
  618. //not used now
  619. Blockly.Blocks['blynk_log'] = {
  620. init: function() {
  621. this.appendDummyInput()
  622. .appendField(Blockly.Msg.BLYNK_LOG)
  623. this.appendValueInput("CONTENT")
  624. .setCheck(null);
  625. this.setPreviousStatement(true);
  626. this.setNextStatement(true);
  627. this.setInputsInline(true);
  628. this.setColour(Blockly.Blocks.blynk.hue);
  629. this.setTooltip('');
  630. this.setHelpUrl('');
  631. }
  632. };