4 * Class provides methods to fill the content of HVAC's UI.
6 * @module HVACApplication
8 var hvacControler = function() {
14 * Holds statuses of connected buttons when turning Auto AC button ON.
15 * @property autoACStatus {Object}
21 airRecirculation : false,
22 targetTemperatureRight : 0,
23 targetTemperatureLeft : 0,
28 * Holds hazard timer object.
29 * @property hazardTimer {Object}
34 * Holds interval value for hazard timer in ms.
35 * @property hazardTimerInterval {Integer}
38 var hazardTimerInterval = 1000;
41 * Implements hazard light blinking functionality.
42 * @property hazardLight
48 if (hazardLight.currentIndex === 0) {
49 $("#hazard_btn").removeClass("blink");
50 hazardLight.currentIndex = 1;
51 } else if (hazardLight.currentIndex === 1) {
52 $("#hazard_btn").addClass("blink");
53 hazardLight.currentIndex = 0;
59 * Changes the status of AirflowDirection.
60 * @method changeAirflowDirectionStatus
61 * @param button {Object} AirflowDirection button
62 * @param currentStatus {Integer} current status of AirflowDirection
63 * @param value {Integer} AirflowDirection button value
64 * @return newStatus {Integer} a new status of AirflowDirection
66 function changeAirflowDirectionStatus(button, currentStatus, value) {
69 if ($(button).hasClass("on") === true) {
70 newStatus = currentStatus - value;
72 newStatus = currentStatus + value;
78 * Toggles the SeatHeater button to its corresponding value.
79 * @method toggleSeatHeaterButton
80 * @param status {Integer} status to toggle the SeatHeater button to
81 * @param button {Object} SeatHeater button to toggle
83 function toggleSeatHeaterButton(status, button) {
85 if ((status >= 0) && (status <= 3)) {
87 // Setting SeatHeater button to OFF state
88 if ($(button).hasClass("stage4")) {
89 $(button).removeClass("stage4");
91 if ($(button).hasClass("stage3")) {
92 $(button).removeClass("stage3");
94 if ($(button).hasClass("stage2")) {
95 $(button).removeClass("stage2");
97 if (!$(button).hasClass("stage1")) {
98 $(button).addClass("stage1");
103 // Nothing to do as SeatHeater button was set to OFF state above
106 $(button).addClass("stage2");
109 $(button).addClass("stage3");
112 $(button).addClass("stage4");
119 * Toggles the button ON/OFF.
120 * @method toggleButton
121 * @param buttonStatus {Boolean} ON/OFF status of the button
122 * @param button {Object} button to toggle ON/OFF
124 function toggleButton(buttonStatus, button) {
126 if (buttonStatus === true || buttonStatus === "true") {
127 $(button).addClass("on");
129 $(button).removeClass("on");
134 * Turns the Auto AC button OFF.
135 * @method switchAutoACOff
137 function switchAutoACOff() {
139 if ($("#fan_control_auto").hasClass("on")) {
140 $("#fan_control_auto").removeClass("on");
145 * Gets the TargetTemperature slider value depending on temperature.
146 * @method getTargetTemperatureSliderValue
147 * @param temperature {Integer} temperature in Celsius degrees
148 * @return value {Integer} TargetTemperature slider value
150 function getTargetTemperatureSliderValue(temperature) {
153 if (temperature > 28) {
156 } else if (temperature < 16) {
160 value = (temperature + 29) - (temperature * 2);
166 * Sets AirflowDirection status to all the corresponding signals.
167 * @method setAirFlowDirectionStatus
168 * @param newStatus {Integer} a new AirflowDirection status value
170 function setAirFlowDirectionStatus(newStatus) {
172 bootstrap.carIndicator.setStatus("airflowDirection", newStatus);
173 bootstrap.carIndicator.setStatus("FLHSDistrCmd", newStatus);
174 bootstrap.carIndicator.setStatus("FRHSDistrCmd", newStatus);
178 * Sets the status of AirRecirculation button. Allows following values:
180 * * `true` - `ON` - also turns off Automatic AC mode
183 * @method onAirRecirculationChanged
184 * @param newStatus {Boolean} New status of AirRecirculation
186 hvacControler.prototype.onAirRecirculationChanged = function(newStatus) {
188 if (newStatus === false || newStatus === "false") {
189 $("#fan_control_circ").removeClass("on");
191 $("#fan_control_circ").addClass("on");
197 * Sets the status of A/C button. Allows following values:
200 * * `false` - `OFF` - also turns off Automatic AC mode
202 * @method onFanChanged
203 * @param newStatus {Boolean} New status of AirConditioning
205 hvacControler.prototype.onFanChanged = function(newStatus) {
207 if (newStatus === false || newStatus === "false") {
208 $("#fan_control_ac").removeClass("on");
211 $("#fan_control_ac").addClass("on");
216 * Sets the status of FanSpeed button. Allows following values:
219 * * `1` - `8` = sets fan speed to this value and also turns off Automatic AC mode
221 * @method onFanSpeedChanged
222 * @param newStatus {Integer} new status of FanSpeed
224 hvacControler.prototype.onFanSpeedChanged = function(newStatus) {
226 $("#fanSpeedSlider").val(newStatus);
227 $(".fanSpeedOn").css('width', parseInt($(".noUiSliderFan.horizontal.connect").find("a").css('left'), 10));
228 if (newStatus === 0) {
229 bootstrap.carIndicator.setStatus("airflowDirection", 0);
230 } else if (newStatus > 0) {
236 * Sets the status of Right TargetTemperature slider and Right Temperature scrollable box.
237 * Temperature can be set to following values:
239 * * below `16` - `LOW`, also turns off Automatic AC mode
240 * * between `16` and `28` - exact temperature in Celsius degrees
241 * * above `28` - `HIGH`, also turns off Automatic AC mode
243 * @method onTargetTemperatureRightChanged
244 * @param newStatus {Integer} new status of Right TargetTemperature in Celsius degrees
246 hvacControler.prototype.onTargetTemperatureRightChanged = function(newStatus) {
248 var value = getTargetTemperatureSliderValue(newStatus);
249 $("#noUiSliderRight").val(value);
250 $(".scrollable.right").find(".temperature").stop(true, true).animate({
251 "top" : (-680.0606 + (value * +48.57) + '%')
256 * Sets the status of Left TargetTemperature slider and Left Temperature scrollable box.
257 * Temperature can be set to following values:
259 * * below `16` - `LOW`, also turns off Automatic AC mode
260 * * between `16` and `28` - exact temperature in Celsius degrees
261 * * above `28` - `HIGH`, also turns off Automatic AC mode
263 * @method onTargetTemperatureLeftChanged
264 * @param newStatus {Integer} new status of Left TargetTemperature in Celsius degrees
266 hvacControler.prototype.onTargetTemperatureLeftChanged = function(newStatus) {
268 var value = getTargetTemperatureSliderValue(newStatus);
269 $("#noUiSliderLeft").val(value);
270 $(".scrollable.left").find(".temperature").stop(true, true).animate({
271 "top" : (-680.0606 + (value * +48.57) + '%')
276 * Sets the status of Hazard button. Blink interval of hazard light can be configured
277 * using [hazardTimerInterval](../classes/hvacControler.html#property_hazardTimerInterval).
278 * @method onHazardChanged
279 * @param newStatus {Boolean} new status of the Hazard
281 hvacControler.prototype.onHazardChanged = function(newStatus) {
283 if (newStatus === true || newStatus === "true") {
284 $("#hazard_btn").addClass("on");
285 hazardTimer = setInterval(hazardLight.change, hazardTimerInterval);
287 clearInterval(hazardTimer);
289 $("#hazard_btn").removeClass("on");
290 if ($("#hazard_btn").hasClass("blink") === true) {
291 $("#hazard_btn").removeClass("blink");
297 * Sets the status of Right SeatHeater button. Allows 4 levels of heating:
304 * @method onSeatHeaterRightChanged
305 * @param status {Integer} new status of Right SeatHeater
307 hvacControler.prototype.onSeatHeaterRightChanged = function(status) {
309 toggleSeatHeaterButton(status, "#right_seat_btn_stage");
313 * Sets the status of Left SeatHeater button. Allows 4 levels of heating:
320 * @method onSeatHeaterLeftChanged
321 * @param status {Integer} new status of Left SeatHeater
323 hvacControler.prototype.onSeatHeaterLeftChanged = function(status) {
325 toggleSeatHeaterButton(status, "#left_seat_btn_stage");
329 * Sets the status of AirflowDirection buttons to one of the following values:
333 * * `4` - `SCREEN` - when disabled Max defrost mode is turned off as well.
335 * Values can be combined, e.g. `3` is `FOOT` + `FACE`. If any of these values is
336 * set Automatic AC mode is turned off.
338 * @method onAirflowDirectionChanged
339 * @param newStatus {Integer} new status of the AirflowDirection
341 hvacControler.prototype.onAirflowDirectionChanged = function(newStatus) {
343 if ((newStatus >= 0) && (newStatus <= 7)) {
345 if (newStatus === 7) {
346 // Setting all the buttons to ON state
347 if ($("#fan_dir_up_btn").hasClass("on") === false) {
348 $("#fan_dir_up_btn").addClass("on");
350 if ($("#fan_dir_down_btn").hasClass("on") === false) {
351 $("#fan_dir_down_btn").addClass("on");
353 if ($("#fan_dir_right_btn").hasClass("on") === false) {
354 $("#fan_dir_right_btn").addClass("on");
357 // Setting all the buttons to OFF state
358 if ($("#fan_dir_up_btn").hasClass("on") === true) {
359 $("#fan_dir_up_btn").removeClass("on");
361 if ($("#fan_dir_down_btn").hasClass("on") === true) {
362 $("#fan_dir_down_btn").removeClass("on");
364 if ($("#fan_dir_right_btn").hasClass("on") === true) {
365 $("#fan_dir_right_btn").removeClass("on");
370 // AUTO state when all the buttons are OFF
372 // Nothing to do as all the buttons were set to OFF state above
376 $("#fan_dir_down_btn").addClass("on");
380 $("#fan_dir_right_btn").addClass("on");
384 $("#fan_dir_down_btn").addClass("on");
385 $("#fan_dir_right_btn").addClass("on");
389 $("#fan_dir_up_btn").addClass("on");
391 // FOOT ON, SCREEN ON
393 $("#fan_dir_down_btn").addClass("on");
394 $("#fan_dir_up_btn").addClass("on");
396 // SCREEN ON, FACE ON
398 $("#fan_dir_up_btn").addClass("on");
399 $("#fan_dir_right_btn").addClass("on");
401 // FOOT ON, FACE ON, SCREEN ON
403 // Nothing to do as this option is handled above
407 // If SCREEN OFF, Max Defrost OFF
408 if ((newStatus >= 0) && (newStatus <= 3)) {
409 if ($("#defrost_max_btn").hasClass("on")) {
410 $("#defrost_max_btn").removeClass("on");
421 * Sets the status of Rear Defrost button. Allows following values:
426 * @method onRearDefrostChanged
427 * @param newStatus {Boolean} new status of the Rear Defrost
429 hvacControler.prototype.onRearDefrostChanged = function(newStatus) {
431 toggleButton(newStatus, "#defrost_rear_btn");
435 * Sets the status of Front Defrost button. Allows following values:
440 * @method onFrontDefrostChanged
441 * @param newStatus {Boolean} new status of the Front Defrost
443 hvacControler.prototype.onFrontDefrostChanged = function(newStatus) {
445 toggleButton(newStatus, "#defrost_front_btn");
449 * HVAC buttons initialisation.
450 * @method initButtons
452 hvacControler.prototype.initButtons = function() {
455 $("#hazard_btn").bind('click', function() {
456 bootstrap.carIndicator.setStatus("hazard", !bootstrap.carIndicator.status.hazard);
457 bootstrap.carIndicator.setStatus("DirectionIndicationINST", !bootstrap.carIndicator.status.hazard ? 3 : 0);
458 bootstrap.carIndicator.setStatus("DirectionIndicationMS", !bootstrap.carIndicator.status.hazard ? 3 : 0);
461 $("#fan_control_ac").bind('click', function() {
462 bootstrap.carIndicator.setStatus("Fan", !bootstrap.carIndicator.status.fan);
463 bootstrap.carIndicator.setStatus("ACCommand", !bootstrap.carIndicator.status.fan);
466 $("#fan_control_auto").bind('click', function() {
467 if (!$("#fan_control_auto").hasClass("on")) {
468 autoACStatus.fanSpeed = bootstrap.carIndicator.status.fanSpeed;
469 autoACStatus.airflowDirection = bootstrap.carIndicator.status.airflowDirection;
470 autoACStatus.fan = bootstrap.carIndicator.status.fan;
471 autoACStatus.airRecirculation = bootstrap.carIndicator.status.airRecirculation;
472 autoACStatus.targetTemperatureRight = bootstrap.carIndicator.status.targetTemperatureRight;
473 autoACStatus.targetTemperatureLeft = bootstrap.carIndicator.status.targetTemperatureLeft;
474 autoACStatus.maxDefrost = $("#defrost_max_btn").hasClass("on") ? true : false;
476 if (autoACStatus.maxDefrost) {
477 $("#defrost_max_btn").removeClass("on");
480 $("#fan_control_auto").addClass("on");
482 bootstrap.carIndicator.setStatus("fanSpeed", 0);
484 setAirFlowDirectionStatus(0);
486 bootstrap.carIndicator.setStatus("Fan", true);
487 bootstrap.carIndicator.setStatus("ACCommand", true);
489 bootstrap.carIndicator.setStatus("airRecirculation", false);
490 bootstrap.carIndicator.setStatus("RecircReq", 0);
492 if (autoACStatus.targetTemperatureRight < 16 || autoACStatus.targetTemperatureRight > 28) {
493 bootstrap.carIndicator.setStatus("targetTemperatureRight", 22);
494 bootstrap.carIndicator.setStatus("FrontTSetRightCmd", 22);
496 if (autoACStatus.targetTemperatureLeft < 16 || autoACStatus.targetTemperatureLeft > 28) {
497 bootstrap.carIndicator.setStatus("targetTemperatureLeft", 22);
498 bootstrap.carIndicator.setStatus("FrontTSetLeftCmd", 22);
501 $("#fan_control_auto").removeClass("on");
503 bootstrap.carIndicator.setStatus("fanSpeed", autoACStatus.fanSpeed);
504 if (autoACStatus.fanSpeed > 0 && autoACStatus.fanSpeed < 9) {
505 bootstrap.carIndicator.setStatus("FrontBlwrSpeedCmd", (autoACStatus.fanSpeed * 2) - 1);
508 setAirFlowDirectionStatus(autoACStatus.airflowDirection);
510 bootstrap.carIndicator.setStatus("Fan", autoACStatus.fan);
511 bootstrap.carIndicator.setStatus("ACCommand", autoACStatus.fan);
513 bootstrap.carIndicator.setStatus("airRecirculation", autoACStatus.airRecirculation);
514 bootstrap.carIndicator.setStatus("RecircReq", autoACStatus.airRecirculation ? 1 : 0);
516 bootstrap.carIndicator.setStatus("targetTemperatureRight", autoACStatus.targetTemperatureRight);
517 bootstrap.carIndicator.setStatus("FrontTSetRightCmd", autoACStatus.targetTemperatureRight);
519 bootstrap.carIndicator.setStatus("targetTemperatureLeft", autoACStatus.targetTemperatureLeft);
520 bootstrap.carIndicator.setStatus("FrontTSetLeftCmd", autoACStatus.targetTemperatureRight);
522 if (autoACStatus.maxDefrost) {
523 $("#defrost_max_btn").addClass("on");
528 $("#fan_control_circ").bind('click', function() {
529 bootstrap.carIndicator.setStatus("airRecirculation", !bootstrap.carIndicator.status.airRecirculation);
530 bootstrap.carIndicator.setStatus("RecircReq", !bootstrap.carIndicator.status.airRecirculation ? 1 : 0);
532 // SeatHeater - front right
533 $("#right_seat_btn").bind('click', function() {
534 var status = bootstrap.carIndicator.status.seatHeaterRight;
535 if (((status) >= 0) && ((status) <= 3)) {
546 bootstrap.carIndicator.setStatus("seatHeaterRight", status);
549 bootstrap.carIndicator.setStatus("HeatedSeatFRModeRequest", 3);
551 bootstrap.carIndicator.setStatus("HeatedSeatFRModeRequest", 0);
569 bootstrap.carIndicator.setStatus("HeatedSeatFRRequest", request);
572 // SeatHeater - front left
573 $("#left_seat_btn").bind('click', function() {
574 var status = bootstrap.carIndicator.status.seatHeaterLeft;
575 if (((status) >= 0) && ((status) <= 3)) {
586 bootstrap.carIndicator.setStatus("seatHeaterLeft", status);
589 bootstrap.carIndicator.setStatus("HeatedSeatFLModeRequest", 3);
591 bootstrap.carIndicator.setStatus("HeatedSeatFLModeRequest", 0);
609 bootstrap.carIndicator.setStatus("HeatedSeatFLRequest", request);
612 // AirflowDirection - FloorDuct - 1 (FOOT)
613 $("#fan_dir_down_btn").bind('click', function() {
614 var currentStatus = bootstrap.carIndicator.status.airflowDirection;
615 if ((currentStatus >= 0) && (currentStatus <= 7) && (bootstrap.carIndicator.status.fanSpeed !== 0)) {
616 var newStatus = changeAirflowDirectionStatus("#fan_dir_down_btn", currentStatus, 1);
617 setAirFlowDirectionStatus(newStatus);
620 // AirflowDirection - Defroster - 4 (SCREEN)
621 $("#fan_dir_up_btn").bind('click', function() {
622 var currentStatus = bootstrap.carIndicator.status.airflowDirection;
623 if ((currentStatus >= 0) && (currentStatus <= 7) && (bootstrap.carIndicator.status.fanSpeed !== 0)) {
624 var newStatus = changeAirflowDirectionStatus("#fan_dir_up_btn", currentStatus, 4);
625 setAirFlowDirectionStatus(newStatus);
628 // AirflowDirection - Front - 2 (FACE)
629 $("#fan_dir_right_btn").bind('click', function() {
630 var currentStatus = bootstrap.carIndicator.status.airflowDirection;
631 if ((currentStatus >= 0) && (currentStatus <= 7) && (bootstrap.carIndicator.status.fanSpeed !== 0)) {
632 var newStatus = changeAirflowDirectionStatus("#fan_dir_right_btn", currentStatus, 2);
633 setAirFlowDirectionStatus(newStatus);
637 $("#defrost_max_btn").bind('click', function() {
638 if ($("#defrost_max_btn").hasClass("on")) {
639 $("#defrost_max_btn").removeClass("on");
641 $("#defrost_max_btn").addClass("on");
643 if (bootstrap.carIndicator.status.targetTemperatureLeft < 16) {
644 bootstrap.carIndicator.setStatus("targetTemperatureLeft", 16);
645 bootstrap.carIndicator.setStatus("FrontTSetLeftCmd", 16);
647 if (bootstrap.carIndicator.status.targetTemperatureLeft > 28) {
648 bootstrap.carIndicator.setStatus("targetTemperatureLeft", 28);
649 bootstrap.carIndicator.setStatus("FrontTSetLeftCmd", 28);
652 bootstrap.carIndicator.setStatus("fanSpeed", 8);
653 bootstrap.carIndicator.setStatus("FrontBlwrSpeedCmd", 15);
655 setAirFlowDirectionStatus(7);
661 $("#defrost_rear_btn").bind('click', function() {
662 bootstrap.carIndicator.setStatus("rearDefrost", !bootstrap.carIndicator.status.rearDefrost);
665 $("#defrost_front_btn").bind('click', function() {
666 bootstrap.carIndicator.setStatus("frontDefrost", !bootstrap.carIndicator.status.frontDefrost);