load.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. function ready() {
  2. //machiineconnect("ws://localhost:8088");
  3. console.log('11111111111111111111111')
  4. //Ardublockly.initLanguage();
  5. $('.dropdown-trigger').dropdown();
  6. setTimeout(() => $('.modal').modal(), 0);
  7. blockpy = new BlockPy({
  8. blocklyPath: "blockly/",
  9. attachmentPoint: document.getElementById("blockpy-div"),
  10. instructor:
  11. !getQueryParams()["instructor"] ||
  12. getQueryParams()["instructor"] == "true",
  13. developer: true,
  14. editor: getQueryParams()["mode"] || "Split",
  15. urls: {
  16. }
  17. });
  18. setTimeout(() => {
  19. var _type = getLocalStorage("type") || 0;
  20. if (_type == 1) {
  21. $("#mode")[0].selectedIndex = 0;
  22. // $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
  23. selectmode($("#mode")[0], true);
  24. }
  25. else {
  26. $("#mode")[0].selectedIndex = 1;
  27. // $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
  28. selectmode($("#mode")[0], true);
  29. }
  30. }, 2000);
  31. function inIframe() {
  32. try {
  33. return window.self !== window.top;
  34. } catch (e) {
  35. return true;
  36. }
  37. }
  38. if (inIframe()) {
  39. $("#blockpy-container").width("100%");
  40. $("#blockpy-div").css("padding", 0);
  41. }
  42. };
  43. function selectmode(sel, isload) {
  44. var _type = getLocalStorage("type");
  45. if (sel.selectedIndex == 1 && (_type != 1 || isload === true)) {
  46. saveLocalStorageBlocks("pythonai-mode-blocks-xml");
  47. saveLocalStorage("type", 1);
  48. blockpy.setAssignment(
  49. // settings
  50. {},
  51. // assignment
  52. {
  53. modules: {
  54. added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "MainBoard", "ExtendedFunction"],
  55. removed: ['A.I.Board']
  56. }
  57. },
  58. // programs
  59. {
  60. __main__: ""
  61. }
  62. );
  63. loadLocalStorageBlocks("pythonmc-mode-blocks-xml")
  64. }
  65. else if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
  66. saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
  67. saveLocalStorage("type", 0);
  68. blockpy.setAssignment(
  69. // settings
  70. {},
  71. // assignment
  72. {
  73. modules: {
  74. added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "'aaa", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Output", "Files", "Time", "Serial Comm.", "A.I.Board", "ExtendedFunction"],
  75. removed: ['MainBoard']
  76. }
  77. },
  78. // programs
  79. {
  80. __main__: ""
  81. }
  82. );
  83. loadLocalStorageBlocks("pythonai-mode-blocks-xml")
  84. }
  85. }
  86. function getQueryParams() {
  87. try {
  88. url = window.location.href;
  89. query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
  90. r_params = query_str.split("&");
  91. params = {};
  92. for (i in r_params) {
  93. param = r_params[i].split("=");
  94. params[param[0]] = param[1];
  95. }
  96. return params;
  97. } catch (e) {
  98. return {};
  99. }
  100. }
  101. /*
  102. var aiySocket = new WebSocket("ws://localhost:8089");
  103. aiySocket.onopen = function (event) {
  104. // aiySocket.send("hello");
  105. };
  106. aiySocket.onmessage = function (event) {
  107. console.log(event.data);
  108. dataReceived = event.data;
  109. }
  110. function functionSSH() {
  111. aiySocket.send("ls");
  112. aiySocket.send("scp ~/Downloads/python-blockly.py pi@" + document.getElementById("aiyip_input").value + ":/home/pi/python-blockly.py");
  113. aiySocket.send("ssh -t pi@" + document.getElementById("aiyip_input").value + " 'python3 /home/pi/python-blockly.py'");
  114. }
  115. function functionSSHStop() {
  116. aiySocket.send("ssh -t pi@" + document.getElementById("aiyip_input").value + " 'pkill -f python-blockly.py'");
  117. }
  118. */