map.js 997 B

12345678910111213141516171819202122232425262728293031
  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 Code generator for the Arduino map functionality.
  7. * Arduino built-in function docs: http://arduino.cc/en/Reference/HomePage
  8. */
  9. 'use strict';
  10. goog.provide('Blockly.Python.map');
  11. goog.require('Blockly.Python');
  12. /**
  13. * Code generator for the map block.
  14. * Arduino code: loop { map(x, 0, 1024, 0, y) }
  15. * @param {!Blockly.Block} block Block to generate the code from.
  16. * @return {array} Completed code with order of operation.
  17. */
  18. Blockly.Python['base_map'] = function(block) {
  19. var valueNum = Blockly.Python.valueToCode(
  20. block, 'NUM', Blockly.Python.ORDER_NONE) || '0';
  21. var valueDmax = Blockly.Python.valueToCode(
  22. block, 'DMAX', Blockly.Python.ORDER_ATOMIC) || '0';
  23. var code = 'map(' + valueNum + ', 0, 1024, 0, ' + valueDmax + ')';
  24. return [code, Blockly.Python.ORDER_NONE];
  25. };