3 var batteryVoltageStream;
6 var engineCoolantStream;
8 var intakeAirTempStream;
18 function calcAverageMpg(newMpg) {
19 prevMpg += parseInt(newMpg);
22 var averageMpg = prevMpg / mpgReadings;
23 $("#avgmpg").text(Math.floor(averageMpg));
30 function calcAverageVelocity(newVel) {
31 prevVel += parseInt(newVel);
34 var averageVel = prevVel / velReadings;
35 $("#avgspeed").text(Math.floor(averageVel));
40 vehicle.subscribe(["running_status_speedometer", "running_status_engine_speed", "running_status_transmission_gear_status", "running_status_steering_wheel_angle"]);
41 vehicle.subscribe(["running_status_engine_speed"]);
42 vehicle.subscribe(["running_status_transmission_gear_status"]);
43 vehicle.subscribe(["running_status_steering_wheel_angle"]);
44 vehicle.subscribe(["ThrottlePosition"]);
45 vehicle.subscribe(["EngineCoolantTemperature"]);
46 vehicle.subscribe(["MachineGunTurretStatus"]);
48 document.addEventListener("running_status_speedometer",function(data) {
50 adjvalue = data.value;
51 var velocityUnits = $('#velocityUnits');
53 if(velocityUnits.text() === "MPH")
54 adjvalue = Math.floor(data.value * 0.62137);
56 $('#velocity').text(adjvalue);
58 calcAverageVelocity(adjvalue);
61 document.addEventListener("running_status_engine_speed", function(data) {
62 var value = data.value;
63 if(value > 10000) value =10000;
64 var needleDegs = value / 10000 * 180;
65 $('#rpms').text(value);
66 $('#rpmNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
69 document.addEventListener("running_status_transmission_gear_status",function(data) {
71 $('#gear').text(value);
74 document.addEventListener("running_status_steering_wheel_angle", function(data) {
76 $('#wheel').css("-webkit-transform","rotate("+value+"deg)");
79 document.addEventListener("ThrottlePosition", function(data) {
81 var needleDegs = (value / 100 * 180) + 270
83 $('#throttleNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
87 document.addEventListener("EngineCoolantTemperature", function(data) {
89 var needleDegs = (value / 180 * 70) + 270
91 $('#engineCoolantNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
95 document.addEventListener("MachineGunTurretStatus", function(data) {
98 $('#machineGunTurretPopup').popup('open');
106 function connect(addy)
108 vehicle = new Vehicle(connected, function(){$('#velocity').text("ERR");}, "ws://"+addy, "http-only");
111 window.onload = function()
113 var addy = "localhost:23000";
115 if(typeof(Storage)!== "undefined")
117 addyTemp = localStorage.address;
118 if(addyTemp !== undefined) addy = addyTemp;
121 $("#address").val(addy);
122 $("#address").change(function() { localStorage.address = $("#address").val(); });
123 $("#connectButton").click(function() { connect(addy) });
129 var velocityUnits = $('#velocityUnits');
130 velocityUnits.click(function() {
131 if(velocityUnits.text() === "MPH")
133 velocityUnits.text("KPH");
135 else velocityUnits.text("MPH");