LED.js 2.4 KB

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