diff --git a/css/app.css b/css/app.css
index 39a727a..3a26177 100644
--- a/css/app.css
+++ b/css/app.css
@@ -41,6 +41,11 @@ button, input[type="text"], textarea {
float: right;
}
+#info > .center {
+ position: absolute;
+ left: 40%;
+}
+
.toolbar {
width: 100%;
position: absolute;
diff --git a/index.html b/index.html
index 0ada198..64442df 100644
--- a/index.html
+++ b/index.html
@@ -21,6 +21,7 @@
diff --git a/js/app.js b/js/app.js
index 144a466..958d8f5 100644
--- a/js/app.js
+++ b/js/app.js
@@ -15,6 +15,7 @@ var App = {
joystickAreaDiv: document.getElementById('joystickArea'),
leftDebugInfoElem: document.querySelector('#info > .left'),
rightDebugInfoElem: document.querySelector('#info > .right'),
+ bluetoothInfoElem: document.querySelector('#info > .center'),
gistIdElem: document.getElementById('gist-id'),
scriptElem: document.getElementById('script'),
@@ -223,15 +224,18 @@ var App = {
this.rsHelper = new RollingSpiderHelper();
// XXX
- ['connecting', 'discovering-services', 'connected', 'disconnect'].forEach(
+ ['connecting', 'discovering-services', 'connected', 'disconnect',
+ 'scanning-start', 'finding-device', 'scanning-stop',
+ 'gatt-connecting'].forEach(
function(eventName) {
that.rsHelper.on(eventName, function() {
that.changeConnectButtonText(eventName);
+ that.bluetoothInfoElem.textContent = eventName;
switch(eventName) {
case 'connected':
// start monitoring joystick movement when there is connection
that._intervalId =
- window.setInterval(that.monitorJoystickMovement.bind(this), 50);
+ window.setInterval(that.monitorJoystickMovement.bind(that), 50);
break;
case 'disconnect':
// stop monitoring joystick movement when disconnect
@@ -243,7 +247,7 @@ var App = {
});
this.connectButton.addEventListener('click', function() {
if (that.rsHelper.isAbleToConnect()) {
- that.rsHelper.connect().then(function onResolve() {
+ that.rsHelper.connect({address: 'a0:14:3d:29:d3:f0'}).then(function onResolve() {
that.changeConnectButtonText('connected');
}, function onReject() {
that.changeConnectButtonText('disconnect');
diff --git a/js/rolling_spider_helper.js b/js/rolling_spider_helper.js
index fd322aa..c074ec7 100644
--- a/js/rolling_spider_helper.js
+++ b/js/rolling_spider_helper.js
@@ -53,16 +53,17 @@ RollingSpiderHelper.prototype = evt({
return this._stateManager.isConnected();
},
- connect: function (deviceNamePrefix) {
- var prefix = deviceNamePrefix || 'RS_';
+ connect: function (options) {
+ var prefix = options.deviceNamePrefix || 'RS_';
+ var address = options.address;
var that = this;
if (this._stateManager.isAbleToConnect()) {
this.fire('connecting');
return new Promise(function(resolve, reject) {
that.fire('scanning-start');
that._startScan().then(function(/* handle */) {
- that.fire('finding-device', {prefix: prefix});
- return that._findDevice(prefix);
+ that.fire('finding-device', {prefix: prefix, address: address});
+ return that._findDevice({deviceNamePrefix: prefix, address: address});
}).then(function(device) {
that.fire('scanning-stop');
device.gatt.onconnectionstatechanged =
@@ -121,13 +122,17 @@ RollingSpiderHelper.prototype = evt({
}
},
- _findDevice: function(deviceNamePrefix) {
+ _findDevice: function(options) {
+ var namePrefix = options.deviceNamePrefix;
+ var address = options.address;
var that = this;
// XXX: we should set timeout for rejection
return new Promise(function(resolve, reject) {
var onGattDeviceFount = function(evt) {
var device = evt.device;
- if(device.name.startsWith(deviceNamePrefix) && !that._isGattConnected) {
+ console.log('found ' + device.name + ': ' + device.address);
+ if(!that._isGattConnected &&
+ (device.name.startsWith(namePrefix) || device.address === address)) {
that._device = device;
that._gatt = device.gatt;
resolve(evt.device);
diff --git a/js/script_runner.js b/js/script_runner.js
index 06d550f..afdbe9d 100644
--- a/js/script_runner.js
+++ b/js/script_runner.js
@@ -56,7 +56,7 @@
run: function() {
if (this._tasks.length > 0 && this._rsHelper.isAbleToConnect()) {
- this._rsHelper.connect().then(function() {
+ this._rsHelper.connect({address: 'a0:14:3d:29:d3:f0'}).then(function() {
// on resolve
this._intervalId =
window.setInterval(this.onEachTask.bind(this), this._timeout);