-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebctl.html
More file actions
260 lines (225 loc) · 6.32 KB
/
webctl.html
File metadata and controls
260 lines (225 loc) · 6.32 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Feu control room</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
}
/* Style the header */
header {
background-color: #444;
padding: 1px;
text-align: center;
font-size: 20px;
color: #d55;
}
/* Container for flexboxes */
section {
display: -webkit-flex;
display: flex;
}
/* Style the navigation menu */
nav {
-webkit-flex: 1;
-ms-flex: 1;
flex: 3;
background: #ccc;
padding: 5px;
}
/* Style the list inside the menu */
nav ul {
list-style-type: none;
padding: 0;
}
/* Style the content */
article {
-webkit-flex: 3;
-ms-flex: 3;
flex: 1;
background-color: #f1f1f1;
padding: 10px;
}
/* Style the footer */
footer {
background-color: #777;
padding: 10px;
text-align: center;
color: white;
}
/* Responsive layout - makes the menu and the content (inside the section) sit on top of each other instead of next to each other */
@media (max-width: 600px) {
section {
-webkit-flex-direction: column;
flex-direction: column;
}
}
.button {
padding: 10px;
font-size: 16px;
}
.switch {
position: relative;
width: 34px;
height: 34px;
}
.slider {
width: 50%;
height: 20px;
}
.ctldiv {
padding: 5px;
}
label{
vertical-align:50%;
font-size: 16px;
font-weight: normal;
}
</style>
</head>
<body>
<header>
<h2>Feu control room</h2>
</header>
<section>
<nav>
<ul>
<h1>Controls</h1>
<div class="ctldiv">
<input type="range" class="slider" id="volume" min="0" max="255"/>
<label>Master volume: <output id="volume_value">0</output></label>
</div>
<br>
<div class="ctldiv">
<input type="range" class="slider" id="soufflevolume" min="0" max="255"/>
<label>Souffle volume: <output id="soufflevolume_value">0</output></label>
</div>
<div class="ctldiv">
<input type="range" class="slider" id="gresillvolume" min="0" max="255"/>
<label>Gresille volume: <output id="gresillvolume_value">0</output></label>
</div>
<div class="ctldiv">
<input type="range" class="slider" id="crepitvolume" min="0" max="255"/>
<label>Crepite volume: <output id="crepitvolume_value">0</output></label>
</div>
<br>
<div class="ctldiv">
<input type="range" class="slider" id="intens" min="0" max="255"/>
<label>Intensité feu: <output id="intens_value">0</output></label>
</div>
<div class="ctldiv">
<input type="range" class="slider" id="crepit" min="0" max="255"/>
<label>Crépitements: <output id="crepit_value">0</output></label>
</div>
<div class="ctldiv">
<input type="range" class="slider" id="rouge" min="0" max="64"/>
<label>Taux de rouge: <output id="rouge_value">0</output></label>
</div>
</ul>
</nav>
<article>
<h1>Log</h1>
<textarea id='chatbox' rows=12 cols=40 readonly> </textarea>
</article>
</section>
<footer>
<p> metalu.net 2025</p>
</footer>
<script type="text/javascript">
function log(text) {
const logbox = document.getElementById("chatbox");
logbox.value += text + '\n';
logbox.scrollTo( 0, 999999 );
}
function update_label(control, val) {
document.getElementById(control + "_value").textContent = val;
}
function get_fraise_chars(words) {
const id = parseInt(words.shift());
if(id != 1) return;
let command = words.shift();
if(command !== "R") return;
let control = words.shift();
let val = parseInt(words.shift());
document.getElementById(control).value = val;
update_label(control, val);
}
function get_fraise_bytes(words) {
}
const controls = ["volume", "soufflevolume", "gresillvolume", "crepitvolume", "intens", "crepit", "rouge"];
class WebSocketHandler {
periodic(event) {
if(this.count > 5)
this.ws.send("hello from websocket");
this.count++;
}
get_current_state() {
controls.forEach(el => this.ws.send("F 1 Rget " + el));
}
constructor() {
this.count = 0;
if (window.location.protocol == "https:") {
this.ws = new WebSocket("wss://" + location.hostname + ":443/websocket");
}
else if (window.location.protocol == "http:") {
this.ws = new WebSocket("ws://" + location.hostname + ":80/websocket");
}
else if (window.location.protocol == "file:") {
this.ws = new WebSocket("ws://127.0.0.1:80/websocket");
}
this.ws.onerror = (event) => {
console.log("WebSocket error: ", event);
};
this.ws.onopen = (event) => {
this.ws.send("P 1 1"); // poll fruit ID 1
this.get_current_state();
};
this.ws.onmessage = (event) => {
event.data.text().then(text => {
//console.log("Message from server " + text);
//log("Message: " + text);
const words = text.split(" ");
const command = words.shift();
switch(command) {
case "F": get_fraise_chars(words); break;
case "f": get_fraise_bytes(words); break;
case "D": this.get_current_state(); break; // fruit is detected, get its state
}
});
};
}
}
let handler = new WebSocketHandler();
function int32_to_bytes(i) {
return [i >> 24, (i >> 16) % 255, (i >> 8) % 255, i % 255].join(" ");
}
function format_control(control, update_label_func) {
let c = document.getElementById(control);
c.addEventListener("input", (event) => {
update_label_func(control, event.target.value)
handler.ws.send(`F 1 Rset ${control} ${event.target.value}`);
});
}
function send_setting_string(num, value) {
let outstr = "f 1 50 " + num;
for(i = 0; i < value.length; i++) outstr += " " + value.charCodeAt(i);
handler.ws.send(outstr);
}
controls.forEach(el => format_control(el, update_label));
/*format_control("volume", update_label);
format_control("intens", update_label);
format_control("crepit", update_label);
format_control("rouge", update_label);*/
/*document.getElementById("save_eeprom").onclick = function() {
send_setting_string(255, "EEPROM_SAVE");
}*/
chatbox.value='';
log("Feu control room loaded!");
</script>
</body>
</html>