diff --git a/ardublockly/ardublockly_toolbox.js b/ardublockly/ardublockly_toolbox.js
index 28c3c6283f..e23b4894f8 100644
--- a/ardublockly/ardublockly_toolbox.js
+++ b/ardublockly/ardublockly_toolbox.js
@@ -56,6 +56,7 @@ Ardublockly.TOOLBOX_XML =
' ' +
' ' +
' ' +
+' ' +
' ' +
' ' +
' ' +
diff --git a/blockly/blocks/math.js b/blockly/blocks/math.js
index 9df246612f..775498c8e1 100644
--- a/blockly/blocks/math.js
+++ b/blockly/blocks/math.js
@@ -226,6 +226,50 @@ Blockly.Blocks['math_trig'] = {
}
};
+Blockly.Blocks['math_ang'] = {
+ /**
+ * Block for angle operators.
+ * @this Blockly.Block
+ */
+ init: function() {
+ this.jsonInit({
+ "message0": "%1 %2",
+ "args0": [
+ {
+ "type": "field_dropdown",
+ "name": "OP",
+ "options": [
+ [Blockly.Msg.MATH_ANG_DEG, 'DEG'],
+ [Blockly.Msg.MATH_ANG_RAD, 'RAD']
+ ]
+ },
+ {
+ "type": "input_value",
+ "name": "NUM",
+ "check": Blockly.Types.DECIMAL.checkList
+ }
+ ],
+ "output": Blockly.Types.DECIMAL.output,
+ "colour": Blockly.Blocks.math.HUE,
+ "helpUrl": Blockly.Msg.MATH_AND_HELPURL
+ });
+ // Assign 'this' to a variable for use in the tooltip closure below.
+ var thisBlock = this;
+ this.setTooltip(function() {
+ var mode = thisBlock.getFieldValue('OP');
+ var TOOLTIPS = {
+ 'DEG': Blockly.Msg.MATH_ANG_TOOLTIP_DEG,
+ 'RAD': Blockly.Msg.MATH_ANG_TOOLTIP_RAD
+ };
+ return TOOLTIPS[mode];
+ });
+ },
+ /** @return {!string} Type of the block, all these operations are floats. */
+ getBlockType: function() {
+ return Blockly.Types.DECIMAL;
+ }
+};
+
Blockly.Blocks['math_constant'] = {
/**
* Block for constants: PI, E, the Golden Ratio, sqrt(2), 1/sqrt(2), INFINITY.
diff --git a/blockly/generators/arduino/math.js b/blockly/generators/arduino/math.js
index a7afb241ec..911d70e200 100644
--- a/blockly/generators/arduino/math.js
+++ b/blockly/generators/arduino/math.js
@@ -129,6 +129,9 @@ Blockly.Arduino['math_single'] = function(block) {
case 'TAN':
code = 'tan(' + arg + ' / 180 * Math.PI)';
break;
+ case 'RAD':
+ code = 'rad(' + arg + ' / 180 * Math.PI)';
+ break;
}
if (code) {
return [code, Blockly.Arduino.ORDER_UNARY_POSTFIX];
@@ -147,6 +150,9 @@ Blockly.Arduino['math_single'] = function(block) {
case 'ATAN':
code = 'atan(' + arg + ') / M_PI * 180';
break;
+ case 'DEG':
+ code = 'deg(' + arg + ') / M_PI * 180';
+ break;
default:
throw 'Unknown math operator: ' + operator;
}