More set commands being implemented. Defrost, fanspeed, seat heater, and hazard
[profile/ivi/Modello_Hvac.git] / js / main.js
1 /*global Bootstrap, hvacControler*/
2
3 /**
4  * Heat, Ventilation and Air Conditioning provides UI controls to operate this subystem of the car from
5  * [navigator.vehicle API](https://raw.github.com/otcshare/automotive-message-broker/master/docs/amb.idl).
6  * Uses mainly {{#crossLink "CarIndicator"}}{{/crossLink}} module from {{#crossLink "Bootstrap/carIndicator:property"}}{{/crossLink}}.
7  *
8  * Application directly controls following AMB properties:
9  *
10  * * WindowStatus
11  *   * FrontDefrost
12  *   * RearDefrost
13  * * HVAC
14  *   * FanSpeed
15  *   * TargetTemperatureRight
16  *   * TargetTemperatureLeft
17  *   * SeatHeaterRight
18  *   * SeatHeaterLeft
19  *   * AirConditioning
20  *   * AirRecirculation
21  *   * AirflowDirection
22  * * LightStatus
23  *   * Hazard
24  * * DirectionIndicationINST
25  * * DirectionIndicationMS
26  * * ACCommand
27  * * RecircReq
28  * * FrontTSetRightCmd
29  * * FrontTSetLeftCmd
30  * * FrontBlwrSpeedCmd
31  * * HeatedSeatFRModeRequest
32  * * HeatedSeatFRRequest
33  * * HeatedSeatFLModeRequest
34  * * HeatedSeatFLRequest
35  * * FLHSDistrCmd
36  * * FRHSDistrCmd
37  *
38  * Additionaly HVAC application implements following scenarios:
39  *
40  * * Automatic AC mode - Sets Fan Speed to zero, Airflow direction to OFF, Air recirculation to off and both target temperatures to 22 degrees.
41  * Turning off Automatic AC mode will set all properties to their previous values. If any of properties are set separately Automatic AC mode is
42  * turned off.
43  * * Max defrost mode - Maximum defrost mode sets Fan speed to maximum value, Airflow direction to Screen and resets Left target temperature
44  * within range 16 to 28 degrees. If any of properties are set separately Max defrost mode is turned off.
45  *
46  * Hover and click on elements in images below to navigate to components of HVAC application.
47  *
48  * <img id="Image-Maps_1201312180420487" src="../assets/img/hvac.png" usemap="#Image-Maps_1201312180420487" border="0" width="649" height="1152" alt="" />
49  *   <map id="_Image-Maps_1201312180420487" name="Image-Maps_1201312180420487">
50  *     <area shape="rect" coords="0,0,573,78" href="../classes/TopBarIcons.html" alt="Top bar icons" title="Top bar icons" />
51  *     <area shape="rect" coords="0,994,644,1147" href="../classes/BottomPanel.html" alt="bottom panel" title="Bottom panel" />
52  *     <area shape="rect" coords="573,1,644,76" href="../modules/Settings.html" alt="Settings" title="Settings" />
53  *     <area  shape="rect" coords="138,103,513,176" alt="Hazard button" title="Hazard button" target="_self" href="../classes/hvacControler.html#method_onHazardChanged"     >
54  *     <area  shape="rect" coords="13,197,99,653" alt="Left target temperature" title="Left target temperature" target="_self" href="../classes/hvacControler.html#method_onTargetTemperatureLeftChanged"     >
55  *     <area  shape="rect" coords="551,194,637,650" alt="Right target temperature" title="Right target temperature" target="_self" href="../classes/hvacControler.html#method_onTargetTemperatureRightChanged"     >
56  *     <area  shape="rect" coords="369,403,512,612" alt="Right target temperature indicator" title="Right target temperature indicator" target="_self" href="../classes/hvacControler.html#method_onTargetTemperatureRightChanged"     >
57  *     <area  shape="rect" coords="135,404,278,614" alt="Left target temperature indicator" title="Left target temperature indicator" target="_self" href="../classes/hvacControler.html#method_onTargetTemperatureLeftChanged"     >
58  *     <area  shape="rect" coords="137,252,278,368" alt="Left seat heater" title="Left seat heater" target="_self" href="../classes/hvacControler.html#method_onSeatHeaterLeftChanged"     >
59  *     <area  shape="rect" coords="370,252,511,368" alt="Right seat heater" title="Right seat heater" target="_self" href="../classes/hvacControler.html#method_onSeatHeaterRightChanged"     >
60  *     <area  shape="rect" coords="391,780,491,860" alt="Air recirculation" title="Air recirculation" target="_self" href="../classes/hvacControler.html#method_onAirRecirculationChanged"     >
61  *     <area  shape="rect" coords="157,780,257,860" alt="Fan status" title="Fan status" target="_self" href="../classes/hvacControler.html#method_onFanChanged"     >
62  *     <area  shape="rect" coords="273,781,373,861" alt="Automatic AC mode" title="Automatic AC mode" target="_self" href="../classes/HVAC.html"     >
63  *     <area  shape="rect" coords="151,653,498,764" alt="Fan speed" title="Fan speed" target="_self" href="../classes/hvacControler.html#method_onFanSpeedChanged"     >
64  *     <area  shape="rect" coords="17,672,135,961" alt="Airflow direction" title="Airflow direction" target="_self" href="../classes/hvacControler.html#method_onAirflowDirectionChanged"     >
65  *     <area  shape="rect" coords="516,781,626,859" alt="Rear defrost" title="Rear defrost" target="_self" href="../classes/hvacControler.html#method_onRearDefrostChanged"     >
66  *     <area  shape="rect" coords="518,876,627,956" alt="Front defrost" title="Front defrost" target="_self" href="../classes/hvacControler.html#method_onFrontDefrostChanged"     >
67  *     <area  shape="rect" coords="515,676,627,764" alt="Max defrost mode" title="Max defrost mode" target="_self" href="../classes/HVAC.html"     >
68  *     <area shape="rect" coords="646,1150,648,1152" alt="Image Map" title="Image Map" href="http://www.image-maps.com/index.php?aff=mapped_users_0" >
69  *  </map>
70  * </img>
71  *
72  * @module HVACApplication
73  * @main HVACApplication
74  * @class HVAC
75  **/
76
77 /**
78  * Reference to instance of bootstrap class.
79  * @property bootstrap {Bootstrap}
80  */
81 var bootstrap;
82
83 /**
84  * Initializes plugins and register events for HVAC app.
85  * @method init
86  * @static
87  **/
88 var init = function() {
89         "use strict";
90         var hvacIndicator = new hvacControler();
91         bootstrap = new Bootstrap(function(status) {
92                 $("#topBarIcons").topBarIconsPlugin('init');
93                 $('#bottomPanel').bottomPanel('init');
94
95                 $(".noUiSliderLeft").noUiSlider({
96                         range : [ 0, 14 ],
97                         step : 1,
98                         start : 14,
99                         handles : 1,
100                         connect : "upper",
101                         orientation : "vertical",
102                         slide : function() {
103                                 if ($("#defrost_max_btn").hasClass("on")) {
104                                         switch ($(this).val()) {
105                                         case 0:
106                                                 $(this).val(1);
107                                                 break;
108                                         case 14:
109                                                 $(this).val(13);
110                                                 break;
111                                         }
112                                 }
113                                 bootstrap.carIndicator.setStatus("targetTemperatureLeft", ($(this).val() + 29) - ($(this).val() * 2));
114                         }
115                 });
116
117                 $(".noUiSliderRight").noUiSlider({
118                         range : [ 0, 14 ],
119                         step : 1,
120                         start : 14,
121                         handles : 1,
122                         connect : "upper",
123                         orientation : "vertical",
124                         slide : function() {
125                                 bootstrap.carIndicator.setStatus("targetTemperatureRight", ($(this).val() + 29) - ($(this).val() * 2));
126                         }
127                 });
128
129                 $(".noUiSliderFan").noUiSlider({
130                         range : [ 0, 8 ],
131                         step : 1,
132                         start : 0,
133                         handles : 1,
134                         connect : "upper",
135                         orientation : "horizontal",
136                         slide : function() {
137                                 bootstrap.carIndicator.setStatus("fanSpeed", $(this).val());
138
139                                 if ($(this).val() > 0 && $(this).val() < 9) {
140                                         bootstrap.carIndicator.setStatus("FrontBlwrSpeedCmd", ($(this).val() * 2) - 1);
141                                 }
142                         }
143                 });
144
145                 bootstrap.carIndicator.addListener({
146                         onAirRecirculationChanged : function(newValue) {
147                                 hvacIndicator.onAirRecirculationChanged(newValue);
148                         },
149                         onFanChanged : function(newValue) {
150                                 hvacIndicator.onFanChanged(newValue);
151                         },
152                         onFanSpeedChanged : function(newValue) {
153                                 hvacIndicator.onFanSpeedChanged(newValue);
154                         },
155                         onTargetTemperatureRightChanged : function(newValue) {
156                                 hvacIndicator.onTargetTemperatureRightChanged(newValue);
157                         },
158                         onTargetTemperatureLeftChanged : function(newValue) {
159                                 hvacIndicator.onTargetTemperatureLeftChanged(newValue);
160                         },
161                         onHazardChanged : function(newValue) {
162                                 hvacIndicator.onHazardChanged(newValue);
163                         },
164                         onSeatHeaterRightChanged : function(newValue) {
165                                 hvacIndicator.onSeatHeaterRightChanged(newValue);
166                         },
167                         onSeatHeaterLeftChanged : function(newValue) {
168                                 hvacIndicator.onSeatHeaterLeftChanged(newValue);
169                         },
170                         onAirflowDirectionChanged : function(newValue) {
171                                 hvacIndicator.onAirflowDirectionChanged(newValue);
172                         },
173                         onFrontDefrostChanged : function(newValue) {
174                                 hvacIndicator.onFrontDefrostChanged(newValue);
175                         },
176                         onRearDefrostChanged : function(newValue) {
177                                 hvacIndicator.onRearDefrostChanged(newValue);
178                         }
179                 });
180         });
181 };
182
183 /**
184  * Calls initialization fuction after document is loaded.
185  * @method $(document).ready
186  * @param init {function} Callback function for initialize Homescreen.
187  * @static
188  **/
189 $(function() {
190         "use strict";
191         // debug mode - window.setTimeout("init()", 20000);
192         init();
193 });