LED.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. let lastPushId = ""
  2. let arduionoURL
  3. let openSlide = "animationsContainer"
  4. let data
  5. let var_1 = 0
  6. let speed = 100
  7. readTextFile("./res/settings.json", function(text){
  8. data = JSON.parse(text);
  9. arduionoURL = data.settings.ip
  10. console.log(data)
  11. });
  12. function buttonPushAnimation(id) {
  13. if (id !== lastPushId) {
  14. document.getElementById(id).style.backgroundColor = "#2c2c36"
  15. if (lastPushId !== "") {
  16. document.getElementById(lastPushId).style.backgroundColor = "#252531"
  17. }
  18. lastPushId = id
  19. speed = data.animations[id].speed
  20. var_1 = data.animations[id].var_1
  21. document.getElementById("speed").value = speed
  22. document.getElementById("var_1").value = var_1
  23. httpGetAsync(arduionoURL + "/" + id)
  24. }
  25. }
  26. function topBarClick(id) {
  27. if (id !== openSlide) {
  28. document.getElementById(id).classList.toggle("hide")
  29. document.getElementById(openSlide).classList.toggle("hide")
  30. openSlide = id
  31. }
  32. }
  33. function setSpeed(value) {
  34. if (value !== speed) {
  35. speed = value
  36. document.getElementById("speed").value = value
  37. try {
  38. httpGetAsync(arduionoURL + "/y1:" + value + ":;")
  39. } catch (e) {
  40. }
  41. }
  42. }
  43. function setVar_1(value) {
  44. if (value !== var_1) {
  45. var_1 = value
  46. document.getElementById("var_1").value = value
  47. try {
  48. httpGetAsync(arduionoURL + "/y2:" + value + ":;")
  49. } catch (e) {
  50. }
  51. }
  52. }
  53. function setSettings() {
  54. var nSpeed = document.getElementById("speed").value
  55. var nVar_1 = document.getElementById("var_1").value
  56. setSpeed(nSpeed)
  57. setVar_1(nVar_1)
  58. }
  59. function httpGetAsync(theUrl, callback) {
  60. try {
  61. var xmlHttp = new XMLHttpRequest();
  62. xmlHttp.onreadystatechange = function () {
  63. if (xmlHttp.readyState === 4 && xmlHttp.status === 200)
  64. callback(xmlHttp.responseText);
  65. }
  66. xmlHttp.open("GET", theUrl, true); // true for asynchronous
  67. xmlHttp.send(null);
  68. } catch (e) {
  69. console.log(e)
  70. }
  71. }
  72. function readTextFile(file, callback) {
  73. var rawFile = new XMLHttpRequest();
  74. rawFile.overrideMimeType("application/json");
  75. rawFile.open("GET", file, true);
  76. rawFile.onreadystatechange = function() {
  77. if (rawFile.readyState === 4 && rawFile.status === "200") {
  78. callback(rawFile.responseText);
  79. }
  80. }
  81. rawFile.send(null);
  82. }