rt-sim-training-client/static/workertest/trafficplan/trafficstation.js

42 lines
633 B
JavaScript
Raw Normal View History

var i=0;
var update = null;
function timedCount(){
onmessage = (e) => {
if(e.data[0] == "on"){
// console.log("on");
2020-11-13 09:36:14 +08:00
update = "1";
}
if(e.data[0] == "off"){
clearInterval(update);
}
// console.log(e.data);
if(e.data[0] == "changespeed"){
if(update){
2020-11-13 09:36:14 +08:00
console.log(e.data[1]);
clearInterval(update);
2020-11-13 09:36:14 +08:00
if(e.data[1] == 0){
}else{
let speed = 900/e.data[1];
console.log(speed);
update = setInterval("stationupdate()", speed);
}
}
}
}
}
function stationupdate(){
postMessage("up");
}
timedCount();