time.js 6.9 KB

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