time.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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_delayseconds'] = {
  55. /**
  56. * delayMicroseconds block definition
  57. * @this Blockly.Block
  58. */
  59. init: function () {
  60. this.setHelpUrl('');
  61. this.setColour(Blockly.Blocks.time.HUE);
  62. this.appendValueInput('DELAY_TIME_MICRO')
  63. //.setCheck(Blockly.Types.NUMBER.checkList)
  64. .appendField(Blockly.Msg.ARD_TIME_DELAY);
  65. this.appendDummyInput()
  66. .appendField(Blockly.Msg.ARD_TIME_DELAY_seconds);
  67. this.setInputsInline(true);
  68. this.setPreviousStatement(true, null);
  69. this.setNextStatement(true, null);
  70. this.setTooltip(Blockly.Msg.ARD_TIME_DELAY_seconds_TIP);
  71. }
  72. };
  73. Blockly.Blocks['time_millis'] = {
  74. /**
  75. * Elapsed time in milliseconds block definition
  76. * @this Blockly.Block
  77. */
  78. init: function () {
  79. this.setHelpUrl('http://arduino.cc/en/Reference/Millis');
  80. this.setColour(Blockly.Blocks.time.HUE);
  81. this.appendDummyInput()
  82. // .appendField("")
  83. // .appendField(new Blockly.FieldDropdown([["IoT 模組 ","on_esp32"], ["AI 模組","on_ai"]]), "type")
  84. .appendField(Blockly.Msg.ARD_TIME_MILLIS);
  85. this.setOutput(true);
  86. this.setTooltip(Blockly.Msg.ARD_TIME_MILLIS_TIP);
  87. },
  88. /** @return {string} The type of return value for the block, an integer. */
  89. getBlockType: function () {
  90. return Blockly.Types.LARGE_NUMBER;
  91. }
  92. };
  93. Blockly.Blocks['time_micros'] = {
  94. /**
  95. * Elapsed time in microseconds block definition
  96. * @this Blockly.Block
  97. */
  98. init: function () {
  99. this.setHelpUrl('http://arduino.cc/en/Reference/Micros');
  100. this.setColour(Blockly.Blocks.time.HUE);
  101. this.appendDummyInput()
  102. // .appendField("")
  103. // .appendField(new Blockly.FieldDropdown([["IoT 模組 ","on_esp32"], ["AI 模組","on_ai"]]), "type")
  104. .appendField(Blockly.Msg.ARD_TIME_MICROS);
  105. this.setOutput(true);
  106. this.setTooltip(Blockly.Msg.ARD_TIME_MICROS_TIP);
  107. },
  108. /**
  109. * Should be a long (32bit), but for for now an int.
  110. * @return {string} The type of return value for the block, an integer.
  111. */
  112. getBlockType: function () {
  113. return Blockly.Types.LARGE_NUMBER;
  114. }
  115. };
  116. Blockly.Blocks['infinite_loop'] = {
  117. /**
  118. * Waits forever, end of program.
  119. * @this Blockly.Block
  120. */
  121. init: function () {
  122. this.setHelpUrl('');
  123. this.setColour(Blockly.Blocks.time.HUE);
  124. this.appendDummyInput()
  125. .appendField(Blockly.Msg.ARD_TIME_INF);
  126. this.setInputsInline(true);
  127. this.setPreviousStatement(true);
  128. this.setTooltip(Blockly.Msg.ARD_TIME_INF_TIP);
  129. }
  130. };
  131. /**
  132. * Chrono Stopwatch
  133. * record current time passed
  134. */
  135. Blockly.Blocks['time_chrono_setup'] = {
  136. /**
  137. * Chrono.h Setup
  138. * @this Blockly.Block
  139. */
  140. init: function () {
  141. this.appendDummyInput()
  142. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/stopwatch-header.png", 180, 40, "0"));
  143. .appendField(new Blockly.FieldImage("./../blockly/media/stopwatch-header.png", 40, 40, "0"));
  144. this.appendDummyInput()
  145. .appendField(Blockly.Msg.ARD_TIME_CHRONO_SETUP);
  146. this.setHelpUrl('');
  147. this.setColour("#eeaf3c");
  148. this.setTooltip(Blockly.Msg.ARD_TIME_INF_TIP);
  149. }
  150. };
  151. /**
  152. * Chrono Stopwatch
  153. * record current time passed
  154. */
  155. Blockly.Blocks['time_chrono_reset'] = {
  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_RESET)
  165. this.setPreviousStatement(true, null);
  166. this.setNextStatement(true, null);
  167. this.setTooltip("");
  168. }
  169. };
  170. /**
  171. * Chrono Stopwatch
  172. * record current time passed
  173. */
  174. Blockly.Blocks['time_chrono_elapsed'] = {
  175. /**
  176. * Chrono.h Setup
  177. * @this Blockly.Block
  178. */
  179. init: function () {
  180. this.setHelpUrl('');
  181. this.setColour("#eeaf3c");
  182. this.appendDummyInput()
  183. .appendField(Blockly.Msg.ARD_TIME_CHRONO_ELAPSED)
  184. this.setOutput(true)
  185. this.setTooltip("");
  186. }
  187. };
  188. /**
  189. * Chrono Stopwatch
  190. * check time for passed
  191. */
  192. Blockly.Blocks['time_chrono_timeCheck'] = {
  193. /**
  194. * Chrono.h Setup
  195. * @this Blockly.Block
  196. */
  197. init: function () {
  198. this.setHelpUrl('');
  199. this.setColour("#eeaf3c");
  200. this.appendValueInput("TIME")
  201. .appendField(Blockly.Msg.ARD_TIME_CHRONO_CHECK)
  202. this.appendDummyInput()
  203. .appendField(Blockly.Msg.ARD_TIME_CHRONO_CHECK1)
  204. this.setInputsInline(true);
  205. this.setOutput(true);
  206. this.setTooltip("");
  207. }
  208. };
  209. /**
  210. * time counter
  211. * counter time every @param {Int} num seconds
  212. * @this Blockly.Block
  213. */
  214. Blockly.Blocks['time_everySecond'] = {
  215. init: function () {
  216. this.setColour(Blockly.Blocks.time.HUE);
  217. this.appendValueInput("TIME")
  218. .appendField(Blockly.Msg.ARD_TIME_EVERY);
  219. this.appendDummyInput()
  220. .appendField(Blockly.Msg.ARD_TIME_SECOND);
  221. this.appendStatementInput("STACK")
  222. .appendField(Blockly.Msg.ARD_TIME_DO)
  223. // this.setOutput(true, Blockly.Types.BOOLEAN.output);
  224. this.setPreviousStatement(true);
  225. this.setNextStatement(true)
  226. },
  227. };
  228. /**
  229. * time counter (ms version)
  230. * counter time every @param {Int} num milliseconds
  231. * @this Blockly.Block
  232. */
  233. Blockly.Blocks['time_everyMilliSecond'] = {
  234. init: function () {
  235. this.setColour(Blockly.Blocks.time.HUE);
  236. this.appendValueInput("TIME")
  237. .appendField(Blockly.Msg.ARD_TIME_EVERY_MS);
  238. this.appendDummyInput()
  239. .appendField(Blockly.Msg.ARD_TIME_SECOND_MS);
  240. this.appendStatementInput("STACK")
  241. .appendField(Blockly.Msg.ARD_TIME_DO_MS)
  242. // this.setOutput(true, Blockly.Types.BOOLEAN.output);
  243. this.setPreviousStatement(true);
  244. this.setNextStatement(true)
  245. },
  246. };