Skip to content

Commit e5b1e35

Browse files
fstanisMarkusBordihn
authored andcommitted
Disable Joy Demo when connecting to AIY (#207)
* Add warning about Joy Demo * Disable Joy Demo when connecting * add default timeout
1 parent 59ce036 commit e5b1e35

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

src/mode/boards/aiy/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ cwc.mode.aiy.Connection.prototype.connectInteractive = async function(host) {
150150
cwc.mode.aiy.Connection.prototype.connect = async function(host) {
151151
const url = this.buildSocketUrl(host);
152152
await this.api_.connect(url);
153+
await this.api_.terminateJoyDemo();
153154
this.database_.put('host', host);
154155
};
155156

src/protocol/boards/aiy/api.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ cwc.protocol.aiy.Api = function() {
4141
/** @private {!boolean} */
4242
this.connected_ = false;
4343

44+
/** @private {!boolean} */
45+
this.quiet_ = false;
46+
4447
/** @private {!string} */
4548
this.url_ = '';
4649
};
@@ -154,6 +157,27 @@ cwc.protocol.aiy.Api.prototype.sendRun = function(code, args) {
154157
};
155158

156159

160+
/**
161+
* @param {!number} timeout
162+
* @return {!Promise}
163+
* @export
164+
*/
165+
cwc.protocol.aiy.Api.prototype.terminateJoyDemo = function(timeout = 2000) {
166+
return new Promise((resolve) => {
167+
this.quiet_ = true;
168+
this.send_(JSON.stringify({
169+
'type': 'run',
170+
'args': ['sudo', 'systemctl', 'stop', 'joy_detection_demo.service'],
171+
}));
172+
setTimeout(() => {
173+
this.quiet_ = false;
174+
this.disconnect();
175+
resolve(this.reconnect());
176+
}, timeout);
177+
});
178+
};
179+
180+
157181
/**
158182
* @param {!number} signum
159183
* @export
@@ -200,7 +224,7 @@ cwc.protocol.aiy.Api.prototype.parseMessage_ = function(messageData) {
200224
* @private
201225
*/
202226
cwc.protocol.aiy.Api.prototype.handleMessage_ = function(messageData) {
203-
if (!messageData) {
227+
if (!messageData || this.quiet_) {
204228
return;
205229
}
206230

src/ui/select_screen/advanced/aiy/aiy.soy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454

5555
{call cwc.soy.SelectScreenTemplate.fileCard data="all"}
5656
{param title: 'Vision Kit' /}
57-
{param text: 'Start building for the AIY Voice Kit' /}
57+
{param text: 'Start building for the AIY Vision Kit' /}
58+
{param warning: 'Please note that if you connect to the AIY kit, joydemo will be disabled automatically.' /}
5859
{param opt_link_text: 'Create new project' /}
5960
{param mode: 'aiy' /}
6061
{param opt_color_class: 'bg-orange' /}

src/ui/select_screen/select_screen_templates.soy

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@
118118
{@param title: string}
119119
{@param? id: string}
120120
{@param? hidden: bool}
121+
{@param? warning: string}
121122
{@param? opt_link_text: string}
122123
{@param? opt_color_class: string}
123124
{@param? opt_icon: string}
124125
{@param? opt_image: string}
125126

127+
126128
{call .dataActionDiv_ data="all"}
127129
{param classes: 'cwc-file-card mdl-card mdl-shadow--2dp' /}
128130
{param content kind="html"}
@@ -140,11 +142,17 @@
140142
<i class="icon_auto">insert_drive_file</i>
141143
</div>
142144
{/if}
143-
</div>
145+
</div>
144146
</div>
145147
<div class="mdl-card__supporting-text">
146148
{msg desc=""}{$text}{/msg}
147149
</div>
150+
{if $warning}
151+
<div class="mdl-card__supporting-text mdl-color-text--red">
152+
{msg desc=""}{$warning}{/msg}
153+
</div>
154+
{/if}
155+
148156
<div class="mdl-card__actions mdl-card--border"{if $id} id="{$id}"{/if}>
149157
<a class="mdl-button mdl-button--colored mdl-js-button mdl-js-ripple-effect">
150158
{if $opt_link_text}
@@ -340,7 +348,7 @@
340348
{let $tab_id: 'select-screen-tab-' + $id /}
341349
{let $isEnabled: isNonnull($modules[$module]) and $modules[$module] == true or not isNonnull($modules[$module]) /}
342350

343-
<a href="#{$tab_id}" id="{$tab_id}-link" class="mdl-tabs__tab
351+
<a href="#{$tab_id}" id="{$tab_id}-link" class="mdl-tabs__tab
344352
{if $icon} icon_24px_raw{/if}
345353
{if $active} is-active{/if}
346354
{if not $isEnabled} hidden{/if}">{$name}</a>

0 commit comments

Comments
 (0)