Skip to content

Commit 0c92f6f

Browse files
committed
Improved existing mBot Ranger implementation.
Added Bluetooth web warning and error infobar for unsupported platforms.
1 parent d1024b8 commit 0c92f6f

File tree

42 files changed

+390
-1433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+390
-1433
lines changed

locales/deu/select_screen.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @fileoverview Translation file for the Select screen (german).
3+
*
4+
* @license Copyright 2018 The Coding with Chrome Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author [email protected] (Markus Bordihn)
19+
*/
20+
/* eslint-disable max-len */
21+
Locales['deu']['SELECT_SCREEN'] = {
22+
'LOAD_FILE': 'Load {$title}',
23+
'BLUETOOTH_WEB_NOT_AVAILABLE': 'Erforderliche Web-Bluetooth-Unterstützung ist nicht verfügbar.',
24+
'BLUETOOTH_WEB_LIGHT': 'Erforderliche Web-Bluetooth-Unterstützung ist derzeit auf Windows-Betriebssystemen eingeschränkt.',
25+
};
26+
27+
28+
Locales['deu']['SELECT_SCREEN_NORMAL'] = {
29+
'TITLE': 'Block Coding',
30+
'DESCRIPTION': 'Block basierte Programmierung',
31+
'BLOCKLY': 'Blockly',
32+
'BLOCKLY_ACTION': 'Verwende Blockly',
33+
'BLOCKLY_TEXT': 'Verwende Blockly, um mit Hilfe von Codeblöcken ein Programm zu erstellen.',
34+
'GAME': 'Games',
35+
'GAME_ACTION': 'Ein Spiel erstellen',
36+
'GAME_TEXT': 'Erstelle ein einfaches Spiele durch das ziehen und plazieren von Codeblöcken',
37+
'ROBOTS': 'Roboter',
38+
'ROBOTS_ACTION': 'Kontroliere Roboter',
39+
'ROBOTS_TEXT': 'Kontrolliere einen echten oder virtuellen Roboter mit Codeblöcke',
40+
};

locales/deu/translation.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
Object.assign(Locales['deu'], {
2323
'All': 'Alle',
2424
'Audio': 'Audio',
25-
'Block Coding': 'Block basierte Programmierung',
2625
'Blockly Prompt': 'Blockly Aufforderung',
2726
'Blockly file': 'Blockly Datei',
2827
'Bluetooth is disabled!': 'Bluetooth ist deaktiviert!',
@@ -34,10 +33,8 @@ Object.assign(Locales['deu'], {
3433
'Colour': 'Farbe',
3534
'Connect Bluetooth device...': 'Verbinde ein Bluetooth Gerät...',
3635
'Connect serial device...': 'Verbinde ein serieles Gerät...',
37-
'Control real or on-screen robots with Blockly': 'Kontrollieren Sie einen echte oder virtuelle Roboter mit Blockly',
3836
'Create Game with name': 'Erstelle ein Spiel mit den Namen',
3937
'Create new variable...': 'Lege eine neue Variable an...',
40-
'Create simple games by dragging and dropping code blocks': 'Erstellen ein einfache Spiele durch das ziehen und plazieren von Codeblöcken',
4138
'Create your own game': 'Erstelle dein eigenes Spiel',
4239
'Create your own games...': 'Erstelle dein eigenenes Spiel...',
4340
'Create': 'Anlegen',
@@ -105,7 +102,6 @@ Object.assign(Locales['deu'], {
105102
'Start a file': 'Start eine neue Datei',
106103
'Start a new project': 'Starte ein neues Projekt',
107104
'Start building new code': 'Neuen Code aufbauen',
108-
'Start creating games': 'Ein Spiel erstellen',
109105
'Switch from one game state to another game state': 'Wechsel von einem Spiel Modus zum anderen Spielmodus',
110106
'Switch to Blockly': 'Wechsel zu Blockly',
111107
'Switch to Editor': 'Wechsel zum Editor',
@@ -123,7 +119,6 @@ Object.assign(Locales['deu'], {
123119
'Update': 'Aktualisieren',
124120
'Upload file': 'Datei hochladen',
125121
'Upload': 'Hochladen',
126-
'Use Blockly to build code by dragging and dropping code blocks': 'Verwenden Sie Blockly, um Code zu erstellen, indem Sie Codeblöcke reinziehen und ablegen',
127122
'Variables': 'Variablen',
128123
'World wrap sprite': 'Welt wrap Sprite',
129124
'World': 'Welt',

locales/eng/select_screen.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @fileoverview Translation file for the Select screen (english).
3+
*
4+
* @license Copyright 2018 The Coding with Chrome Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* @author [email protected] (Markus Bordihn)
19+
*/
20+
/* eslint-disable max-len */
21+
Locales['eng']['SELECT_SCREEN'] = {
22+
'LOAD_FILE': 'Load {$title}',
23+
'BLUETOOTH_WEB_NOT_AVAILABLE': 'Required Web Bluetooth support is not available.',
24+
'BLUETOOTH_WEB_LIGHT': 'Required Web Bluetooth support is currently limited on Windows OS.',
25+
};
26+
27+
28+
Locales['eng']['SELECT_SCREEN_NORMAL'] = {
29+
'TITLE': 'Block Coding',
30+
'DESCRIPTION': 'Block-based programming',
31+
'BLOCKLY': 'Blockly',
32+
'BLOCKLY_ACTION': 'Go Blockly',
33+
'BLOCKLY_TEXT': 'Use Blockly to build code by dragging and dropping code blocks',
34+
'GAME': 'Games',
35+
'GAME_ACTION': 'Start creating games',
36+
'GAME_TEXT': 'Create simple games by dragging and dropping code blocks',
37+
'ROBOTS': 'Robots',
38+
'ROBOTS_ACTION': 'Control Robots',
39+
'ROBOTS_TEXT': 'Control real or on-screen robots with Blockly',
40+
};

locales/eng/translation.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Object.assign(Locales['eng'], {
3131
'Begin a new program to drive a mBot or an on-screen robot with Blockly': 'Begin a new program to drive a mBot or an on-screen robot with Blockly',
3232
'Begin a new program to drive a mBot with Blockly': 'Begin a new program to drive a mBot with Blockly',
3333
'Begin a new program to drive an EV3 or an on-screen robot with Blockly': 'Begin a new program to drive an EV3 or an on-screen robot with Blockly',
34-
'Block Coding': 'Block Coding',
3534
'Blockly file': 'Blockly file',
3635
'Blocks': 'Blocks',
3736
'Build software with text-based programming languages': 'Build software with text-based programming languages',
@@ -71,7 +70,6 @@ Object.assign(Locales['eng'], {
7170
'Control an EV3 with Blocks': 'Control an EV3 with Blocks',
7271
'Control an EV3 with JavaScript': 'Control an EV3 with JavaScript',
7372
'Control an mBot by assembling Blockly Blocks': 'Control an mBot by assembling Blockly Blocks',
74-
'Control real or on-screen robots with Blockly': 'Control real or on-screen robots with Blockly',
7573
'Control real or virtual robots': 'Control real or virtual robots',
7674
'Control the EV3 or a virtual robot with JavaScript': 'Control the EV3 or a virtual robot with JavaScript',
7775
'Control the Sphero or a virtual robot with JavaScript': 'Control the Sphero or a virtual robot with JavaScript',
@@ -82,7 +80,6 @@ Object.assign(Locales['eng'], {
8280
'Create empty project': 'Create empty project',
8381
'Create games with the Phaser framework': 'Create games with the Phaser framework',
8482
'Create new project': 'Create new project',
85-
'Create simple games by dragging and dropping code blocks': 'Create simple games by dragging and dropping code blocks',
8683
'Create some music': 'Create some music',
8784
'Create website code': 'Create website code',
8885
'Create your own games...': 'Create your own games...',
@@ -127,9 +124,7 @@ Object.assign(Locales['eng'], {
127124
'Get the current value of the Ultrasonic sensor': 'Get the current value of the Ultrasonic sensor',
128125
'Get the current value of the color sensor': 'Get the current value of the color sensor',
129126
'Get the current value of the touch sensor': 'Get the current value of the touch sensor',
130-
'Go Blockly': 'Go Blockly',
131127
'Go Coding ': 'Go Coding ',
132-
'Go Robots': 'Go Robots',
133128
'Go Simple': 'Go Simple',
134129
'Go Web': 'Go Web',
135130
'Guess number': 'Guess number',
@@ -284,7 +279,6 @@ Object.assign(Locales['eng'], {
284279
'Start an empty Sphero project': 'Start an empty Sphero project',
285280
'Start an empty pencil code project': 'Start an empty pencil code project',
286281
'Start building new code': 'Start building new code',
287-
'Start creating games': 'Start creating games',
288282
'Start drawing': 'Start drawing',
289283
'Start learning JavaScript with video tutorials on YouTube': 'Start learning JavaScript with video tutorials on YouTube',
290284
'Stop all motors immediately or after the last command has finished': 'Stop all motors immediately or after the last command has finished',
@@ -328,7 +322,6 @@ Object.assign(Locales['eng'], {
328322
'Undo last change': 'Undo last change',
329323
'Unsaved changes for Game Engine': 'Unsaved changes for Game Engine',
330324
'Unsaved changes for basic: Text loop': 'Unsaved changes for basic: Text loop',
331-
'Use Blockly to build code by dragging and dropping code blocks': 'Use Blockly to build code by dragging and dropping code blocks',
332325
'Use CoffeeScript': 'Use CoffeeScript',
333326
'Use EV3 Robot': 'Use EV3 Robot',
334327
'Use HTML5': 'Use HTML5',

src/blocks/makeblock/mbot/javascript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Blockly.JavaScript['mbot_rgb'] = function(block) {
222222
let green = colour >> 8 & 0xFF;
223223
let blue = colour & 0xFF;
224224
return 'mBot.setRGBLED(' + red + ', ' + green + ', ' + blue + ', ' +
225-
position + ', 100);\n';
225+
position + ', 50);\n';
226226
};
227227

228228

src/frameworks/makeblock/mbot/mbot.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,31 @@ cwc.framework.makeblock.MBot.prototype.setLEDColor =
8484
* @param {number} red 0-255
8585
* @param {number} green 0-255
8686
* @param {number} blue 0-255
87-
* @param {string=} opt_position
88-
* position of the on-board LED: 0-both, 1-left, 2-right
89-
* @param {void=} opt_delay
87+
* @param {string=} index On-board LED: 0-both, 1-left, 2-right
88+
* @param {void=} delay
9089
* @export
9190
*/
92-
cwc.framework.makeblock.MBot.prototype.setRGBLED = function(red, green, blue,
93-
opt_position, opt_delay) {
91+
cwc.framework.makeblock.MBot.prototype.setRGBLED = function(
92+
red, green, blue, index, delay) {
9493
this.messenger_.send('setRGBLED', {
9594
'red': red,
9695
'green': green,
9796
'blue': blue,
98-
'position': opt_position || 0}, opt_delay);
97+
'index': index || 0}, delay);
9998
};
10099

101100

102101
/**
103102
* Plays a tone through the buzzer.
104103
* @param {number} frequency frequency of the note
105104
* @param {number} duration duration in milliseconds
106-
* @param {number=} opt_delay
105+
* @param {number=} delay
107106
* @export
108107
*/
109108
cwc.framework.makeblock.MBot.prototype.playTone = function(frequency, duration,
110-
opt_delay) {
109+
delay) {
111110
this.messenger_.send('playTone', {
112-
'frequency': frequency, 'duration': duration}, opt_delay);
111+
'frequency': frequency, 'duration': duration}, delay);
113112
};
114113

115114

@@ -231,11 +230,11 @@ cwc.framework.makeblock.MBot.prototype.wait = function(time) {
231230

232231
/**
233232
* Stop the mBot
234-
* @param {number=} opt_delay in msec
233+
* @param {number=} delay in msec
235234
* @export
236235
*/
237-
cwc.framework.makeblock.MBot.prototype.stop = function(opt_delay) {
238-
this.messenger_.send('stop', null, opt_delay);
236+
cwc.framework.makeblock.MBot.prototype.stop = function(delay) {
237+
this.messenger_.send('stop', null, delay);
239238
};
240239

241240

src/mode/makeblock/mbot/connection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ cwc.mode.makeblock.mBot.Connection = function(helper) {
6363
this.events_ = new cwc.utils.Events(this.name);
6464

6565
/** @private {!cwc.lib.protocol.bluetoothChrome.profile.Device} */
66-
this.device_ = BluetoothProfile.MAKEBLOCK_MBOT_RANGER;
66+
this.device_ = BluetoothProfile.MAKEBLOCK_MBOT;
6767
};
6868

6969

7070
/**
71-
* Connects the mbot unit.
71+
* Connects the mBot unit.
7272
* @export
7373
*/
7474
cwc.mode.makeblock.mBot.Connection.prototype.init = function() {
7575
this.handleConnecting_({
76-
'data': 'Connecting Sphero 2.0',
76+
'data': 'Searching for ' + this.device_.name,
7777
'source': 1,
7878
});
7979

@@ -194,7 +194,7 @@ cwc.mode.makeblock.mBot.Connection.prototype.cleanUp = function() {
194194
cwc.mode.makeblock.mBot.Connection.prototype.handleConnecting_ = function(e) {
195195
let message = e.data;
196196
let step = e.source;
197-
let title = 'Connecting' + this.device_.name;
197+
let title = 'Connecting ' + this.device_.name;
198198
let connectScreenInstance = this.helper.getInstance('connectScreen');
199199
connectScreenInstance.showConnectingStep(title, message, step);
200200
};

src/mode/makeblock/mbot_ranger/connection.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@
1919
*/
2020
goog.provide('cwc.mode.makeblock.mBotRanger.Connection');
2121

22-
goog.require('cwc.protocol.makeblock.mBotRanger.Api');
22+
goog.require('cwc.lib.protocol.makeblock.mBotRanger.Api');
23+
goog.require('cwc.lib.protocol.bluetoothChrome.profile.Device');
24+
goog.require('cwc.lib.protocol.makeblock.mBotRanger.Events');
2325
goog.require('cwc.utils.Events');
2426

2527
goog.require('goog.Timer');
2628

2729

30+
goog.scope(function() {
31+
const Api = goog.module.get('cwc.lib.protocol.makeblock.mBotRanger.Api');
32+
const BluetoothProfile =
33+
goog.module.get('cwc.lib.protocol.bluetoothChrome.profile.Device');
34+
const Events = goog.module.get('cwc.lib.protocol.makeblock.mBotRanger.Events');
35+
2836
/**
2937
* @constructor
3038
* @param {!cwc.utils.Helper} helper
@@ -39,32 +47,41 @@ cwc.mode.makeblock.mBotRanger.Connection = function(helper) {
3947
/** @type {!cwc.utils.Helper} */
4048
this.helper = helper;
4149

42-
/** @type {!cwc.protocol.makeblock.mBotRanger.Api} */
43-
this.api_ = new cwc.protocol.makeblock.mBotRanger.Api();
44-
4550
/** @type {goog.Timer} */
4651
this.connectMonitor = null;
4752

4853
/** @type {number} */
4954
this.connectMonitorInterval = 5000;
5055

56+
/** @type {!cwc.protocol.makeblock.mBotRanger.Api} */
57+
this.api_ = new Api();
58+
59+
/** @private {!goog.events.EventTarget} */
60+
this.apiEvents_ = this.api_.getEventTarget();
61+
5162
/** @private {!cwc.utils.Events} */
5263
this.events_ = new cwc.utils.Events(this.name);
64+
65+
/** @private {!cwc.lib.protocol.bluetoothChrome.profile.Device} */
66+
this.device_ = BluetoothProfile.MAKEBLOCK_MBOT_RANGER;
5367
};
5468

5569

5670
/**
57-
* Connects the mbot unit.
71+
* Connects the mBot Ranger unit.
5872
* @export
5973
*/
6074
cwc.mode.makeblock.mBotRanger.Connection.prototype.init = function() {
61-
if (!this.connectMonitor) {
62-
this.connectMonitor = new goog.Timer(this.connectMonitorInterval);
63-
this.events_.listen(this.connectMonitor, goog.Timer.TICK,
64-
this.connect.bind(this));
75+
this.handleConnecting_({
76+
'data': 'Searching for ' + this.device_.name,
77+
'source': 1,
78+
});
79+
80+
if (this.apiEvents_) {
81+
this.events_.listen(this.apiEvents_,
82+
Events.Type.CONNECT, this.handleConnecting_.bind(this));
6583
}
6684

67-
// Unload event
6885
let layoutInstance = this.helper.getInstance('layout');
6986
if (layoutInstance) {
7087
this.events_.listen(layoutInstance.getEventTarget(),
@@ -78,13 +95,19 @@ cwc.mode.makeblock.mBotRanger.Connection.prototype.init = function() {
7895
false, this);
7996
}
8097

98+
if (!this.connectMonitor) {
99+
this.connectMonitor = new goog.Timer(this.connectMonitorInterval);
100+
this.events_.listen(this.connectMonitor, goog.Timer.TICK,
101+
this.connect.bind(this));
102+
}
103+
81104
this.connectMonitor.start();
82105
this.connect();
83106
};
84107

85108

86109
/**
87-
* Connects the mbot ball.
110+
* Connects the mBot Ranger robot.
88111
* @param {Event=} opt_event
89112
* @export
90113
*/
@@ -95,12 +118,10 @@ cwc.mode.makeblock.mBotRanger.Connection.prototype.connect = function(
95118
return;
96119
}
97120
if (!this.isConnected()) {
98-
bluetoothInstance.autoConnectDevice(this.autoConnectName, function(device) {
99-
if (device) {
100-
this.api_.connect(device);
101-
}
102-
}.bind(this));
121+
bluetoothInstance.autoConnectDevice(this.autoConnectName,
122+
this.api_.connect.bind(this.api_));
103123
}
124+
this.api_.monitor(true);
104125
};
105126

106127

@@ -169,6 +190,20 @@ cwc.mode.makeblock.mBotRanger.Connection.prototype.cleanUp = function() {
169190
};
170191

171192

193+
/**
194+
* @param {Event|Object} e
195+
* @private
196+
*/
197+
cwc.mode.makeblock.mBotRanger.Connection.prototype.handleConnecting_ =
198+
function(e) {
199+
let message = e.data;
200+
let step = e.source;
201+
let title = 'Connecting ' + this.device_.name;
202+
let connectScreenInstance = this.helper.getInstance('connectScreen');
203+
connectScreenInstance.showConnectingStep(title, message, step);
204+
};
205+
206+
172207
/**
173208
* @param {Event|Object} e
174209
* @private
@@ -179,3 +214,4 @@ cwc.mode.makeblock.mBotRanger.Connection.prototype.handlePreviewStatus_ =
179214
this.stop();
180215
}
181216
};
217+
});

0 commit comments

Comments
 (0)