car.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. $(document).ready(function() {
  2. $('#forward').click(function() {
  3. $.post("../cgi-bin/car.sh", "forward" );
  4. });
  5. addEventListener("keydown", function (e) {
  6. if (e.key === "w") {
  7. $.post("../cgi-bin/car.sh", "forward" );
  8. }
  9. });
  10. $('#reverse').click(function() {
  11. $.post("../cgi-bin/car.sh", "reverse" );
  12. });
  13. addEventListener("keydown", function (e) {
  14. if (e.key === "s") {
  15. $.post("../cgi-bin/car.sh", "reverse" );
  16. }
  17. });
  18. $('#left').click(function() {
  19. $.post("../cgi-bin/car.sh", "left" );
  20. });
  21. addEventListener("keydown", function (e) {
  22. if (e.key === "a") {
  23. $.post("../cgi-bin/car.sh", "left" );
  24. }
  25. });
  26. $('#right').click(function() {
  27. $.post("../cgi-bin/car.sh", "right" );
  28. });
  29. addEventListener("keydown", function (e) {
  30. if (e.key === "d") {
  31. $.post("../cgi-bin/car.sh", "right" );
  32. }
  33. });
  34. $('#forward_left').click(function() {
  35. $.post("../cgi-bin/car.sh", "forward_left" );
  36. });
  37. addEventListener("keydown", function (e) {
  38. if (e.key === "q") {
  39. $.post("../cgi-bin/car.sh", "forward_left" );
  40. }
  41. });
  42. $('#forward_right').click(function() {
  43. $.post("../cgi-bin/car.sh", "forward_right" );
  44. });
  45. addEventListener("keydown", function (e) {
  46. if (e.key === "e") {
  47. $.post("../cgi-bin/car.sh", "forward_right" );
  48. }
  49. });
  50. $('#reverse_left').click(function() {
  51. $.post("../cgi-bin/car.sh", "reverse_left" );
  52. });
  53. addEventListener("keydown", function (e) {
  54. if (e.key === "z") {
  55. $.post("../cgi-bin/car.sh", "reverse_left" );
  56. }
  57. });
  58. $('#reverse_right').click(function() {
  59. $.post("../cgi-bin/car.sh", "reverse_right" );
  60. });
  61. addEventListener("keydown", function (e) {
  62. if (e.key === "c") {
  63. $.post("../cgi-bin/car.sh", "reverse_right" );
  64. }
  65. });
  66. $('#all_stop').click(function() {
  67. $.post("../cgi-bin/car.sh", "all_stop" );
  68. });
  69. addEventListener("keydown", function (e) {
  70. if (e.key === "x") {
  71. $.post("../cgi-bin/car.sh", "all_stop" );
  72. }
  73. });
  74. $('#headlight').click(function() {
  75. $.post("../cgi-bin/car.sh", "headlight" );
  76. });
  77. addEventListener("keydown", function (e) {
  78. if (e.key === "x") {
  79. $.post("../cgi-bin/car.sh", "headlight" );
  80. }
  81. });
  82. $('#irled').click(function() {
  83. $.post("../cgi-bin/car.sh", "irled" );
  84. });
  85. addEventListener("keydown", function (e) {
  86. if (e.key === "x") {
  87. $.post("../cgi-bin/car.sh", "irled" );
  88. }
  89. });
  90. $('#honk').click(function() {
  91. $.post("../cgi-bin/car.sh", "honk" );
  92. });
  93. addEventListener("keydown", function (e) {
  94. if (e.key === "x") {
  95. $.post("../cgi-bin/car.sh", "honk" );
  96. }
  97. });
  98. });