not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.4 KiB

  1. //* comment *//
  2. Copyright (C) 2015 Ignacio Rodriguez
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. //* globals *//
  14. var accelerometer = {'x': null, 'y': null, 'z': null};
  15. function saveAccelerometerData(event) {
  16. accelerometer['x'] = event.accelerationIncludingGravity.x;
  17. accelerometer['y'] = event.accelerationIncludingGravity.y;
  18. accelerometer['z'] = event.accelerationIncludingGravity.z;
  19. };
  20. if (window.DeviceMotionEvent) {
  21. window.addEventListener("devicemotion", saveAccelerometerData, false);
  22. }
  23. else{
  24. console.log("DeviceMotionEvent is not supported (no accelerometer)");
  25. }
  26. //* arg:accelerometerx *//
  27. var block = logo.blocks.blockList[blk];
  28. block.value = accelerometer['x'];
  29. //* arg:accelerometery *//
  30. var block = logo.blocks.blockList[blk];
  31. block.value = accelerometer['y'];
  32. //* arg:accelerometerz *//
  33. var block = logo.blocks.blockList[blk];
  34. block.value = accelerometer['z'];
  35. //* block:accelerometerx *//
  36. var accelerometerXBlk = new ProtoBlock('accelerometerx');
  37. accelerometerXBlk.palette = palettes.dict['sensors'];
  38. blocks.protoBlockDict['accelerometerx'] = accelerometerXBlk;
  39. accelerometerXBlk.staticLabels.push(_('motion x'));
  40. accelerometerXBlk.adjustWidthToLabel();
  41. accelerometerXBlk.parameterBlock();
  42. //* block:accelerometery *//
  43. var accelerometerYBlk = new ProtoBlock('accelerometery');
  44. accelerometerYBlk.palette = palettes.dict['sensors'];
  45. blocks.protoBlockDict['accelerometery'] = accelerometerYBlk;
  46. accelerometerYBlk.staticLabels.push(_('motion y'));
  47. accelerometerYBlk.adjustWidthToLabel();
  48. accelerometerYBlk.parameterBlock();
  49. //* block:accelerometerz *//
  50. var accelerometerZBlk = new ProtoBlock('accelerometerz');
  51. accelerometerZBlk.palette = palettes.dict['sensors'];
  52. blocks.protoBlockDict['accelerometerz'] = accelerometerZBlk;
  53. accelerometerZBlk.staticLabels.push(_('motion z'));
  54. accelerometerZBlk.adjustWidthToLabel();
  55. accelerometerZBlk.parameterBlock();