2 * Copyright (c) 2013, Ford Motor Company All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met: ·
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer. · Redistributions in binary
8 * form must reproduce the above copyright notice, this list of conditions and
9 * the following disclaimer in the documentation and/or other materials provided
10 * with the distribution. · Neither the name of the Ford Motor Company nor the
11 * names of its contributors may be used to endorse or promote products derived
12 * from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
27 * @name SDL.SDLController
28 * @desc Main SDL Controller
29 * @category Controller
30 * @filesource app/controller/sdl/SDLController.js
33 SDL.SDLController = Em.Object
36 * Current system context
40 sysContext: function() {
42 if (SDL.VRPopUp.VRActive) {
45 if (SDL.AlertPopUp.active) {
48 if ( SDL.SliderView.active
49 || SDL.InteractionChoicesView.active
50 || SDL.ScrollableMessage.active
51 || SDL.AudioPassThruPopUp.activate
52 || SDL.VRHelpListView.active) {
54 return 'HMI_OBSCURED';
56 if (SDL.OptionsView.active) {
59 if (SDL.States.info.nonMedia.active
60 || SDL.States.media.sdlmedia.active
61 || SDL.States.navigationApp.baseNavigation.active) {
67 }.property('SDL.OptionsView.active',
68 'SDL.SliderView.active',
69 'SDL.VRPopUp.VRActive',
70 'SDL.AlertPopUp.active',
71 'SDL.States.info.nonMedia.active',
72 'SDL.States.media.sdlmedia.active',
73 'SDL.States.navigationApp.baseNavigation.active',
74 'SDL.ScrollableMessage.active',
75 'SDL.InteractionChoicesView.active',
76 'SDL.VRHelpListView.active',
77 'SDL.AudioPassThruPopUp.activate'),
80 * List of SDL application models
86 1: SDL.SDLNonMediaModel
90 * Registered components handler
94 activateTBT: function(){
95 if (SDL.SDLAppController.model && SDL.SDLAppController.model.tbtActivate) {
96 SDL.TurnByTurnView.activate(SDL.SDLAppController.model.appID);
101 * Registered components handler
105 registeredComponentStatus: function(component) {
107 for ( var i = 0; i < SDL.SDLModel.registeredComponents.length; i++) {
108 if (SDL.SDLModel.registeredComponents[i].type == component) {
109 SDL.SDLModel.set('registeredComponents.' + i + '.state', true);
116 * Registered components handler
120 unregisterComponentStatus: function(component) {
122 for ( var i = 0; i < SDL.SDLModel.registeredComponents.length; i++) {
123 if (SDL.SDLModel.registeredComponents[i].type == component) {
124 SDL.SDLModel.set('registeredComponents.' + i + '.state', false);
131 * Notification from state manager about triggered state
132 * Method aborts all popups and requests currently in process
136 triggerState: function(){
137 if (SDL.SliderView.active) {
138 SDL.SliderView.deactivate(false);
143 * Notify SDLCore that HMI is ready and all components are registered
147 componentsReadiness: function(component) {
149 for ( var i = 0; i < SDL.SDLModel.registeredComponents.length; i++) {
150 if (!SDL.SDLModel.registeredComponents[i].state) {
154 FFW.BasicCommunication.onReady();
155 SDL.SDLModel.timeStamp = new Date().getTime();
157 console.log(SDL.SDLModel.timeStamp);
159 }.observes('SDL.SDLModel.registeredComponents.@each.state'),
162 * Show VrHelpItems popup with necessary params
163 * if VRPopUp is active - show data from Global Properties
164 * if VRPopUp and InteractionChoicesView are active - show data from PerformInteraction request
167 showVRHelpItems: function() {
169 if (SDL.SDLAppController.model) {
170 if (SDL.SDLModel.VRActive && SDL.SDLModel.interactionData.vrHelp) {
172 SDL.SDLModel.ShowVrHelp(SDL.SDLModel.interactionData.vrHelpTitle, SDL.SDLModel.interactionData.vrHelp);
173 } else if (SDL.SDLModel.VRActive && !SDL.SDLModel.interactionData.vrHelp && SDL.SDLAppController.model.globalProperties.vrHelp) {
175 if (SDL.SDLAppController.model) {
176 SDL.SDLModel.ShowVrHelp(SDL.SDLAppController.model.globalProperties.vrHelpTitle, SDL.SDLAppController.model.globalProperties.vrHelp );
179 if (SDL.VRHelpListView.active) {
180 SDL.VRHelpListView.deactivate();
184 if (SDL.SDLAppController.model && !SDL.SDLModel.VRActive && SDL.SDLAppController.model.activeRequests.vrPerformInteraction) {
185 SDL.SDLController.vrInteractionResponse(SDL.SDLModel.resultCode['ABORTED']);
187 }.observes('SDL.SDLModel.VRActive', 'SDL.SDLModel.interactionData.vrHelp'),
190 * Handler for Help button in VR menu
191 * triggers helpPrompt on HMI
194 vrHelpAction: function() {
195 if (SDL.SDLModel.interactionData.helpPrompt) {
196 SDL.SDLModel.onPrompt(SDL.SDLModel.interactionData.helpPrompt);
197 } else if (SDL.SDLAppController.model && SDL.SDLAppController.model.globalProperties.helpPrompt.length) {
198 SDL.SDLModel.onPrompt(SDL.SDLAppController.model.globalProperties.helpPrompt);
203 * Notify SDLCore that TTS haas finished processing
207 TTSResponseHandler: function() {
209 if (FFW.TTS.requestId) {
210 if (FFW.TTS.aborted) {
211 FFW.TTS.sendError(SDL.SDLModel.resultCode["ABORTED"], FFW.TTS.requestId, "TTS.Speak", "TTS Speak request aborted");
213 FFW.TTS.sendTTSResult(SDL.SDLModel.resultCode["SUCCESS"], FFW.TTS.requestId, "TTS.Speak");
215 FFW.TTS.requestId = null;
216 FFW.TTS.aborted = false;
221 * Move VR list to right side when VRHelpList was activated
227 if (SDL.VRHelpListView.active || SDL.InteractionChoicesView.active) {
228 SDL.SDLModel.set('VRHelpListActivated', true);
230 SDL.SDLModel.set('VRHelpListActivated', false);
235 * Activate navigationApp method to set navigationApp data to controlls on main screen
237 navigationAppUpdate: function() {
238 SDL.BaseNavigationView.update(SDL.SDLAppController.model.appID);
242 * Default action for SoftButtons: closes window, popUp or clears
243 * applications screen
247 defaultActionSoftButton: function(element) {
249 switch (element.groupName) {
251 SDL.AlertPopUp.deactivate();
254 case "ScrollableMessage": {
255 SDL.ScrollableMessage.deactivate(true);
262 * SDL notification call function
263 * to notify that SDL Core should reset timeout for some method
265 onResetTimeout: function (appID, methodName) {
266 FFW.UI.onResetTimeout(appID, methodName);
269 * Action to show Voice Recognition PopUp
271 activateVRPopUp: function() {
273 SDL.SDLModel.toggleProperty('VRActive');
276 * Action for SoftButtons that closes popUp or window and opens
277 * applications screen
281 stealFocusSoftButton: function(element) {
283 switch (element.groupName) {
285 SDL.AlertPopUp.deactivate();
286 this.onActivateSDLApp(element);
289 case "ScrollableMessage": {
290 SDL.ScrollableMessage.deactivate();
291 this.onActivateSDLApp(element);
297 * Action for SoftButtons that clears popUps timer and it become visible
298 * all the time until user user closes it
302 keepContextSoftButton: function(element) {
304 switch (element.groupName) {
306 clearTimeout(SDL.AlertPopUp.timer);
307 SDL.AlertPopUp.timer = setTimeout(function() {
308 SDL.AlertPopUp.deactivate();
309 }, SDL.AlertPopUp.timeout);
310 this.onResetTimeout(element.appID, "UI.Alert");
313 case "ScrollableMessage": {
314 clearTimeout(SDL.ScrollableMessage.timer);
315 SDL.ScrollableMessage.timer = setTimeout(function() {
316 SDL.ScrollableMessage.deactivate();
317 }, SDL.ScrollableMessage.timeout);
318 this.onResetTimeout(element.appID, "UI.ScrollableMessage");
324 * Action for ClosePopUp request that triggers deactivate function from
327 closePopUp: function() {
329 if (SDL.AlertPopUp.active) {
330 SDL.AlertPopUp.deactivate();
332 if (SDL.AudioPassThruPopUp.active) {
333 SDL.AudioPassThruPopUp.deactivate();
334 this.performAudioPassThruResponse(SDL.SDLModel.resultCode["SUCCESS"]);
336 if (SDL.InteractionChoicesView.active) {
337 SDL.InteractionChoicesView.deactivate("ABORTED");
339 if (SDL.ScrollableMessage.active) {
340 SDL.ScrollableMessage.deactivate(true);
342 if (SDL.SliderView.active) {
343 SDL.SliderView.deactivate(true);
345 if (SDL.VRHelpListView.active) {
346 SDL.VRHelpListView.deactivate();
351 * Method to close InteractionChoices view
353 InteractionChoicesDeactivate: function() {
355 SDL.InteractionChoicesView.deactivate("ABORTED");
358 * Method to open Turn List view from TBT
361 * appID AppID of activated sdl application
363 tbtTurnList: function(appID) {
365 SDL.TBTTurnList.activate(appID);
368 * Method to sent notification with selected state of TBT Client State
372 tbtClientStateSelected: function(state) {
374 FFW.Navigation.onTBTClientState(state);
377 * Method to sent notification with selected reason of Exit Application
381 exitAppViewSelected: function(state) {
383 FFW.BasicCommunication.ExitAllApplications(state);
386 * Method to sent notification with selected reason of OnSystemRequest
390 systemRequestViewSelected: function(state) {
392 FFW.BasicCommunication.OnSystemRequest(state);
395 * Method to sent notification ABORTED for PerformInteractionChoise
397 interactionChoiseCloseResponse: function(appID, result, choiceID, manualTextEntry) {
399 FFW.UI.interactionResponse(SDL.SDLController.getApplicationModel(appID).activeRequests.uiPerformInteraction, result, choiceID, manualTextEntry);
400 SDL.SDLModel.set('interactionData.vrHelpTitle', null);
401 SDL.SDLModel.set('interactionData.vrHelp', null);
403 SDL.SDLController.getApplicationModel(appID).activeRequests.uiPerformInteraction = null;
406 * Method to sent notification ABORTED for VR PerformInteraction
408 vrInteractionResponse: function(result, choiceID) {
410 FFW.VR.interactionResponse(SDL.SDLAppController.model.activeRequests.vrPerformInteraction, result, choiceID);
412 SDL.SDLAppController.model.activeRequests.vrPerformInteraction = null;
414 SDL.SDLModel.set('VRActive', false);
417 * Method to sent notification for Alert
424 alertResponse: function(result, alertRequestID) {
426 FFW.UI.alertResponse(result, alertRequestID);
429 * Method to sent notification for Scrollable Message
436 scrollableMessageResponse: function(result, messageRequestId) {
438 if (result == SDL.SDLModel.resultCode['SUCCESS']) {
439 FFW.UI.sendUIResult(result,
441 'UI.ScrollableMessage');
443 FFW.UI.sendError(result,
445 'UI.ScrollableMessage',
446 "ScrollableMessage aborted!");
450 * Method to do necessary actions when user navigate throught the menu
452 userStateAction: function() {
453 if (SDL.ScrollableMessage.active) {
454 SDL.ScrollableMessage.deactivate(true);
458 * Method to sent notification for Slider
465 sliderResponse: function(result, sliderRequestId) {
467 FFW.UI.sendUIResult(result, sliderRequestId, 'UI.Slider');
470 * Method to call performAudioPassThruResponse with Result code
474 * element Button object
476 callPerformAudioPassThruPopUpResponse: function(element) {
478 this.performAudioPassThruResponse(element.responseResult);
481 * Method close PerformAudioPassThruPopUp and call response from UI RPC
487 performAudioPassThruResponse: function(result) {
489 SDL.SDLModel.set('AudioPassThruState', false);
490 FFW.UI.sendUIResult(result,
491 FFW.UI.performAudioPassThruRequestID,
492 "UI.PerformAudioPassThru");
495 * Method close PerformAudioPassThruPopUp and call error response from
496 * UI RPC back to SDLCore
501 callPerformAudioPassThruPopUpErrorResponse: function(element) {
503 SDL.SDLModel.set('AudioPassThruState', false);
504 FFW.UI.sendError(element.responseResult,
505 FFW.UI.performAudioPassThruRequestID,
506 "UI.PerformAudioPassThru",
507 "PerformAudioPassThru was not completed successfuly!");
510 * Method to set language for UI component with parameters sent from
513 onLanguageChangeUI: function() {
515 FFW.UI.OnLanguageChange(SDL.SDLModel.hmiUILanguage);
516 }.observes('SDL.SDLModel.hmiUILanguage'),
518 * Method to set language for TTS and VR components with parameters sent
519 * from SDLCore to UIRPC
521 onLanguageChangeTTSVR: function() {
523 FFW.TTS.OnLanguageChange(SDL.SDLModel.hmiTTSVRLanguage);
524 FFW.VR.OnLanguageChange(SDL.SDLModel.hmiTTSVRLanguage);
525 }.observes('SDL.SDLModel.hmiTTSVRLanguage'),
527 * Register application
534 registerApplication: function(params, applicationType) {
536 SDL.SDLModel.get('registeredApps')
537 .pushObject(this.applicationModels[applicationType].create( {
539 appName: params.appName,
540 deviceName: params.deviceName,
541 appType: params.appType
545 * Unregister application
550 unregisterApplication: function(appID) {
552 this.getApplicationModel(appID).VRCommands = [];
553 this.getApplicationModel(appID).onDeleteApplication(appID);
554 var len = SDL.SDLModel.VRCommands.length;
555 for (var i = len - 1; i >= 0; i--) {
556 if (SDL.SDLModel.VRCommands[i].appID == appID) {
557 SDL.SDLModel.VRCommands.splice(i, 1);
560 SDL.SDLAppController.set('model', null);
563 * SDL Driver Distraction ON/OFF switcher
565 selectDriverDistraction: function() {
567 if (SDL.SDLModel.driverDistractionState) {
568 FFW.UI.onDriverDistraction("DD_ON");
570 FFW.UI.onDriverDistraction("DD_OFF");
572 }.observes('SDL.SDLModel.driverDistractionState'),
575 * Ondisplay keyboard event handler
576 * Sends notification on SDL Core with changed value
578 onKeyboardChanges: function() {
579 if (null !== SDL.SDLModel.keyboardInputValue) {
581 var str = SDL.SDLModel.keyboardInputValue;
583 if (SDL.SDLAppController.model.globalProperties.keyboardProperties.keypressMode) {
584 switch (SDL.SDLAppController.model.globalProperties.keyboardProperties.keypressMode) {
585 case 'SINGLE_KEYPRESS':{
586 FFW.UI.OnKeyboardInput(str.charAt( str.length-1 ));
589 case 'QUEUE_KEYPRESS':{
592 case 'RESEND_CURRENT_ENTRY':{
594 FFW.UI.OnKeyboardInput(str, "KEYPRESS");
601 }.observes('SDL.SDLModel.keyboardInputValue'),
604 * Get application model
608 getApplicationModel: function(applicationId) {
610 return SDL.SDLModel.registeredApps.filterProperty('appID',
614 * Function returns ChangeDeviceView back to previous state
616 turnChangeDeviceViewBack: function() {
618 SDL.States.goToStates('info.apps');
621 * Enter screen vith list of devices application model
623 onGetDeviceList: function() {
625 SDL.States.goToStates('info.devicelist');
626 SDL.SDLModel.set('deviceSearchProgress', true);
629 * Send notification if device was choosed
634 onDeviceChoosed: function(element) {
636 SDL.SDLModel.set('CurrDeviceInfo.name', element.deviceName);
637 SDL.SDLModel.set('CurrDeviceInfo.id', element.id);
638 FFW.BasicCommunication.OnDeviceChosen(element.deviceName,
640 this.turnChangeDeviceViewBack();
643 * Method creates list of Application ID's Then call HMI method for
644 * display a list of Applications
648 onGetAppList: function(appList) {
650 SDL.SDLModel.onGetAppList(appList);
653 * Method call's request to get list of applications
655 findNewApps: function() {
657 FFW.BasicCommunication.OnFindApplications();
660 * Method activates selected registered application
664 onActivateSDLApp: function(element) {
666 FFW.BasicCommunication.OnAppActivated(element.appID);
669 * Method sent custom softButtons pressed and event status to RPC
673 onSoftButtonActionUpCustom: function(element) {
675 if (element.time > 0) {
676 FFW.Buttons.buttonEventCustom("CUSTOM_BUTTON",
678 element.softButtonID);
680 FFW.Buttons.buttonEventCustom("CUSTOM_BUTTON",
682 element.softButtonID);
683 FFW.Buttons.buttonPressedCustom("CUSTOM_BUTTON",
685 element.softButtonID);
687 clearTimeout(element.timer);
691 * Method sent custom softButtons pressed and event status to RPC
695 onSoftButtonActionDownCustom: function(element) {
697 FFW.Buttons.buttonEventCustom("CUSTOM_BUTTON",
699 element.softButtonID);
701 element.timer = setTimeout(function() {
703 FFW.Buttons.buttonPressedCustom("CUSTOM_BUTTON",
705 element.softButtonID);
710 * Method sent softButtons pressed and event status to RPC
715 onSoftButtonActionUp: function(element) {
717 if (element.time > 0) {
718 FFW.Buttons.buttonEvent(element.presetName, "BUTTONUP");
720 FFW.Buttons.buttonEvent(element.presetName, "BUTTONUP");
721 FFW.Buttons.buttonPressed(element.presetName, "SHORT");
723 clearTimeout(element.timer);
727 * Method sent softButtons Ok pressed and event status to RPC
731 onSoftButtonOkActionDown: function(name) {
733 FFW.Buttons.buttonEvent(name, "BUTTONDOWN");
736 * Method sent softButton OK pressed and event status to RPC
740 onSoftButtonOkActionUp: function(name) {
742 FFW.Buttons.buttonEvent(name, "BUTTONUP");
743 FFW.Buttons.buttonPressed(name, "SHORT");
744 if (SDL.SDLAppController.model) {
745 SDL.SDLAppController.model.set('isPlaying',
746 !SDL.SDLAppController.model.isPlaying);
750 * Method sent softButtons pressed and event status to RPC
755 onSoftButtonActionDown: function(element) {
757 FFW.Buttons.buttonEvent(element.presetName, "BUTTONDOWN");
759 element.timer = setTimeout(function() {
761 FFW.Buttons.buttonPressed(element.presetName, "LONG");
766 * Send system context
768 onSystemContextChange: function() {
770 FFW.UI.OnSystemContext(this.get('sysContext'));