-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.htm
141 lines (118 loc) · 6.03 KB
/
ui.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Robot</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="ui.css">
</head>
<body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
<div class="overlay" id="loading">
<div class="overlay__inner">
<div class="overlay__content">
<span class="lead text-muted align-self-baseline">
<div class="d-flex align-items-center">
<span class="spinner-border ms-auto" role="status" aria-hidden="true"></span>
<strong>connecting...</strong>
</div>
</span>
</div>
</div>
</div>
<ul class="nav nav-pills mb-4 sticky-top" id="pills-tab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="pills-home-tab"
data-bs-toggle="pill" data-bs-target="#pills-control"
type="button" role="tab" aria-controls="pills-control" aria-selected="true">
<i class="bi bi-joystick"></i> Control</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="pills-contact-tab"
data-bs-toggle="pill" data-bs-target="#pills-messages"
type="button" role="tab" aria-controls="pills-messages" aria-selected="false">
<i class="bi bi-info-circle-fill"></i> Messages</button>
</li>
</ul>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade show active" id="pills-control" role="tabpanel" aria-labelledby="pills-control-tab">
<div class="btn-group" role="group" aria-label="Command buttons">
<button type="button" class="btn btn-success" onclick="mySocket.send('CMD_RUN');"><i class="bi bi-play-circle"></i> Run</button>
<button type="button" class="btn btn-primary" onclick="mySocket.send('CMD_STEP');"><i class="bi bi-fast-forward-circle"></i> Step</button>
<button type="button" class="btn btn-warning" onclick="mySocket.send('CMD_PAUSE');"><i class="bi bi-pause-circle"></i> Pause</button>
<button type="button" class="btn btn-danger" onclick="mySocket.send('CMD_STOP');" ><i class="bi bi-stop-circle"></i></i> Stop</button>
</div>
<span id="state">State is UNKNOWN</span>
<HR>
<P>G Code
(<span id="active_line"><span class="placeholder col-1"></span></span> of
<span id="lines_count"><span class="placeholder col-1"></span></span>):</P>
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-animated"
role="progressbar" aria-label="Execution" id="progress"
aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
</div>
<div class="font-monospace">
<samp id="gcode">
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-6"></span>
<span class="placeholder col-8"></span>
</p>
</samp>
</div>
</div>
<div class="tab-pane fade" id="pills-messages" role="tabpanel" aria-labelledby="pills-messages-tab">
<p class="card-text placeholder-glow">
<span class="placeholder col-7"></span>
<span class="placeholder col-4"></span>
<span class="placeholder col-6"></span>
<span class="placeholder col-8"></span>
</p>
</div>
</div>
</body>
<script>
var mySocket;
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const socketMessageListener = (event) => {
var data = JSON.parse(event.data);
$('#gcode').empty();
$('#active_line').text(data.active_line);
$('#lines_count').text(data.lines_count);
$('#state').text(data.state);
$('#progress').width(data.progress + "%").attr('aria-valuenow', data.progress);
var ix = 0;
for (lne in data.code) {
ix++;
$('#gcode').append("<div class='float' id='gcode_line" + ix + "'> " + data.code[lne] + " </div>");
}
$('#gcode_line' + data.active_line).addClass("text-bg-primary");
};
// Open
const socketOpenListener = (event) => {
$('#loading').addClass('visually-hidden');
};
// Closed
const socketCloseListener = (event) => {
if (mySocket) {
$('#loading').removeClass('visually-hidden');
sleep(100);
} else {
sleep(500);
}
mySocket = new WebSocket('ws://localhost:8000');
mySocket.addEventListener('open', socketOpenListener);
mySocket.addEventListener('message', socketMessageListener);
mySocket.addEventListener('close', socketCloseListener);
};
socketCloseListener();
</script>
</html>