Skip to content

Commit 0b1a468

Browse files
committed
Added flash LED button for Sphero integration.
1 parent 7962b82 commit 0b1a468

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

src/mode/lego/ev3/panel/control/control.soy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{@param prefix: string}
2828

2929
<div id="{$prefix}control">
30-
Use the buttons belows or the keyboard to control the EV3 manual.<br>
30+
Use the buttons belows, the cursor keys or an gamepad to control the EV3 manual.<br>
3131
<div id="{$prefix}buttons-body">
3232
<div id="{$prefix}buttons" class="icon_gamepad" title="Moves the robot.">
3333
games

src/mode/sphero/classic/panel/control/control.gss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
padding-bottom: 10px;
2626
}
2727

28-
#{$prefix}sphero-classic-control-buttons:first-child {
29-
padding-left: 3px;
28+
#{$prefix}sphero-classic-control-commands {
29+
padding: 5px;
30+
margin-left: 50px;
3031
}
3132

32-
#{$prefix}sphero-classic-control-system-buttons > div {
33-
padding: 10px;
33+
#{$prefix}sphero-classic-control-commands > .icon_button {
34+
padding: 5px;
3435
}

src/mode/sphero/classic/panel/control/control.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ cwc.mode.sphero.classic.Control.prototype.addEventHandler_ = function() {
112112
this.api.exec('roll', {'speed': 50, 'heading': 90});
113113
});
114114

115+
// Flash
116+
this.events_.listen('flash', goog.events.EventType.CLICK, function() {
117+
this.api.exec('setRGB', {'blue': 255});
118+
this.api.exec('setRGB', {'red': 255});
119+
this.api.exec('setRGB', {'blue': 255});
120+
this.api.exec('setRGB', {'red': 255});
121+
this.api.exec('setRGB', {'blue': 255});
122+
this.api.exec('setRGB');
123+
});
124+
115125
// Stop
116126
this.events_.listen('stop', goog.events.EventType.CLICK, function() {
117127
this.connection.stop();

src/mode/sphero/classic/panel/control/control.soy

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@
2727
{@param prefix: string}
2828

2929
<div id="{$prefix}body">
30-
Use the buttons belows or the keyboard to control the Sphero manual.<br>
30+
Use the buttons belows, the cursor keys or an gamepad to control the Sphero manual.<br>
3131

32-
<div id="{$prefix}control-buttons">
32+
<div id="{$prefix}buttons">
3333
<div id="{$prefix}move-left" class="icon_36px icon_button">keyboard_arrow_left</div>
3434
<div id="{$prefix}move-forward" class="icon_36px icon_button">keyboard_arrow_up</div>
3535
<div id="{$prefix}move-backward" class="icon_36px icon_button">keyboard_arrow_down</div>
3636
<div id="{$prefix}move-right" class="icon_36px icon_button">keyboard_arrow_right</div>
3737
</div>
3838

39-
<div id="{$prefix}control-commands">
39+
<div id="{$prefix}commands">
40+
<div id="{$prefix}flash" class="icon_36px icon_button">flare</div>
41+
<div class="mdl-tooltip" for="{$prefix}flash">
42+
Let the connected unit flash.
43+
</div>
4044
<div id="{$prefix}sleep" class="icon_36px icon_button">local_hotel</div>
4145
<div class="mdl-tooltip" for="{$prefix}sleep">
4246
Puts the connected unit to sleep.

src/protocol/robots/sphero/v1/api.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323
goog.provide('cwc.protocol.sphero.v1.Api');
2424

25+
goog.require('cwc.lib.protocol.bluetoothWeb.Profile');
2526
goog.require('cwc.protocol.sphero.v1.CallbackType');
2627
goog.require('cwc.protocol.sphero.v1.Events');
2728
goog.require('cwc.protocol.sphero.v1.Handler');
@@ -35,6 +36,10 @@ goog.require('cwc.utils.StreamReader');
3536
goog.require('goog.events.EventTarget');
3637

3738

39+
goog.scope(function() {
40+
const BluetoothProfile =
41+
goog.module.get('cwc.lib.protocol.bluetoothWeb.Profile');
42+
3843
/**
3944
* @constructor
4045
* @struct
@@ -74,6 +79,9 @@ cwc.protocol.sphero.v1.Api = function() {
7479
/** @private {number} */
7580
this.locationSpeed_ = 0;
7681

82+
/** @private {!Object} */
83+
this.profile_ = BluetoothProfile.Characteristic.SPHERO.spheroBLE;
84+
7785
/** @private {!goog.events.EventTarget} */
7886
this.eventTarget_ = new goog.events.EventTarget();
7987

@@ -108,22 +116,21 @@ cwc.protocol.sphero.v1.Api.prototype.connect = function(device) {
108116

109117
// Enable Developer mode.
110118
this.device.sendRaw(
111-
new TextEncoder('utf-8').encode('011i3'),
112-
'22bb746f-2bbd-7554-2d6f-726568705327', () => {
119+
new TextEncoder('utf-8').encode('011i3'), this.profile_.antiDOS, () => {
113120
this.eventTarget_.dispatchEvent(cwc.protocol.sphero.v1.Events.connect(
114121
'Enable developer mode ...', 2));
115122
});
116123

117124
// Power on device.
118125
this.device.sendRaw(
119-
new Uint8Array([0x07]), '22bb746f-2bb2-7554-2d6f-726568705327', () => {
126+
new Uint8Array([0x07]), this.profile_.txPower, () => {
120127
this.eventTarget_.dispatchEvent(cwc.protocol.sphero.v1.Events.connect(
121128
'Power on device. Waiting until device wakes up ...', 2));
122129
});
123130

124131
// Wakeup device.
125132
this.device.sendRaw(
126-
new Uint8Array([0x01]), '22bb746f-2bbf-7554-2d6f-726568705327', () => {
133+
new Uint8Array([0x01]), this.profile_.wake, () => {
127134
this.prepare();
128135
this.runTest();
129136
this.eventTarget_.dispatchEvent(cwc.protocol.sphero.v1.Events.connect(
@@ -397,3 +404,4 @@ cwc.protocol.sphero.v1.Api.prototype.verifiyChecksum_ = function(buffer,
397404

398405
return (checksum === (bufferChecksum % 256) ^ 0xFF) ? true : false;
399406
};
407+
});

0 commit comments

Comments
 (0)