convert speed to kmh and display it in browser

This commit is contained in:
unknown 2020-12-25 22:19:37 +01:00
parent a64aa0db7c
commit fffda650bb
3 changed files with 9 additions and 7 deletions

View File

@ -51,12 +51,13 @@ var mySpeedometer = new Chart(ctx1, options1);
function addSpeedData(/*speedTCP,*/ speedSERIAL){ function addSpeedData(/*speedTCP,*/ speedSERIAL){
//var speedTCPpercent = (speedTCP/250)*100; //var speedTCPpercent = (speedTCP/250)*100;
var serialSpeedKmh = (speedSERIAL * 0.0036) var serialSpeedKmh = (speedSERIAL * 3.6)
var speedSERIALpercent = (serialSpeedKmh/250)*100; var speedSERIALpercent = (serialSpeedKmh/250)*100
console.log("speed percent", speedSERIALpercent) console.log("speed ms", speedSERIAL)
console.log("actual speed", speedSERIAL)
console.log("speed kmh", serialSpeedKmh) console.log("speed kmh", serialSpeedKmh)
console.log("speed percent", speedSERIALpercent)
//mySpeedometer.data.datasets[0].data = [speedTCPpercent, 100-speedTCPpercent]; //mySpeedometer.data.datasets[0].data = [speedTCPpercent, 100-speedTCPpercent];
mySpeedometer.data.datasets[1].data = [speedSERIALpercent, 100-speedSERIALpercent]; mySpeedometer.data.datasets[1].data = [speedSERIALpercent, 100-speedSERIALpercent];
document.getElementById("speedSERIAL").innerHTML = "Speed Smartphone (km/h): " + serialSpeedKmh.toFixed(3)
mySpeedometer.update(); mySpeedometer.update();
} }

View File

@ -79,7 +79,7 @@ window.addEventListener("load", function(evt) {
} }
} }
if(checkBoxUblox.checked && !checkBoxSmartphone.checked){ if(checkBoxUblox.checked && !checkBoxSmartphone.checked){
if(!(dat.SOURCE_SERIAL.Orientation[0] === 0) && !(dat.SOURCE_SERIAL.Orientation[1] === 0) && !(dat.SOURCE_SERIAL.Orientation[2] === 0)){ if(!(dat.SOURCE_SERIAL.Orientation[0] === 0) && /*!(dat.SOURCE_SERIAL.Orientation[1] === 0) &&*/ !(dat.SOURCE_SERIAL.Orientation[2] === 0)){
document.getElementById("gyroscopeSERIAL").style.transform = `rotateX(${dat.SOURCE_SERIAL.Orientation[0]}deg) rotateY(${dat.SOURCE_SERIAL.Orientation[1]}deg) rotateZ(${dat.SOURCE_SERIAL.Orientation[2]}deg)` document.getElementById("gyroscopeSERIAL").style.transform = `rotateX(${dat.SOURCE_SERIAL.Orientation[0]}deg) rotateY(${dat.SOURCE_SERIAL.Orientation[1]}deg) rotateZ(${dat.SOURCE_SERIAL.Orientation[2]}deg)`
} }
if(!(dat.SOURCE_SERIAL.Position[1] === 0) && !(dat.SOURCE_SERIAL.Position[0] === 0)){ if(!(dat.SOURCE_SERIAL.Position[1] === 0) && !(dat.SOURCE_SERIAL.Position[0] === 0)){
@ -162,6 +162,7 @@ window.addEventListener("load", function(evt) {
.then(console.log); .then(console.log);
checkBoxSmartphone.disabled = false; checkBoxSmartphone.disabled = false;
checkBoxUblox.disabled = false; checkBoxUblox.disabled = false;
ws.close();
} }
return false; return false;
}; };

View File

@ -169,8 +169,8 @@
</div> </div>
<div class="float-child"> <div class="float-child">
<div class="outer"> <div class="outer">
<label id="speedTCP" style="color: firebrick; font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">Speed Smartphone: </label><br> <label id="speedTCP" style="color: firebrick; font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">Speed Smartphone (km/h): </label><br>
<label id="speedSERIAL" style="color: forestgreen; font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">Speed Ublox: </label><br> <label id="speedSERIAL" style="color: forestgreen; font: 15px 'Helvetica Neue', Arial, Helvetica, sans-serif">Speed Ublox (km/h): </label><br>
<canvas id="speedometer" width="300" height="200"></canvas> <canvas id="speedometer" width="300" height="200"></canvas>
<p class="speedMin">0</p> <p class="speedMin">0</p>
<p class="speedMax">250</p> <p class="speedMax">250</p>