adds map to the index file
This commit is contained in:
parent
6b5a98a2a8
commit
580ac21ca0
@ -3,89 +3,14 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.bundle.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.bundle.js"></script>
|
||||||
<script>
|
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
|
||||||
const GRAPH_RES = 100;
|
<script src="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.js"></script>
|
||||||
var dataSmartphone = [];
|
<link href="https://api.mapbox.com/mapbox-gl-js/v1.12.0/mapbox-gl.css" rel="stylesheet" />
|
||||||
window.addEventListener("load", function(evt) {
|
<style>
|
||||||
var orientation = [0,0,0];
|
body { margin: 0; padding: 0; }
|
||||||
var multiplier = 180/Math.PI/15
|
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
|
||||||
var output = document.getElementById("output");
|
</style>
|
||||||
var input = document.getElementById("input");
|
<script src="static/scripts/websocket.js"></script>
|
||||||
var ws;
|
|
||||||
var print = function(message) {
|
|
||||||
var d = document.createElement("div");
|
|
||||||
d.textContent = message;
|
|
||||||
output.appendChild(d);
|
|
||||||
};
|
|
||||||
var print2 = function(message) {
|
|
||||||
var d = document.createElement("p");
|
|
||||||
d.innerText = message;
|
|
||||||
oldNode = output.firstChild
|
|
||||||
output.replaceChild(d, oldNode)
|
|
||||||
};
|
|
||||||
document.getElementById("open").onclick = function(evt) {
|
|
||||||
if (ws && ws.OPEN) {
|
|
||||||
print("Websocket already open")
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ws = new WebSocket("{{.}}");
|
|
||||||
ws.onopen = function(evt) {
|
|
||||||
print("OPEN");
|
|
||||||
}
|
|
||||||
ws.onclose = function(evt) {
|
|
||||||
ws = null;
|
|
||||||
print2("CLOSE");
|
|
||||||
}
|
|
||||||
ws.onmessage = function(evt) {
|
|
||||||
//print2("RESPONSE: " + evt.data);
|
|
||||||
dataSmartphone.push(evt.data)
|
|
||||||
// let dat = JSON.parse(evt.data)["bmi26x gyroscope"]
|
|
||||||
// let dat = JSON.parse(evt.data)["lsm6dsm gyroscope"]
|
|
||||||
//let dat = JSON.parse(evt.data)["lsm6ds3c gyroscope"]
|
|
||||||
let dat = JSON.parse(evt.data)
|
|
||||||
//console.log(dat)
|
|
||||||
//console.log(dat.orientation)
|
|
||||||
document.getElementById("gyroscope").style.transform = `rotateX(${-((dat.orientation[1]+90)%360)}deg) rotateY(${dat.orientation[0]}deg) rotateZ(${-dat.orientation[2]}deg)`
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
console.log(dat)
|
|
||||||
orientation[0] += dat[0] * multiplier
|
|
||||||
orientation[1] += dat[1] * multiplier
|
|
||||||
orientation[2] += dat[2] * multiplier
|
|
||||||
// dataset.push(orientation[0])
|
|
||||||
// while (dataset.length >= 50) {
|
|
||||||
// dataset.shift();
|
|
||||||
// }
|
|
||||||
// addData(orientation[0] / multiplier)
|
|
||||||
*/
|
|
||||||
addData(dat.orientation[0])
|
|
||||||
// addData(dat[0])
|
|
||||||
//document.getElementById("gyroscope").style.transform = `rotateX(${-orientation[0]}deg) rotateY(${orientation[1]}deg) rotateZ(${-orientation[2]}deg) translateZ(50px)`
|
|
||||||
}
|
|
||||||
ws.onerror = function(evt) {
|
|
||||||
print("ERROR: " + evt.data);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
document.getElementById("send").onclick = function(evt) {
|
|
||||||
if (!ws) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
print("SEND: " + input.value);
|
|
||||||
ws.send(input.value);
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
document.getElementById("close").onclick = function(evt) {
|
|
||||||
if (!ws) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ws.close();
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<style>
|
<style>
|
||||||
* { box-sizing: border-box; }
|
* { box-sizing: border-box; }
|
||||||
|
|
||||||
@ -162,6 +87,12 @@
|
|||||||
<button id="send">Send</button>
|
<button id="send">Send</button>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
<div class="scene" style='width: 600px; height: 400px;'>
|
||||||
|
<div id="map" style='width: 600px; height: 400px;'></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
|
||||||
|
<script src="static/scripts/map.js"></script>
|
||||||
<div class="scene">
|
<div class="scene">
|
||||||
<div id="gyroscope" class="cube">
|
<div id="gyroscope" class="cube">
|
||||||
<div class="cube__face cube__face--front">front</div>
|
<div class="cube__face cube__face--front">front</div>
|
||||||
@ -175,51 +106,8 @@
|
|||||||
<div style="width: 600px; height: 400px;">
|
<div style="width: 600px; height: 400px;">
|
||||||
<canvas id="myChart" width="400" height="200"></canvas>
|
<canvas id="myChart" width="400" height="200"></canvas>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script src="static/scripts/chart.js"></script>
|
||||||
var ctx = document.getElementById('myChart').getContext('2d');
|
|
||||||
var myChart = new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: {
|
|
||||||
labels: new Array(GRAPH_RES),
|
|
||||||
datasets: [{
|
|
||||||
label: 'Z',
|
|
||||||
backgroundColor: 'rgba(255, 99, 132, 0.2)',
|
|
||||||
borderColor: 'rgba(255, 99, 132, 1)',
|
|
||||||
borderWidth: 1,
|
|
||||||
pointRadius: 0,
|
|
||||||
lineTension: 0.5,
|
|
||||||
data: new Array(GRAPH_RES)
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
scales: {
|
|
||||||
yAxes: [{
|
|
||||||
ticks: {
|
|
||||||
// beginAtZero: true
|
|
||||||
min: -100,
|
|
||||||
max: 100
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
},
|
|
||||||
animation: {
|
|
||||||
duration: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
myChart.data.labels.fill("", 0, GRAPH_RES);
|
|
||||||
myChart.data.datasets.forEach((dataset) => dataset.data.fill(0, 0, GRAPH_RES))
|
|
||||||
function addData(data) {
|
|
||||||
myChart.data.labels.push("");
|
|
||||||
myChart.data.datasets.forEach((dataset) => {
|
|
||||||
dataset.data.push(data);
|
|
||||||
});
|
|
||||||
while (myChart.data.labels.length >= GRAPH_RES) {
|
|
||||||
myChart.data.labels.shift();
|
|
||||||
myChart.data.datasets.forEach((dataset) => dataset.data.shift())
|
|
||||||
}
|
|
||||||
myChart.update();
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
</td>
|
</td>
|
||||||
<td valign="top" width="50%">
|
<td valign="top" width="50%">
|
||||||
<div id="output"></div>
|
<div id="output"></div>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user