Updated GhostCluster web sample from upstream
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_AMBSimulator / project / js / randomizerDemo.js
1 /*global Simulator, TWEEN */
2
3 /**
4  * Script operates all indicators that are present in Dashboard application:
5  *
6  * * Vehicle speed similar as {{#crossLink "SpeedDemo2"}}speedDemo2{{/crossLink}}
7  * * Transmission gear similar as {{#crossLink "SpeedDemo2"}}speedDemo2{{/crossLink}}
8  * * Battery status same as {{#crossLink "BatteryDemo"}}batteryDemo{{/crossLink}}
9  * * Exterior brightness same as {{#crossLink "BatteryDemo"}}batteryDemo{{/crossLink}}
10  * * Head, parking lights
11  * * Front wheel radius
12  * * Child lock status
13  * * Exterior temperature
14  * * Tire pressure same as {{#crossLink "TirePressureDemo"}}tirePressureDemo{{/crossLink}}
15  *
16  * @module AMBSimulatorApplication
17  * @class RandomizerDemo
18  */
19
20 setInterval(function() {
21         "use strict";
22         TWEEN.update();
23 }, 200);
24
25 //gear & speed
26 var neutralGear, firstGear, secondGear, thirdGear, fourthGear;
27
28 function getGearTween(time, gear, speedFrom, speedTo) {
29         "use strict";
30         return new TWEEN.Tween({
31                 speed : speedFrom
32         }).to({
33                 speed : speedTo
34         }, time).onStart(function() {
35                 Simulator.set("vcan0", "TransmissionShiftPosition", gear, 0);
36         }).onUpdate(function() {
37                 Simulator.set("vcan0", "VehicleSpeed", this.speed, 0);
38         });
39 }
40 neutralGear = getGearTween(3000, "0", 0, 0).onComplete(function() {
41         "use strict";
42         firstGear = getGearTween(2000, "1", 0, 20);
43         secondGear = getGearTween(3000, "2", 20, 40);
44         thirdGear = getGearTween(4000, "3", 40, 60);
45         fourthGear = getGearTween(5000, "4", 60, 100).onComplete(function() {
46                 firstGear = getGearTween(2000, "1", 20, 0);
47                 secondGear = getGearTween(3000, "2", 40, 20);
48                 thirdGear = getGearTween(4000, "3", 60, 40);
49                 fourthGear = getGearTween(5000, "4", 100, 60);
50                 fourthGear.chain(thirdGear.chain(secondGear.chain(firstGear.chain(neutralGear)))).start();
51         });
52
53         firstGear.chain(secondGear.chain(thirdGear.chain(fourthGear))).start();
54 });
55
56 neutralGear.start();
57
58 // battery level && exterior Brightness
59 var batteryStatus, exteriorBrightness, headLights, parkingLights;
60
61 batteryStatus = new TWEEN.Tween({
62         battery : 100
63 }).to({
64         battery : 0
65 }, 10000).easing(TWEEN.Easing.Cubic.Out).onUpdate(function() {
66         "use strict";
67         Simulator.set("vcan0", "BatteryStatus", this.battery, 0);
68 }).repeat('Infinity').yoyo(true).start();
69
70 exteriorBrightness = new TWEEN.Tween({
71         brightness : 5000
72 }).to({
73         brightness : 0
74 }, 10000).onUpdate(function() {
75         "use strict";
76         if (this.brightness < 2000 && !headLights) {
77                 headLights = true;
78                 parkingLights = true;
79                 Simulator.set("vcan0", "LightHead", headLights, 0);
80                 Simulator.set("vcan0", "LightParking", parkingLights, 0);
81         } else if (this.brightness >= 2000 && headLights) {
82                 headLights = false;
83                 parkingLights = false;
84                 Simulator.set("vcan0", "LightHead", headLights, 0);
85                 Simulator.set("vcan0", "LightParking", parkingLights, 0);
86         }
87         Simulator.set("vcan0", "ExteriorBrightness", this.brightness, 0);
88 }).repeat('Infinity').yoyo(true).start();
89
90 // front wheel radius
91 var frontWheelRadius;
92
93 frontWheelRadius = new TWEEN.Tween({
94         radius : 1
95 }).to({
96         radius : 359
97 }, 5000).onUpdate(function() {
98         "use strict";
99         Simulator.set("vcan0", "SteeringWheelAngle", this.radius, 0);
100 }).repeat('Infinity').yoyo(true).start();
101
102 // head lights, parking lights, childlock, exterior temperature, weather
103 var childLock, extTemp, rand;
104
105 parkingLights = false;
106 childLock = false;
107 extTemp = 30;
108 function setRandomValues() {
109         "use strict";
110         rand = Math.random();
111         if (!headLights) {
112                 parkingLights = !parkingLights;
113                 Simulator.set("vcan0", "LightParking", parkingLights, 0);
114         }
115         extTemp = Math.floor(rand * 7) + (extTemp - 3);
116         extTemp = (extTemp < -21)? -21 : extTemp;
117         extTemp = (extTemp > 45)? 45 : extTemp;
118         Simulator.set("vcan0", "ExteriorTemperature", extTemp, 0);
119         Simulator.set("vcan0", "InteriorTemperature", extTemp+10, 0);
120         Simulator.set("vcan0", "Weather", Math.floor(rand * 3), 0);
121         childLock = !childLock;
122         Simulator.set("vcan0", "ChildLockStatus", childLock, 0);
123         setTimeout(setRandomValues, Math.floor(rand * 9500) + 500);
124 }
125 setRandomValues();
126
127 //tire
128 var tirePressure;
129
130 tirePressure = new TWEEN.Tween({
131         pressure: 0
132 }).to({
133         pressure: 3
134 }, 5000).easing(TWEEN.Easing.Cubic.InOut).onUpdate(function() {
135         "use strict";
136         Simulator.set("vcan0", "TirePressureLeftFront", this.pressure, 0);
137         Simulator.set("vcan0", "TirePressureRightFront", this.pressure, 0);
138         Simulator.set("vcan0", "TirePressureLeftRear", this.pressure, 0);
139         Simulator.set("vcan0", "TirePressureRightRear", this.pressure, 0);
140 }).repeat('Infinity').yoyo(true).start();