|
53 | 53 | .setLanguageDesired(SDL.rpc.enums.Language.EN_US)
|
54 | 54 | .setHmiDisplayLanguageDesired(SDL.rpc.enums.Language.EN_US)
|
55 | 55 | .setAppTypes([
|
56 |
| - SDL.rpc.enums.AppHMIType.DEFAULT, |
| 56 | + SDL.rpc.enums.AppHMIType.MEDIA, |
57 | 57 | ])
|
58 | 58 | .setTransportConfig(new SDL.transport.WebSocketClientConfig('ws://localhost', 5050))
|
59 | 59 | .setAppIcon(file)
|
|
98 | 98 |
|
99 | 99 | this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
|
100 | 100 | this._sdlManager.start();
|
| 101 | + this._isButtonSubscriptionRequested = false; |
101 | 102 | }
|
102 | 103 |
|
103 | 104 | async _onConnected () {
|
|
123 | 124 | screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
|
124 | 125 | screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
|
125 | 126 | .setFilePath(this._filePath));
|
| 127 | + screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration() |
| 128 | + .setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA)); |
126 | 129 | }
|
127 | 130 |
|
128 | 131 | async _onHmiStatusListener (onHmiStatus) {
|
|
131 | 134 |
|
132 | 135 | // wait for the FULL state for more functionality
|
133 | 136 | if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
|
| 137 | + const screenManager = this._sdlManager.getScreenManager(); |
| 138 | + const isRpcAllowed = (rpc) => { |
| 139 | + return this._permissionManager && |
| 140 | + this._permissionManager.isRpcAllowed(rpc); |
| 141 | + }; |
| 142 | + |
| 143 | + if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) { |
| 144 | + const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) { |
| 145 | + return capability.getNameParam(); |
| 146 | + }); |
| 147 | + |
| 148 | + // add button listeners |
| 149 | + const ButtonName = SDL.rpc.enums.ButtonName; |
| 150 | + const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, |
| 151 | + ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8, |
| 152 | + ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT, |
| 153 | + ButtonName.TUNEUP, ButtonName.TUNEDOWN]; |
| 154 | + |
| 155 | + |
| 156 | + for (const buttonName of buttonNames) { |
| 157 | + if (availableButtons.indexOf(buttonName) !== -1) { |
| 158 | + console.log('Subscribing to', buttonName); |
| 159 | + await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { |
| 160 | + console.error(err); |
| 161 | + }); |
| 162 | + } else { |
| 163 | + console.log('No capability found for button', buttonName); |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + this._isButtonSubscriptionRequested = true; |
| 168 | + } |
| 169 | + |
134 | 170 | const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
|
135 | 171 | .setFilePath(this._filePath);
|
136 | 172 |
|
|
153 | 189 | ];
|
154 | 190 |
|
155 | 191 | // set the softbuttons now and rotate through the states of the first softbutton
|
156 |
| - const screenManager = this._sdlManager.getScreenManager(); |
157 | 192 | await screenManager.setSoftButtonObjects(softButtonObjects);
|
158 | 193 |
|
159 | 194 | await this._sleep(2000);
|
|
164 | 199 |
|
165 | 200 | const count = 3;
|
166 | 201 | for (let i = 0; i < count; i++) {
|
167 |
| - const showCountdown = new SDL.rpc.messages.Show(); |
168 |
| - showCountdown.setMainField1(`Exiting in ${(count - i).toString()}`) |
169 |
| - .setMainField2('') |
170 |
| - .setMainField3(''); |
171 |
| - |
172 |
| - this._sdlManager.sendRpcResolve(showCountdown); // don't wait for a response |
| 202 | + screenManager.setTextField1(`Exiting in ${(count - i).toString()}`) |
| 203 | + .setTextField2('') |
| 204 | + .setTextField3(''); |
173 | 205 |
|
174 | 206 | await this._sleep();
|
175 | 207 | }
|
|
187 | 219 | });
|
188 | 220 | }
|
189 | 221 |
|
| 222 | + _onButtonListener (buttonName, onButton) { |
| 223 | + if (onButton instanceof SDL.rpc.messages.OnButtonPress) { |
| 224 | + this._sdlManager.getScreenManager().setTextField1(`${buttonName} pressed`); |
| 225 | + } else if (onButton instanceof SDL.rpc.messages.OnButtonEvent) { |
| 226 | + this._sdlManager.getScreenManager().setTextField2(`${buttonName} ${onButton.getButtonEventMode()}`); |
| 227 | + } |
| 228 | + } |
| 229 | + |
190 | 230 | _logPermissions () {
|
191 | 231 | if (this._permissionManager) {
|
192 | 232 | console.log(`Show RPC allowed: ${this._permissionManager.isRpcAllowed(SDL.rpc.enums.FunctionID.Show)}`);
|
|
0 commit comments