updated to use new vehicle api
[profile/ivi/GhostCluster.git] / business.js
1 var counter = 0;
2 var velocityStream;
3 var batteryVoltageStream;
4 var rpmStream;
5 var headingStream;
6 var engineCoolantStream;
7 var throttleStream;
8 var intakeAirTempStream;
9 var engineLoadStream;
10 var engineoiltemp;
11 var mafStream;
12
13 var vehicle;
14
15 var mpgReadings = 0;
16 var prevMpg = 0;
17 var curVss;
18
19 function calcAverageMpg(newMpg) {
20         prevMpg += parseInt(newMpg);
21         mpgReadings++;
22
23         var averageMpg = prevMpg / mpgReadings;
24         $("#avgmpg").text(Math.floor(averageMpg));
25 }
26
27
28 var velReadings = 0;
29 var prevVel = 0;
30
31 function calcAverageVelocity(newVel) {
32         prevVel += parseInt(newVel);
33         velReadings++;
34
35         var averageVel = prevVel / velReadings;
36         $("#avgspeed").text(Math.floor(averageVel));
37 }
38
39 window.onload = function()
40 {
41     var vehicle = tizen.vehicle
42
43     var velocityUnits = $('#velocityUnits');
44     velocityUnits.click(function() {
45                               if(velocityUnits.text() === "MPH")
46                               {
47                                   velocityUnits.text("KPH");
48                               }
49                               else velocityUnits.text("MPH");
50                         });
51
52    vehicle.vehicleSpeed.subscribe(function(data) {
53                                   console.log("Vehicle data" + data.speed);
54                                   adjvalue = data.speed;
55                                   curVss = adjvalue;
56                                   var velocityUnits = $('#velocityUnits');
57
58                                   if(velocityUnits.text() === "MPH")
59                                       adjvalue = Math.floor(adjvalue * 0.62137);
60
61                                   $('#velocity').text(adjvalue);
62
63                                   calcAverageVelocity(adjvalue);
64                               });
65
66    vehicle.engineSpeed.subscribe(function(data) {
67                                   var value = data.speed;
68                                   if(value > 10000) value =10000;
69                                   var needleDegs = value / 10000 * 180;
70                                   $('#rpms').text(value);
71                                   $('#rpmNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
72                               });
73
74     vehicle.transmission.subscribe(function(data) {
75                                   value = data.gear;
76                                   if(value == 128)
77                                       $('#gear').text('Reverse');
78                                   else if(value == 0)
79                                       $('#gear').text('Neutral');
80                                   else $('#gear').text(value);
81
82                               });
83
84     vehicle.steeringWheel.subscribe(function(data) {
85                                   value = data.angle;
86                                   $('#wheel').css("-webkit-transform","rotate("+value+"deg)");
87                                   $('#machinegun').css("-webkit-transform","rotate("+value+"deg)");
88                               });
89
90     vehicle.throttlePosition.subscribe(function(data) {
91                                   value = data.value;
92                                   var needleDegs = (value / 100 * 180) + 270
93
94                                   $('#throttleNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
95
96                               });
97
98     vehicle.engineCoolant.subscribe(function(data) {
99                                   value = data.temperature;
100                                   var needleDegs = (value / 180 * 70) + 270
101
102                                   $('#engineCoolantNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
103
104                               });
105 }