/**
 * @license Licensed under the Apache License, Version 2.0 (the "License"):
 *          http://www.apache.org/licenses/LICENSE-2.0
 *
 * @fileoverview Blocks for Arduino Time functions.
 *               The arduino built in functions syntax can be found in
 *               http://arduino.cc/en/Reference/HomePage
 */
'use strict';

goog.provide('Blockly.Blocks.Arduino.time');

goog.require('Blockly.Arduino');


Blockly.Blocks.Arduino.time.HUE = 120;

Blockly.Blocks['time_delay'] = {
  /**
   * Delay block definition
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('http://arduino.cc/en/Reference/Delay');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendValueInput(
          'DELAY_TIME_MILI', Blockly.StaticTyping.blocklyType.NUMBER)
        .setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
        .appendField('wait');
    this.appendDummyInput()
        .appendField('milliseconds');
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('Wait specific time in milliseconds');
  }
};

Blockly.Blocks['time_delaymicros'] = {
  /**
   * delayMicroseconds block definition
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('http://arduino.cc/en/Reference/DelayMicroseconds');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendValueInput(
        'DELAY_TIME_MICRO', Blockly.StaticTyping.blocklyType.NUMBER)
        .setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
        .appendField('wait');
    this.appendDummyInput()
        .appendField('microseconds');
    this.setInputsInline(true);
    this.setPreviousStatement(true, null);
    this.setNextStatement(true, null);
    this.setTooltip('Wait specific time in microseconds');
  }
};

Blockly.Blocks['time_millis'] = {
  /**
   * Elapsed time in milliseconds block definition
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('http://arduino.cc/en/Reference/Millis');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendDummyInput('')
        .appendField('elapsed Time (milliseconds)');
    this.setOutput(true, Blockly.StaticTyping.blocklyType.NUMBER);
    this.setTooltip('Returns the number of milliseconds since the Arduino ' +
                    'board began running the current program.');
  },
  /**
   * Retrieves the type of the block, should be a long (32bit), but  for for
   * now an int.
   */
  getType: function() {
    return Blockly.StaticTyping.blocklyType.INTEGER;
  }
};

Blockly.Blocks['time_micros'] = {
  /**
   * Elapsed time in microseconds block definition
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('http://arduino.cc/en/Reference/Micros');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendDummyInput('')
        .appendField('elapsed Time (microseconds)');
    this.setOutput(true, Blockly.StaticTyping.blocklyType.NUMBER);
    this.setTooltip('Returns the number of microseconds since the Arduino ' +
                    'board began running the current program.');
  },
  /**
   * Retrieves the type of the block, should be a long (32bit), but  for for
   * now an int.
   */
  getType: function() {
    return Blockly.StaticTyping.blocklyType.INTEGER;
  }
};

Blockly.Blocks['infinite_loop'] = {
  /**
   * Waits forever, end of program.
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendDummyInput()
        .appendField('wait forever (end program)');
    this.setInputsInline(true);
    this.setPreviousStatement(true);
    this.setTooltip('Wait indefinitely, stopping the program.');
  }
};

Blockly.Blocks['infinite_loop'] = {
  /**
   * Waits forever, end of program.
   * @this Blockly.Block
   */
  init: function() {
    this.setHelpUrl('');
    this.setColour(Blockly.Blocks.Arduino.time.HUE);
    this.appendDummyInput()
        .appendField('wait forever (end program)');
    this.setInputsInline(true);
    this.setPreviousStatement(true);
    this.setTooltip('Wait indefinitely, stopping the program.');
  }
};

@@ -411,16 +411,71 @@
 no');%0A%0A%0A
+/** Common HSV hue for all blocks in this category. */%0A
 Blockly.
@@ -501,17 +501,17 @@
 .HUE = 1
-2
+4
 0;%0A%0ABloc
@@ -2169,32 +2169,40 @@
   .appendField('
+current 
 elapsed Time (mi
@@ -2440,105 +2440,77 @@
  /**
-%0A   * Retrieves the type of the block, should be a long (32bit), but  for for%0A   * now
+ @return %7Bstring%7D The type of return value for the block,
  an int
-.%0A  
+eger.
  */%0A
@@ -2904,16 +2904,24 @@
 dField('
+current 
 elapsed 
@@ -3173,42 +3173,9 @@
   * 
-Retrieves the type of the block, s
+S
 houl
@@ -3207,21 +3207,16 @@
  for for
-%0A   *
  now an 
@@ -3228,197 +3228,77 @@
    *
-/%0A  getType: function() %7B%0A    return Blockly.StaticTyping.blocklyType.INTEGER;%0A  %7D%0A%7D;%0A%0ABlockly.Blocks%5B'infinite_loop'%5D = %7B%0A  /**%0A   * Waits forever, end of program.%0A   * @this Blockly.Block
+ @return %7Bstring%7D The type of return value for the block, an integer.
 %0A   
@@ -3294,36 +3294,39 @@
 nteger.%0A   */%0A  
-init
+getType
 : function() %7B%0A 
@@ -3332,294 +3332,55 @@
     
-this.setHelpUrl('');%0A    this.setColour(Blockly.Blocks.Arduino.time.HUE);%0A    this.appendDummyInput()%0A        .appendField('wait forever (end program)');%0A    this.setInputsInline(true);%0A    this.setPreviousStatement(true);%0A    this.setTooltip('Wait indefinitely, stopping the program.')
+return Blockly.StaticTyping.blocklyType.INTEGER
 ;%0A  

Remove duplication in time block. Not quite sure how that sneaked into the file to begin with...