updated to use new vehicle api
[profile/ivi/GhostCluster.git] / business.js
index f307d54..8ad84e0 100644 (file)
@@ -14,6 +14,7 @@ var vehicle;
 
 var mpgReadings = 0;
 var prevMpg = 0;
+var curVss;
 
 function calcAverageMpg(newMpg) {
        prevMpg += parseInt(newMpg);
@@ -35,110 +36,70 @@ function calcAverageVelocity(newVel) {
        $("#avgspeed").text(Math.floor(averageVel));
 }
 
-function connected()
+window.onload = function()
 {
-    vehicle.subscribe(["running_status_speedometer", "running_status_engine_speed", "running_status_transmission_gear_status", "running_status_steering_wheel_angle"]);
-    //vehicle.subscribe(["running_status_engine_speed"]);
-    //vehicle.subscribe(["running_status_transmission_gear_status"]);
-    //vehicle.subscribe(["running_status_steering_wheel_angle"]);
-    vehicle.subscribe(["ThrottlePosition"]);
-    vehicle.subscribe(["EngineCoolantTemperature"]);
-    vehicle.subscribe(["MachineGunTurretStatus"]);
+    var vehicle = tizen.vehicle
 
-    document.addEventListener("running_status_speedometer",function(data) {
+    var velocityUnits = $('#velocityUnits');
+    velocityUnits.click(function() {
+                              if(velocityUnits.text() === "MPH")
+                              {
+                                  velocityUnits.text("KPH");
+                              }
+                              else velocityUnits.text("MPH");
+                        });
 
-                                  adjvalue = data.value;
+   vehicle.vehicleSpeed.subscribe(function(data) {
+                                 console.log("Vehicle data" + data.speed);
+                                  adjvalue = data.speed;
+                                  curVss = adjvalue;
                                   var velocityUnits = $('#velocityUnits');
 
                                   if(velocityUnits.text() === "MPH")
-                                      adjvalue = Math.floor(data.value * 0.62137);
+                                      adjvalue = Math.floor(adjvalue * 0.62137);
 
                                   $('#velocity').text(adjvalue);
 
                                   calcAverageVelocity(adjvalue);
-                              },false);
+                              });
 
-    document.addEventListener("running_status_engine_speed", function(data) {
-                                  var value = data.value;
+   vehicle.engineSpeed.subscribe(function(data) {
+                                  var value = data.speed;
                                   if(value > 10000) value =10000;
                                   var needleDegs = value / 10000 * 180;
                                   $('#rpms').text(value);
                                   $('#rpmNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
-                              },false);
-
-    document.addEventListener("running_status_transmission_gear_status",function(data) {
-                                  value = data.value;
-                                                                 if(value == 128)
-                                                                         $('#gear').text('Reverse');
-                                                                 else if(value == 0)
-                                                                         $('#gear').text('Neutral');
+                              });
+
+    vehicle.transmission.subscribe(function(data) {
+                                  value = data.gear;
+                                  if(value == 128)
+                                      $('#gear').text('Reverse');
+                                  else if(value == 0)
+                                      $('#gear').text('Neutral');
                                   else $('#gear').text(value);
-                                                                 
-                              },false);
 
-    document.addEventListener("running_status_steering_wheel_angle", function(data) {
-                                  value = data.value;
+                              });
+
+    vehicle.steeringWheel.subscribe(function(data) {
+                                  value = data.angle;
                                   $('#wheel').css("-webkit-transform","rotate("+value+"deg)");
                                   $('#machinegun').css("-webkit-transform","rotate("+value+"deg)");
-                              },false);
+                              });
 
-    document.addEventListener("ThrottlePosition", function(data) {
+    vehicle.throttlePosition.subscribe(function(data) {
                                   value = data.value;
                                   var needleDegs = (value / 100 * 180) + 270
 
                                   $('#throttleNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
 
-                              },false);
+                              });
 
-    document.addEventListener("EngineCoolantTemperature", function(data) {
-                                  value = data.value;
+    vehicle.engineCoolant.subscribe(function(data) {
+                                  value = data.temperature;
                                   var needleDegs = (value / 180 * 70) + 270
 
                                   $('#engineCoolantNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
 
-                              },false);
-
-    document.addEventListener("MachineGunTurretStatus", function(data) {
-                                  value = data.value;
-                                  if(value === "1")
-                                      $('#machineGunTurretPopup').popup('open');
-                                  else $('#machineGunTurretPopup').popup('close');
-
-                              },false);
-
-
-
-}
-
-function connect(addy)
-{
-    vehicle = new Vehicle(connected, function(){$('#velocity').text("ERR");}, "ws://"+addy, "http-only");
-}
-
-window.onload = function()
-{
-    var addy = "127.0.0.1:23000";
-
-    if(typeof(Storage)!== "undefined")
-    {
-        addyTemp = localStorage.address;
-        if(addyTemp !== undefined) addy = addyTemp;
-    }
-
-    $("#address").val(addy);
-    $("#address").change(function() { localStorage.address = $("#address").val(); });
-    $("#connectButton").click(function() { connect(addy) });
-
-
-
-    connect(addy);
-
-    var velocityUnits = $('#velocityUnits');
-    velocityUnits.click(function() {
-                              if(velocityUnits.text() === "MPH")
-                              {
-                                  velocityUnits.text("KPH");
-                              }
-                              else velocityUnits.text("MPH");
-                        });
+                              });
 }