|
12 | 12 | </div>
|
13 | 13 | </body>
|
14 | 14 |
|
15 |
| -<!------------ START SCRIPT ------------> |
| 15 | +<!-- JavaScript scripts --> |
16 | 16 | <script>
|
| 17 | + /* Electron setups */ |
17 | 18 | const isReachable = require('is-reachable');
|
18 | 19 | let ipc = require("electron").ipcRenderer;
|
19 | 20 |
|
20 | 21 | function init() {
|
| 22 | + // Quit with the x button |
21 | 23 | document.getElementById("close-button").addEventListener("click", function (e) {
|
22 | 24 | console.log("close");
|
23 | 25 | ipc.send("win.close");
|
|
30 | 32 | // }
|
31 | 33 | // };
|
32 | 34 | init();
|
33 |
| - </script> |
34 |
| - <script> |
| 35 | +</script> |
| 36 | + |
| 37 | +<script> |
| 38 | + /* Camera drawing setups */ |
| 39 | + |
| 40 | + /* Change this number to your team number! */ |
| 41 | + const TEAM_NUMBER = "1720"; |
| 42 | + |
| 43 | + // Pad the team number for the IP address |
| 44 | + let team_num = "0".repeat(4-TEAM_NUMBER.length) + TEAM_NUMBER; |
| 45 | + let team_ip = team_num[0] + team_num[1] + "." + team_num[2] + team_num[3]; |
| 46 | + |
| 47 | + // The drawing plane |
35 | 48 | const cameraCanvas = document.getElementById("camera-canvas");
|
36 | 49 | let camCtx = cameraCanvas.getContext('2d');
|
37 | 50 | camCtx.canvas.width = window.innerWidth;
|
38 | 51 | camCtx.canvas.height = window.innerHeight;
|
39 | 52 |
|
| 53 | + // Connection status. Red if not connected, green if connected. |
40 | 54 | const statusIndicator = document.getElementById("status-indicator");
|
41 | 55 | let stCtx = statusIndicator.getContext('2d');
|
42 | 56 | stCtx.canvas.width = 25;
|
|
54 | 68 | height: height / 2.0,
|
55 | 69 | };
|
56 | 70 |
|
57 |
| - let img = new Image(); |
| 71 | + let img = new Image(); // This is where the camera feed goes |
58 | 72 |
|
| 73 | + // Used for resizing and centering the image |
59 | 74 | let scale = 1;
|
60 | 75 | let imageX = 0;
|
61 | 76 | let imageY = 0;
|
62 | 77 |
|
63 | 78 | let source = "";
|
64 | 79 |
|
| 80 | + // Connect to the camera |
65 | 81 | (async () => {
|
66 |
| - let sourceMain = "http://10.17.20.2:1181"; |
67 |
| - let sourceUSB = "http://172.22.11.2:1181"; |
| 82 | + let sourceMain = "http://10." + team_ip + ".2:1181"; // IP is team number dependent |
| 83 | + let sourceUSB = "http://172.22.11.2:1181"; // Always the same |
| 84 | + |
| 85 | + // Wait until first contact |
68 | 86 | while (true) {
|
69 | 87 | if (await isReachable(sourceMain)) {
|
70 | 88 | source = sourceMain + "/?action=stream";
|
|
77 | 95 | }
|
78 | 96 | setup(source);
|
79 | 97 |
|
| 98 | + // Green for go! |
80 | 99 | stCtx.fillStyle = "rgb(0, 255, 0)";
|
81 | 100 | stCtx.fillRect(0, 0, stCtx.canvas.width, stCtx.canvas.height);
|
82 | 101 | })();
|
|
0 commit comments