From 6b5a98a2a8fff998c06df49209012aadc5835153 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 8 Dec 2020 13:30:12 +0100 Subject: [PATCH] get static folder from frank-dev --- static/scripts/chart.js | 43 ++ static/scripts/hike.geo.json | 737 +++++++++++++++++++++++++++++++++++ static/scripts/map.js | 57 +++ static/scripts/websocket.js | 82 ++++ 4 files changed, 919 insertions(+) create mode 100644 static/scripts/chart.js create mode 100644 static/scripts/hike.geo.json create mode 100644 static/scripts/map.js create mode 100644 static/scripts/websocket.js diff --git a/static/scripts/chart.js b/static/scripts/chart.js new file mode 100644 index 0000000..f9220bb --- /dev/null +++ b/static/scripts/chart.js @@ -0,0 +1,43 @@ +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(); +}; \ No newline at end of file diff --git a/static/scripts/hike.geo.json b/static/scripts/hike.geo.json new file mode 100644 index 0000000..fb2388e --- /dev/null +++ b/static/scripts/hike.geo.json @@ -0,0 +1,737 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "LineString", + "coordinates": [ + [ + 9.196275472640991, + 49.12280972701122 + ], + [ + 9.19629693031311, + 49.122757066649065 + ], + [ + 9.196267426013947, + 49.1227219597099 + ], + [ + 9.196237921714783, + 49.12268685274588 + ], + [ + 9.196205735206604, + 49.122642969005895 + ], + [ + 9.196168184280396, + 49.12259908522708 + ], + [ + 9.196090400218964, + 49.122556956762885 + ], + [ + 9.196015298366547, + 49.12252536039125 + ], + [ + 9.195816814899445, + 49.122421794365344 + ], + [ + 9.19578731060028, + 49.12246041223081 + ], + [ + 9.195752441883085, + 49.122495519355134 + ], + [ + 9.195720255374908, + 49.1225306264546 + ], + [ + 9.195685386657715, + 49.12257099958827 + ], + [ + 9.195658564567566, + 49.122602595930815 + ], + [ + 9.195634424686432, + 49.12263419225324 + ], + [ + 9.195604920387268, + 49.12266052250654 + ], + [ + 9.19557273387909, + 49.12268334204809 + ], + [ + 9.195548593997955, + 49.12271318297122 + ], + [ + 9.195532500743866, + 49.12273951318259 + ], + [ + 9.195497632026672, + 49.12276057734161 + ], + [ + 9.19557273387909, + 49.12281850373281 + ], + [ + 9.195524454116821, + 49.12285712128936 + ], + [ + 9.195497632026672, + 49.12287818539843 + ], + [ + 9.195476174354553, + 49.122904515522194 + ], + [ + 9.195586144924162, + 49.12300983587742 + ], + [ + 9.195840954780579, + 49.1232152099268 + ], + [ + 9.19605016708374, + 49.1233942532759 + ], + [ + 9.196152091026306, + 49.1235346789797 + ], + [ + 9.196280837059021, + 49.12368212554077 + ], + [ + 9.196393489837646, + 49.12382606104651 + ], + [ + 9.196511507034302, + 49.123924358225025 + ], + [ + 9.196581244468689, + 49.12404371882266 + ], + [ + 9.196720719337463, + 49.124173610911306 + ], + [ + 9.196838736534119, + 49.12435967195905 + ], + [ + 9.196951389312744, + 49.124501850213676 + ], + [ + 9.197013080120087, + 49.1245896143649 + ], + [ + 9.19705867767334, + 49.12465280445759 + ], + [ + 9.19714719057083, + 49.12476865275172 + ], + [ + 9.197292029857635, + 49.12495120102961 + ], + [ + 9.197361767292023, + 49.12506529336202 + ], + [ + 9.197455644607544, + 49.125175874910624 + ], + [ + 9.197522699832916, + 49.12529347723932 + ], + [ + 9.197605848312378, + 49.12543565281655 + ], + [ + 9.197745323181152, + 49.125690163634275 + ], + [ + 9.197841882705688, + 49.12584989044582 + ], + [ + 9.19790893793106, + 49.12598328826778 + ], + [ + 9.197978675365448, + 49.12612195141281 + ], + [ + 9.198064506053925, + 49.12627290072483 + ], + [ + 9.19819325208664, + 49.126525652032335 + ], + [ + 9.198254942893982, + 49.12668011053043 + ], + [ + 9.198305904865265, + 49.12679770929164 + ], + [ + 9.198405146598816, + 49.12695743253551 + ], + [ + 9.198488295078278, + 49.12716981099699 + ], + [ + 9.198619723320007, + 49.12720315959838 + ], + [ + 9.198799431324005, + 49.127229487425765 + ], + [ + 9.199027419090271, + 49.12716630061657 + ], + [ + 9.19931173324585, + 49.127129441607394 + ], + [ + 9.199504852294922, + 49.12708556179883 + ], + [ + 9.19965773820877, + 49.12704870272959 + ], + [ + 9.199883043766022, + 49.12700482284956 + ], + [ + 9.200116395950317, + 49.1269732293119 + ], + [ + 9.200357794761658, + 49.12690653177737 + ], + [ + 9.200548231601715, + 49.12688546937944 + ], + [ + 9.20065551996231, + 49.126911797375485 + ], + [ + 9.200770854949951, + 49.12695743253551 + ], + [ + 9.200899600982666, + 49.12702061961085 + ], + [ + 9.20103371143341, + 49.12706800986451 + ], + [ + 9.201240241527557, + 49.12711891045688 + ], + [ + 9.20141190290451, + 49.12714874871086 + ], + [ + 9.2015540599823, + 49.127191750868846 + ], + [ + 9.201587587594986, + 49.127187362895256 + ], + [ + 9.201736450195312, + 49.1271601574503 + ], + [ + 9.201810210943222, + 49.127157524664504 + ], + [ + 9.201871901750565, + 49.12715313668789 + ], + [ + 9.201933592557907, + 49.12710925690026 + ], + [ + 9.202055633068085, + 49.12697498450896 + ], + [ + 9.20224204659462, + 49.12691530777389 + ], + [ + 9.20237347483635, + 49.126887224579605 + ], + [ + 9.202480763196945, + 49.126842466955814 + ], + [ + 9.20254647731781, + 49.12681613892294 + ], + [ + 9.202671200037003, + 49.126769626030736 + ], + [ + 9.202869683504105, + 49.126692396981234 + ], + [ + 9.202970266342163, + 49.12665729282806 + ], + [ + 9.203054755926132, + 49.12662218865002 + ], + [ + 9.203156679868698, + 49.12659147247387 + ], + [ + 9.203227758407593, + 49.126569532336404 + ], + [ + 9.203289449214935, + 49.126551980219446 + ], + [ + 9.203341752290726, + 49.12653179527724 + ], + [ + 9.203158020973206, + 49.126483526903876 + ], + [ + 9.203088283538818, + 49.12646334193381 + ], + [ + 9.203002452850342, + 49.12644140173965 + ], + [ + 9.202857613563538, + 49.12640278697433 + ], + [ + 9.202712774276733, + 49.126357151303814 + ], + [ + 9.202632308006287, + 49.126325557353475 + ], + [ + 9.202412366867065, + 49.12626236939239 + ], + [ + 9.202256798744202, + 49.126213223144774 + ], + [ + 9.202122688293455, + 49.12616758729978 + ], + [ + 9.201961755752563, + 49.12612546186714 + ], + [ + 9.2018061876297, + 49.12607982594142 + ], + [ + 9.201698899269104, + 49.126037700434225 + ], + [ + 9.201596975326538, + 49.125999085354515 + ], + [ + 9.20129120349884, + 49.125883239934964 + ], + [ + 9.201119542121887, + 49.125827072361396 + ], + [ + 9.200921058654785, + 49.12578143616102 + ], + [ + 9.200685024261473, + 49.125676121692166 + ], + [ + 9.200513362884521, + 49.12560591192202 + ], + [ + 9.200336337089539, + 49.12554623353922 + ], + [ + 9.199842810630798, + 49.125360176943595 + ], + [ + 9.199681878089905, + 49.12527592467067 + ], + [ + 9.1995370388031, + 49.12522677744532 + ], + [ + 9.199456572532654, + 49.12518816173411 + ], + [ + 9.19932246208191, + 49.12513199337321 + ], + [ + 9.199220538139343, + 49.12508635653314 + ], + [ + 9.199113249778748, + 49.125023166992925 + ], + [ + 9.199016690254211, + 49.12496699844514 + ], + [ + 9.198925495147705, + 49.1248932771296 + ], + [ + 9.198732376098633, + 49.12480551351584 + ], + [ + 9.198582172393799, + 49.124721260300475 + ], + [ + 9.198474884033203, + 49.124647538619605 + ], + [ + 9.198367595672607, + 49.12459839077146 + ], + [ + 9.198265671730042, + 49.12455626400573 + ], + [ + 9.198126196861267, + 49.124542221742516 + ], + [ + 9.198099374771118, + 49.12450360549822 + ], + [ + 9.198126196861267, + 49.12441584119478 + ], + [ + 9.198174476623533, + 49.12433509789843 + ], + [ + 9.19828176498413, + 49.12430701324279 + ], + [ + 9.19831931591034, + 49.12427190740087 + ], + [ + 9.198254942893982, + 49.12420871682283 + ], + [ + 9.198115468025208, + 49.124149036758475 + ], + [ + 9.197981357574463, + 49.124085846023824 + ], + [ + 9.197836518287659, + 49.124026165811614 + ], + [ + 9.197707772254944, + 49.12395595370529 + ], + [ + 9.197557568550108, + 49.12386467781845 + ], + [ + 9.197487831115723, + 49.12381201857656 + ], + [ + 9.197385907173157, + 49.123717231800214 + ], + [ + 9.197214245796204, + 49.12367510428589 + ], + [ + 9.197010397911072, + 49.123566274708274 + ], + [ + 9.196908473968506, + 49.123474998104186 + ], + [ + 9.196704626083374, + 49.123401274570526 + ], + [ + 9.196602702140808, + 49.123348614836544 + ], + [ + 9.196484684944153, + 49.123260848488954 + ], + [ + 9.196339845657349, + 49.12319414596088 + ], + [ + 9.196216464042664, + 49.12313095400942 + ], + [ + 9.196135997772217, + 49.12306776197748 + ], + [ + 9.19607162475586, + 49.12299754851418 + ], + [ + 9.195937514305115, + 49.12295893106699 + ], + [ + 9.195835590362549, + 49.12289222813283 + ], + [ + 9.195733666419983, + 49.12282903579667 + ], + [ + 9.195638447999954, + 49.122754433629495 + ], + [ + 9.195600226521492, + 49.12273293063105 + ], + [ + 9.195574074983597, + 49.122708355764296 + ], + [ + 9.195574074983597, + 49.12269431297779 + ], + [ + 9.195623695850372, + 49.1226412136555 + ], + [ + 9.195666611194609, + 49.12260961733753 + ], + [ + 9.195688739418983, + 49.12258021519025 + ], + [ + 9.195733666419983, + 49.12253106529318 + ], + [ + 9.19575646519661, + 49.12250034658276 + ], + [ + 9.195783287286758, + 49.12247269972715 + ], + [ + 9.195801392197609, + 49.12244988008865 + ], + [ + 9.195815473794937, + 49.122438470265486 + ], + [ + 9.195830225944519, + 49.12242047784666 + ], + [ + 9.195859730243683, + 49.122431887674 + ], + [ + 9.195901304483414, + 49.122448563570735 + ], + [ + 9.195931479334831, + 49.12246787249679 + ], + [ + 9.195965006947517, + 49.12248367070343 + ], + [ + 9.195998534560204, + 49.122498152388445 + ], + [ + 9.19603407382965, + 49.12251307290797 + ], + [ + 9.196063578128815, + 49.12253501484029 + ], + [ + 9.196093752980232, + 49.122546424641236 + ], + [ + 9.196127280592918, + 49.1225600286313 + ], + [ + 9.19615812599659, + 49.12258109286655 + ], + [ + 9.196201711893082, + 49.12261927177015 + ], + [ + 9.196238592267036, + 49.12267237111598 + ], + [ + 9.196262061595917, + 49.12270045669739 + ], + [ + 9.196281507611275, + 49.122722837383684 + ], + [ + 9.196305647492409, + 49.122746534569934 + ], + [ + 9.196302965283394, + 49.1227693540719 + ], + [ + 9.196292236447334, + 49.12279392890845 + ], + [ + 9.196286201477049, + 49.122811482355665 + ], + [ + 9.19628955423832, + 49.12282815812477 + ], + [ + 9.196309000253677, + 49.1228479057388 + ] + ] + } + } + ] +} \ No newline at end of file diff --git a/static/scripts/map.js b/static/scripts/map.js new file mode 100644 index 0000000..8ee2a10 --- /dev/null +++ b/static/scripts/map.js @@ -0,0 +1,57 @@ +mapboxgl.accessToken = 'pk.eyJ1IjoiZmhlcmtvbW0iLCJhIjoiY2tobm81bXppMGVuNzMyazY3eDU0M2dyaSJ9.qWJrwtv7KitW60pzs6h3Gg'; +var map = new mapboxgl.Map({ + container: 'map', + style: 'mapbox://styles/mapbox/streets-v11', + zoom: 0 +}); +var empty = { + type: "FeatureCollection", + features: [ + { + type: "Feature", + geometry: { + type: "LineString", + coordinates: [] + } + }] +} + +map.on('load', function () { + // save full coordinate list for later + //var coordinates = data.features[0].geometry.coordinates; + + // start by showing just the first coordinate + //data.features[0].geometry.coordinates = [coordinates[0]]; + + // add it to the map + //map.addSource('trace', { type: 'geojson', data: data }); + + map.addSource('route', { 'type': 'geojson', 'data': empty }) + + map.addLayer({ + 'id': 'route', + 'type': 'line', + 'source': 'route', + 'paint': { + 'line-color': 'yellow', + 'line-opacity': 0.75, + 'line-width': 5 + } + }); + + // setup the viewport + map.jumpTo({ 'center': [9.19640999, 49.12283027], 'zoom': 15 }); + map.setPitch(30); + + // on a regular basis, add more coordinates from the saved list and update the map + //var i = 0; + //var timer = window.setInterval(, 10); + + +}) + +function updateMap (coordinates) { + empty.features[0].geometry.coordinates.push(coordinates); + map.getSource('route').setData(empty); + map.panTo(coordinates); +} \ No newline at end of file diff --git a/static/scripts/websocket.js b/static/scripts/websocket.js new file mode 100644 index 0000000..d8f2bb4 --- /dev/null +++ b/static/scripts/websocket.js @@ -0,0 +1,82 @@ +const GRAPH_RES = 100; +var dataSmartphone = []; +window.addEventListener("load", function(evt) { + var orientation = [0,0,0]; + var multiplier = 180/Math.PI/15 + var output = document.getElementById("output"); + var input = document.getElementById("input"); + 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://localhost:3011/echo"); + 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(evt.data) + console.log("JSON geparsed onmessage", 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]) + setData(dat.GPS[0], dat.GPS[1]) + // 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; + }; +}); \ No newline at end of file