Merge branch 'dev' into add/imperative-work
* dev: Remove Adaptor#_noop function Move Cylon API config to the Cylon.configure block Fixup interval in driver Add all new platforms to README Add default interval in Driver class Switch to single Cylon#config function Conflicts: test/specs/cylon.spec.js
This commit is contained in:
commit
83bf4e3d14
|
@ -139,14 +139,18 @@ Cylon.start();
|
|||
## Hardware Support
|
||||
|
||||
Cylon.js has an extensible syntax for connecting to multiple, different hardware
|
||||
devices. The following 21 platforms are currently supported:
|
||||
devices. The following 26 platforms are currently supported:
|
||||
|
||||
- [Ardrone](http://ardrone2.parrot.com/) <==> [Adaptor/Drivers](https://github.com/hybridgroup/cylon-ardrone)
|
||||
- [Arduino](http://www.arduino.cc/) <==> [Adaptor](https://github.com/hybridgroup/cylon-firmata)
|
||||
- [Arduino YUN](http://arduino.cc/en/Main/ArduinoBoardYun?from=Products.ArduinoYUN) <==> [Adaptor](https://github.com/hybridgroup/cylon-firmata)
|
||||
- [AT&T M2X](https://m2x.att.com) <==> [Adaptor/Drivers](https://github.com/hybridgroup/cylon-m2x)
|
||||
- [Audio]() <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-audio)
|
||||
- [Beaglebone Black](http://beagleboard.org/Products/BeagleBone+Black/) <==> [Adaptor](https://github.com/hybridgroup/cylon-beaglebone)
|
||||
- [Crazyflie](http://www.bitcraze.se/) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-crazyflie)
|
||||
- [Digispark](http://digistump.com/products/1) <==> [Adaptor](https://github.com/hybridgroup/cylon-digispark)
|
||||
- [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) <==> [Adaptor](https://github.com/hybridgroup/cylon-intel-iot)
|
||||
- [Intel Galileo](http://www.intel.com/content/www/us/en/do-it-yourself/galileo-maker-quark-board.html) <==> [Adaptor](https://github.com/hybridgroup/cylon-intel-iot)
|
||||
- [Joystick](http://en.wikipedia.org/wiki/Joystick) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-joystick)
|
||||
- [Keyboard](http://en.wikipedia.org/wiki/Computer_keyboard) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-keyboard)
|
||||
- [Leap Motion](https://www.leapmotion.com/) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-leapmotion)
|
||||
|
@ -160,6 +164,7 @@ devices. The following 21 platforms are currently supported:
|
|||
- [Salesforce](http://www.force.com/) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-force)
|
||||
- [Skynet](http://skynet.im/) <==> [Adaptor](https://github.com/hybridgroup/cylon-skynet)
|
||||
- [Spark](http://www.spark.io/) <==> [Adaptor](https://github.com/hybridgroup/cylon-spark)
|
||||
- [Speech]() <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-speech)
|
||||
- [Sphero](http://www.gosphero.com/) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-sphero)
|
||||
- [Tessel](https://tessel.io/) <==> [Adaptor/Driver](https://github.com/hybridgroup/cylon-tessel)
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
var Cylon = require('../..');
|
||||
|
||||
Cylon.api({ host: '0.0.0.0', port: '8080' });
|
||||
Cylon.config({
|
||||
api: { host: '0.0.0.0', port: '8080' }
|
||||
});
|
||||
|
||||
Cylon.api();
|
||||
|
||||
var bots = [
|
||||
{ port: '/dev/rfcomm0', name: 'Thelma' },
|
||||
|
|
|
@ -13,7 +13,11 @@ First, let's import Cylon:
|
|||
Next up, we'll configure the API Cylon will serve, telling it to serve on port
|
||||
`8080`.
|
||||
|
||||
Cylon.api({host: '0.0.0.0', port: '8080'});
|
||||
Cylon.config({
|
||||
api: { host: '0.0.0.0', port: '8080' }
|
||||
});
|
||||
|
||||
Cylon.api();
|
||||
|
||||
Since we're making two very similar robots (Spheros, in this case), let's put
|
||||
the different parts of each robot in objects so we can initialize them later.
|
||||
|
|
|
@ -4,7 +4,11 @@ var __bind = function(fn, me) {
|
|||
|
||||
var Cylon = require('../..');
|
||||
|
||||
Cylon.api({ host: '0.0.0.0', port: '8080' });
|
||||
Cylon.config({
|
||||
api: { host: '0.0.0.0', port: '8080' }
|
||||
});
|
||||
|
||||
Cylon.api();
|
||||
|
||||
var PebbleRobot = (function() {
|
||||
function PebbleRobot() { this.message = __bind(this.message, this); }
|
||||
|
|
|
@ -7,7 +7,11 @@ First, let's import Cylon:
|
|||
Next up, we'll configure the API Cylon will serve, telling it to serve on port
|
||||
`8080`.
|
||||
|
||||
Cylon.api({ host: '0.0.0.0', port: '8080' });
|
||||
Cylon.config({
|
||||
api: { host: '0.0.0.0', port: '8080' }
|
||||
});
|
||||
|
||||
Cylon.api();
|
||||
|
||||
We'll also setup a convenince function for some binding we'll need to do later:
|
||||
|
||||
|
|
|
@ -29,13 +29,3 @@ var Adaptor = module.exports = function Adaptor(opts) {
|
|||
Utils.subclass(Adaptor, Basestar);
|
||||
|
||||
Adaptor.prototype.commands = [];
|
||||
|
||||
// Public: Voids all command functions so they do not interact
|
||||
// with anything after disconnect has been called.
|
||||
//
|
||||
// Returns nothing
|
||||
Adaptor.prototype._noop = function() {
|
||||
this.commands.forEach(function(command) {
|
||||
this[command] = function() {};
|
||||
}.bind(this));
|
||||
};
|
||||
|
|
27
lib/cylon.js
27
lib/cylon.js
|
@ -62,17 +62,13 @@ Cylon.robot = function robot(opts) {
|
|||
|
||||
// Public: Creates a new API based on passed options
|
||||
//
|
||||
// opts - object containing API options
|
||||
//
|
||||
// Returns nothing
|
||||
Cylon.api = function api(opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
|
||||
Cylon.api = function api() {
|
||||
var API = require('./api');
|
||||
|
||||
this.api_instance = new API(opts);
|
||||
var config = Utils.fetch(Config, 'api', {});
|
||||
|
||||
this.api_instance = new API(config);
|
||||
this.api_instance.listen();
|
||||
};
|
||||
|
||||
|
@ -89,24 +85,17 @@ Cylon.start = function start() {
|
|||
//
|
||||
// opts - object containing configuration key/value pairs
|
||||
//
|
||||
// Returns the updated config
|
||||
Cylon.setConfig = function(opts) {
|
||||
// Returns the current config
|
||||
Cylon.config = function(opts) {
|
||||
if (opts && typeof(opts) === 'object' && !Array.isArray(opts)) {
|
||||
for (var o in opts) {
|
||||
Config[o] = opts[o];
|
||||
}
|
||||
}
|
||||
|
||||
return Config;
|
||||
};
|
||||
|
||||
// Public: Fetches a value from the internal configuration
|
||||
//
|
||||
// key - string key to be fetched from config
|
||||
//
|
||||
// Returns the config value
|
||||
Cylon.config = function(key) {
|
||||
return Config[key];
|
||||
};
|
||||
|
||||
// Public: Halts the API and the robots
|
||||
//
|
||||
// callback - callback to be triggered when Cylon is ready to shutdown
|
||||
|
|
|
@ -21,10 +21,12 @@ var Basestar = require('./basestar'),
|
|||
// Returns a new Driver
|
||||
var Driver = module.exports = function Driver(opts) {
|
||||
opts = opts || {};
|
||||
var extraParams = opts.extraParams || {}
|
||||
|
||||
this.name = opts.name;
|
||||
this.device = opts.device;
|
||||
this.connection = this.device.connection;
|
||||
this.interval = extraParams.interval || 10;
|
||||
|
||||
this.commands = {};
|
||||
};
|
||||
|
|
|
@ -23,22 +23,4 @@ describe("Adaptor", function() {
|
|||
expect(adaptor.commands).to.be.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#_noop", function() {
|
||||
var hello;
|
||||
|
||||
beforeEach(function() {
|
||||
adaptor.commands = ["hello"];
|
||||
hello = adaptor.hello = spy();
|
||||
});
|
||||
|
||||
it("sets all adaptor commands to no-op functions", function() {
|
||||
expect(adaptor.hello).to.be.eql(hello);
|
||||
|
||||
adaptor._noop();
|
||||
|
||||
adaptor.hello();
|
||||
expect(hello).to.not.be.called;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -72,8 +72,9 @@ describe("Cylon", function() {
|
|||
expect(Cylon.api_instance).to.be.an.instanceOf(API);
|
||||
});
|
||||
|
||||
it('passes arguments to the API constructor', function() {
|
||||
Cylon.api({ port: '1234' });
|
||||
it('passes configuration to the API constructor', function() {
|
||||
Cylon.config({ api: { port: '1234' }});
|
||||
Cylon.api();
|
||||
expect(Cylon.api_instance.port).to.be.eql('1234');
|
||||
})
|
||||
});
|
||||
|
@ -95,25 +96,7 @@ describe("Cylon", function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe("#setConfig", function() {
|
||||
var originalConfig = {};
|
||||
|
||||
before(function() {
|
||||
for (var c in Config) {
|
||||
originalConfig[c] = Config[c];
|
||||
}
|
||||
});
|
||||
|
||||
after(function() {
|
||||
for (var c in Config) {
|
||||
delete Config[c];
|
||||
}
|
||||
|
||||
for (var c in originalConfig) {
|
||||
Config[c] = originalConfig[c];
|
||||
}
|
||||
});
|
||||
|
||||
describe("#config", function() {
|
||||
beforeEach(function() {
|
||||
for (var c in Config) {
|
||||
delete Config[c];
|
||||
|
@ -121,30 +104,29 @@ describe("Cylon", function() {
|
|||
});
|
||||
|
||||
it("sets config variables", function() {
|
||||
Cylon.setConfig({ a: 1, b: 2 });
|
||||
Cylon.config({ a: 1, b: 2 });
|
||||
expect(Config.a).to.be.eql(1);
|
||||
expect(Config.b).to.be.eql(2);
|
||||
});
|
||||
|
||||
it("updates existing config", function() {
|
||||
Cylon.setConfig({ a: 1, b: 2 });
|
||||
Cylon.setConfig({ a: 3 });
|
||||
Cylon.config({ a: 1, b: 2 });
|
||||
Cylon.config({ a: 3 });
|
||||
expect(Config.a).to.be.eql(3);
|
||||
expect(Config.b).to.be.eql(2);
|
||||
});
|
||||
|
||||
it("returns updated config", function() {
|
||||
var config = Cylon.setConfig({ a: 1, b: 2 });
|
||||
var config = Cylon.config({ a: 1, b: 2 });
|
||||
expect(Config).to.be.eql(config);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#config", function() {
|
||||
it("returns a value from the Config object", function() {
|
||||
Config.a = "hello world";
|
||||
expect(Cylon.config("a")).to.be.eql("hello world");
|
||||
delete Config.a;
|
||||
})
|
||||
it("doesn't ignores non-object arguments", function() {
|
||||
var config = Cylon.config({ a: 1, b: 2 });
|
||||
Cylon.config(["a", 1, "b", 2]);
|
||||
Cylon.config("hello world");
|
||||
expect(Config).to.be.eql(config);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#halt", function() {
|
||||
|
|
|
@ -37,6 +37,18 @@ describe("Driver", function() {
|
|||
it("sets @commands to an empty object by default", function() {
|
||||
expect(driver.commands).to.be.eql({});
|
||||
});
|
||||
|
||||
it("sets @interval to 10ms by default, or the provided value", function() {
|
||||
expect(driver.interval).to.be.eql(10);
|
||||
driver = new Driver({
|
||||
name: 'driver',
|
||||
device: device,
|
||||
extraParams: {
|
||||
interval: 2000
|
||||
}
|
||||
});
|
||||
expect(driver.interval).to.be.eql(2000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#setupCommands", function() {
|
||||
|
|
|
@ -28,7 +28,7 @@ global.source = function(module) {
|
|||
|
||||
var Cylon = source('cylon');
|
||||
|
||||
Cylon.setConfig({
|
||||
Cylon.config({
|
||||
auto_start: false
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue