Initial commit of the HVAC app
[profile/ivi/html5_UI_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  * [tizen.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                                 bootstrap.carIndicator.setStatus("FrontTSetLeftCmd", ($(this).val() + 29) - ($(this).val() * 2));
115                         }
116                 });
117
118                 $(".noUiSliderRight").noUiSlider({
119                         range : [ 0, 14 ],
120                         step : 1,
121                         start : 14,
122                         handles : 1,
123                         connect : "upper",
124                         orientation : "vertical",
125                         slide : function() {
126                                 bootstrap.carIndicator.setStatus("targetTemperatureRight", ($(this).val() + 29) - ($(this).val() * 2));
127                                 bootstrap.carIndicator.setStatus("FrontTSetRightCmd", ($(this).val() + 29) - ($(this).val() * 2));
128                         }
129                 });
130
131                 $(".noUiSliderFan").noUiSlider({
132                         range : [ 0, 8 ],
133                         step : 1,
134                         start : 0,
135                         handles : 1,
136                         connect : "upper",
137                         orientation : "horizontal",
138                         slide : function() {
139                                 bootstrap.carIndicator.setStatus("fanSpeed", $(this).val());
140
141                                 if ($(this).val() > 0 && $(this).val() < 9) {
142                                         bootstrap.carIndicator.setStatus("FrontBlwrSpeedCmd", ($(this).val() * 2) - 1);
143                                 }
144                         }
145                 });
146
147                 bootstrap.carIndicator.addListener({
148                         onAirRecirculationChanged : function(newValue) {
149                                 hvacIndicator.onAirRecirculationChanged(newValue);
150                         },
151                         onFanChanged : function(newValue) {
152                                 hvacIndicator.onFanChanged(newValue);
153                         },
154                         onFanSpeedChanged : function(newValue) {
155                                 hvacIndicator.onFanSpeedChanged(newValue);
156                         },
157                         onTargetTemperatureRightChanged : function(newValue) {
158                                 hvacIndicator.onTargetTemperatureRightChanged(newValue);
159                         },
160                         onTargetTemperatureLeftChanged : function(newValue) {
161                                 hvacIndicator.onTargetTemperatureLeftChanged(newValue);
162                         },
163                         onHazardChanged : function(newValue) {
164                                 hvacIndicator.onHazardChanged(newValue);
165                         },
166                         onSeatHeaterRightChanged : function(newValue) {
167                                 hvacIndicator.onSeatHeaterRightChanged(newValue);
168                         },
169                         onSeatHeaterLeftChanged : function(newValue) {
170                                 hvacIndicator.onSeatHeaterLeftChanged(newValue);
171                         },
172                         onAirflowDirectionChanged : function(newValue) {
173                                 hvacIndicator.onAirflowDirectionChanged(newValue);
174                         },
175                         onFrontDefrostChanged : function(newValue) {
176                                 hvacIndicator.onFrontDefrostChanged(newValue);
177                         },
178                         onRearDefrostChanged : function(newValue) {
179                                 hvacIndicator.onRearDefrostChanged(newValue);
180                         }
181                 });
182         });
183 };
184
185 /**
186  * Calls initialization fuction after document is loaded.
187  * @method $(document).ready
188  * @param init {function} Callback function for initialize Homescreen.
189  * @static
190  **/
191 $(function() {
192         "use strict";
193         // debug mode - window.setTimeout("init()", 20000);
194         init();
195 });