time.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. * @license Licensed under the Apache License, Version 2.0 (the "License"):
  3. * http://www.apache.org/licenses/LICENSE-2.0
  4. */
  5. /**
  6. * @fileoverview Blocks for Arduino Time functions.
  7. * The arduino built in functions syntax can be found in
  8. * http://arduino.cc/en/Reference/HomePage
  9. */
  10. 'use strict';
  11. goog.provide('Blockly.Blocks.time');
  12. goog.require('Blockly.Blocks');
  13. goog.require('Blockly.Types');
  14. /** Common HSV hue for all blocks in this category. */
  15. Blockly.Blocks.time.HUE = "#fabe23";
  16. Blockly.Blocks['time_delay'] = {
  17. /**
  18. * Delay block definition
  19. * @this Blockly.Block
  20. */
  21. init: function () {
  22. this.setHelpUrl('http://arduino.cc/en/Reference/Delay');
  23. this.setColour(Blockly.Blocks.time.HUE);
  24. this.appendValueInput('DELAY_TIME_MILI')
  25. //.setCheck(Blockly.Types.NUMBER.checkList)
  26. .appendField(Blockly.Msg.ARD_TIME_DELAY);
  27. this.appendDummyInput()
  28. .appendField(Blockly.Msg.ARD_TIME_MS);
  29. this.setInputsInline(true);
  30. this.setPreviousStatement(true, null);
  31. this.setNextStatement(true, null);
  32. this.setTooltip(Blockly.Msg.ARD_TIME_DELAY_TIP);
  33. }
  34. };
  35. Blockly.Blocks['time_delaymicros'] = {
  36. /**
  37. * delayMicroseconds block definition
  38. * @this Blockly.Block
  39. */
  40. init: function () {
  41. this.setHelpUrl('http://arduino.cc/en/Reference/DelayMicroseconds');
  42. this.setColour(Blockly.Blocks.time.HUE);
  43. this.appendValueInput('DELAY_TIME_MICRO')
  44. //.setCheck(Blockly.Types.NUMBER.checkList)
  45. .appendField(Blockly.Msg.ARD_TIME_DELAY);
  46. this.appendDummyInput()
  47. .appendField(Blockly.Msg.ARD_TIME_DELAY_MICROS);
  48. this.setInputsInline(true);
  49. this.setPreviousStatement(true, null);
  50. this.setNextStatement(true, null);
  51. this.setTooltip(Blockly.Msg.ARD_TIME_DELAY_MICRO_TIP);
  52. }
  53. };
  54. Blockly.Blocks['time_millis'] = {
  55. /**
  56. * Elapsed time in milliseconds block definition
  57. * @this Blockly.Block
  58. */
  59. init: function () {
  60. this.setHelpUrl('http://arduino.cc/en/Reference/Millis');
  61. this.setColour(Blockly.Blocks.time.HUE);
  62. this.appendDummyInput()
  63. // .appendField("")
  64. // .appendField(new Blockly.FieldDropdown([["IoT 模組 ","on_esp32"], ["AI 模組","on_ai"]]), "type")
  65. .appendField(Blockly.Msg.ARD_TIME_MILLIS);
  66. this.setOutput(true);
  67. this.setTooltip(Blockly.Msg.ARD_TIME_MILLIS_TIP);
  68. },
  69. /** @return {string} The type of return value for the block, an integer. */
  70. getBlockType: function () {
  71. return Blockly.Types.LARGE_NUMBER;
  72. }
  73. };
  74. Blockly.Blocks['time_micros'] = {
  75. /**
  76. * Elapsed time in microseconds block definition
  77. * @this Blockly.Block
  78. */
  79. init: function () {
  80. this.setHelpUrl('http://arduino.cc/en/Reference/Micros');
  81. this.setColour(Blockly.Blocks.time.HUE);
  82. this.appendDummyInput()
  83. // .appendField("")
  84. // .appendField(new Blockly.FieldDropdown([["IoT 模組 ","on_esp32"], ["AI 模組","on_ai"]]), "type")
  85. .appendField(Blockly.Msg.ARD_TIME_MICROS);
  86. this.setOutput(true);
  87. this.setTooltip(Blockly.Msg.ARD_TIME_MICROS_TIP);
  88. },
  89. /**
  90. * Should be a long (32bit), but for for now an int.
  91. * @return {string} The type of return value for the block, an integer.
  92. */
  93. getBlockType: function () {
  94. return Blockly.Types.LARGE_NUMBER;
  95. }
  96. };
  97. Blockly.Blocks['infinite_loop'] = {
  98. /**
  99. * Waits forever, end of program.
  100. * @this Blockly.Block
  101. */
  102. init: function () {
  103. this.setHelpUrl('');
  104. this.setColour(Blockly.Blocks.time.HUE);
  105. this.appendDummyInput()
  106. .appendField(Blockly.Msg.ARD_TIME_INF);
  107. this.setInputsInline(true);
  108. this.setPreviousStatement(true);
  109. this.setTooltip(Blockly.Msg.ARD_TIME_INF_TIP);
  110. }
  111. };
  112. /**
  113. * Chrono Stopwatch
  114. * record current time passed
  115. */
  116. Blockly.Blocks['time_chrono_setup'] = {
  117. /**
  118. * Chrono.h Setup
  119. * @this Blockly.Block
  120. */
  121. init: function () {
  122. this.appendDummyInput()
  123. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/stopwatch-header.png", 180, 40, "0"));
  124. .appendField(new Blockly.FieldImage("./../blockly/media/stopwatch-header.png", 40, 40, "0"));
  125. this.appendDummyInput()
  126. .appendField(Blockly.Msg.ARD_TIME_CHRONO_SETUP);
  127. this.setHelpUrl('');
  128. this.setColour("#eeaf3c");
  129. this.setTooltip(Blockly.Msg.ARD_TIME_INF_TIP);
  130. }
  131. };
  132. /**
  133. * Chrono Stopwatch
  134. * record current time passed
  135. */
  136. Blockly.Blocks['time_chrono_reset'] = {
  137. /**
  138. * Chrono.h Setup
  139. * @this Blockly.Block
  140. */
  141. init: function () {
  142. this.setHelpUrl('');
  143. this.setColour("#eeaf3c");
  144. this.appendDummyInput()
  145. .appendField(Blockly.Msg.ARD_TIME_CHRONO_RESET)
  146. this.setPreviousStatement(true, null);
  147. this.setNextStatement(true, null);
  148. this.setTooltip("");
  149. }
  150. };
  151. /**
  152. * Chrono Stopwatch
  153. * record current time passed
  154. */
  155. Blockly.Blocks['time_chrono_elapsed'] = {
  156. /**
  157. * Chrono.h Setup
  158. * @this Blockly.Block
  159. */
  160. init: function () {
  161. this.setHelpUrl('');
  162. this.setColour("#eeaf3c");
  163. this.appendDummyInput()
  164. .appendField(Blockly.Msg.ARD_TIME_CHRONO_ELAPSED)
  165. this.setOutput(true)
  166. this.setTooltip("");
  167. }
  168. };
  169. /**
  170. * Chrono Stopwatch
  171. * check time for passed
  172. */
  173. Blockly.Blocks['time_chrono_timeCheck'] = {
  174. /**
  175. * Chrono.h Setup
  176. * @this Blockly.Block
  177. */
  178. init: function () {
  179. this.setHelpUrl('');
  180. this.setColour("#eeaf3c");
  181. this.appendValueInput("TIME")
  182. .appendField(Blockly.Msg.ARD_TIME_CHRONO_CHECK)
  183. this.appendDummyInput()
  184. .appendField(Blockly.Msg.ARD_TIME_CHRONO_CHECK1)
  185. this.setInputsInline(true);
  186. this.setOutput(true);
  187. this.setTooltip("");
  188. }
  189. };
  190. /**
  191. * time counter
  192. * counter time every @param {Int} num seconds
  193. * @this Blockly.Block
  194. */
  195. Blockly.Blocks['time_everySecond'] = {
  196. init: function () {
  197. this.setColour(Blockly.Blocks.time.HUE);
  198. this.appendValueInput("TIME")
  199. .appendField(Blockly.Msg.ARD_TIME_EVERY);
  200. this.appendDummyInput()
  201. .appendField(Blockly.Msg.ARD_TIME_SECOND);
  202. this.appendStatementInput("STACK")
  203. .appendField(Blockly.Msg.ARD_TIME_DO)
  204. // this.setOutput(true, Blockly.Types.BOOLEAN.output);
  205. this.setPreviousStatement(true);
  206. this.setNextStatement(true)
  207. },
  208. };
  209. /**
  210. * time counter (ms version)
  211. * counter time every @param {Int} num milliseconds
  212. * @this Blockly.Block
  213. */
  214. Blockly.Blocks['time_everyMilliSecond'] = {
  215. init: function () {
  216. this.setColour(Blockly.Blocks.time.HUE);
  217. this.appendValueInput("TIME")
  218. .appendField(Blockly.Msg.ARD_TIME_EVERY_MS);
  219. this.appendDummyInput()
  220. .appendField(Blockly.Msg.ARD_TIME_SECOND_MS);
  221. this.appendStatementInput("STACK")
  222. .appendField(Blockly.Msg.ARD_TIME_DO_MS)
  223. // this.setOutput(true, Blockly.Types.BOOLEAN.output);
  224. this.setPreviousStatement(true);
  225. this.setNextStatement(true)
  226. },
  227. };