Эх сурвалжийг харах

Add low effort web client

Tankernn 7 жил өмнө
parent
commit
b5d734b2e2

+ 0 - 0
client/css/style.css


+ 18 - 0
client/index.html

@@ -0,0 +1,18 @@
+<!doctype html>
+
+<html lang="en">
+<head>
+  <meta charset="utf-8">
+
+  <title>RC Control</title>
+  <meta name="description" content="RC Car Control">
+  <meta name="author" content="Tankernn">
+
+  <link rel="stylesheet" href="css/style.css">
+</head>
+
+<body>
+  <script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
+  <script src="js/script.js"></script>
+</body>
+</html>

+ 26 - 0
client/js/script.js

@@ -0,0 +1,26 @@
+$(document).ready(function () {
+  var socket = new WebSocket("ws://raspberrypi:54321");
+  var keys = [];
+
+  socket.onopen = function() {
+    var sendInput = function () {
+      socket.send(JSON.stringify(keys));
+
+    };
+    setInterval(sendInput, 69);
+  }
+
+  $(document).keydown(function(e) {
+    if (keys.indexOf(e.keyCode) === -1) {
+      keys.push(e.keyCode);
+    }
+    e.preventDefault();
+  });
+
+  $(document).keyup(function(e) {
+    if (keys.indexOf(e.keyCode) !== -1) {
+      keys.splice(keys.indexOf(e.keyCode), 1);
+    }
+    e.preventDefault();
+  });
+});