motion.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Ardublockly JavaScript for the Blockly resources and bindings.
  7. */
  8. 'use strict';
  9. goog.provide('Blockly.Blocks.motion');
  10. goog.require('Blockly.Blocks');
  11. Blockly.Blocks.motion.HUE = 270;
  12. /*
  13. *block for motion setup
  14. */
  15. Blockly.Blocks['motion_setup'] = {
  16. init: function() {
  17. this.appendDummyInput()
  18. // .appendField(new Blockly.FieldImage("http://cocorobo.cn/cocoblockly/blockly/media/main-motion.png", 50, 40, "15"));
  19. .appendField(new Blockly.FieldImage("./../blockly/media/main-motion.png", 50, 40, "15"));
  20. this.appendDummyInput()
  21. .appendField(Blockly.Msg.MOTION_SETUP);
  22. //.appendField('MOTION_SETUP');
  23. this.setColour(Blockly.Blocks.motion.HUE);
  24. this.setTooltip('');
  25. this.setHelpUrl('');
  26. }
  27. };
  28. Blockly.Blocks['motion_onshake'] = {
  29. init: function() {
  30. this.appendDummyInput()
  31. .appendField(Blockly.Msg.MOTION_ONSHAKE)
  32. this.setOutput(true, Blockly.Types.BOOLEAN.output);
  33. this.setColour(Blockly.Blocks.motion.HUE);
  34. this.setTooltip('');
  35. this.setHelpUrl('');
  36. },
  37. getBlockType: function() {
  38. return Blockly.Types.BOOLEAN;
  39. }
  40. };
  41. Blockly.Blocks['motion_onDirection'] = {
  42. init: function() {
  43. this.appendDummyInput()
  44. .appendField(Blockly.Msg.MOTION_ONDIRECTION)
  45. .appendField(new Blockly.FieldDropdown([
  46. [Blockly.Msg.MOTION_ONDIRECTION_LEFT, "left"],
  47. [Blockly.Msg.MOTION_ONDIRECTION_RIGHT, "right"],
  48. [Blockly.Msg.MOTION_ONDIRECTION_FRONT, "front"],
  49. [Blockly.Msg.MOTION_ONDIRECTION_BACK, "back"],
  50. // [Blockly.Msg.MOTION_ONDIRECTION_CLOCKWISE, "clockwise"],
  51. // [Blockly.Msg.MOTION_ONDIRECTION_COUNTERCLOCKWISE, "counterClockwise"],
  52. ]), "DIRECTION")
  53. .appendField(Blockly.Msg.MOTION_ONDIRECTION1)
  54. this.setOutput(true, "Boolean");
  55. this.setColour(Blockly.Blocks.motion.HUE);
  56. this.setTooltip('');
  57. this.setHelpUrl('');
  58. }
  59. };
  60. Blockly.Blocks['motion_getRotation_ypr'] = {
  61. init: function() {
  62. this.appendDummyInput()
  63. .appendField(Blockly.Msg.MOTION_GETYPR)
  64. .appendField(new Blockly.FieldDropdown([
  65. ["yaw", "0"],
  66. ["pitch", "1"],
  67. ["roll", "2"]
  68. ]), "Rotation")
  69. .appendField(Blockly.Msg.MOTION_GETYPR1)
  70. this.setOutput(true, Blockly.Types.NUMBER.output);
  71. this.setColour(Blockly.Blocks.motion.HUE);
  72. this.setTooltip('');
  73. this.setHelpUrl('');
  74. },
  75. getBlockType: function() {
  76. return Blockly.Types.NUMBER;
  77. }
  78. }
  79. Blockly.Blocks['motion_getAcceleration'] = {
  80. init: function() {
  81. this.appendDummyInput()
  82. .appendField(Blockly.Msg.MOTION_GETACC)
  83. .appendField(new Blockly.FieldDropdown([
  84. ["x", "x"],
  85. ["y", "y"],
  86. ["z", "z"]
  87. ]), "Acceleration")
  88. .appendField(Blockly.Msg.MOTION_GETACC1)
  89. this.setOutput(true, Blockly.Types.NUMBER.output);
  90. this.setColour(Blockly.Blocks.motion.HUE);
  91. this.setTooltip('');
  92. this.setHelpUrl('');
  93. },
  94. getBlockType: function() {
  95. return Blockly.Types.NUMBER;
  96. }
  97. }