diff --git a/README.markdown b/README.markdown index 0bbca26..5265cbd 100644 --- a/README.markdown +++ b/README.markdown @@ -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) diff --git a/examples/api/api.js b/examples/api/api.js index 1e38655..a09e77e 100644 --- a/examples/api/api.js +++ b/examples/api/api.js @@ -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' }, diff --git a/examples/api/api.markdown b/examples/api/api.markdown index 5a70482..89f9e33 100644 --- a/examples/api/api.markdown +++ b/examples/api/api.markdown @@ -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. diff --git a/examples/sphero-pebble-sf/sphero-pebble-sf.js b/examples/sphero-pebble-sf/sphero-pebble-sf.js index d38bcd5..324ea12 100644 --- a/examples/sphero-pebble-sf/sphero-pebble-sf.js +++ b/examples/sphero-pebble-sf/sphero-pebble-sf.js @@ -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); } diff --git a/examples/sphero-pebble-sf/sphero-pebble-sf.markdown b/examples/sphero-pebble-sf/sphero-pebble-sf.markdown index 9aab7cf..9f92c64 100644 --- a/examples/sphero-pebble-sf/sphero-pebble-sf.markdown +++ b/examples/sphero-pebble-sf/sphero-pebble-sf.markdown @@ -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: diff --git a/lib/adaptor.js b/lib/adaptor.js index 39dceb5..3257807 100644 --- a/lib/adaptor.js +++ b/lib/adaptor.js @@ -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)); -}; diff --git a/lib/cylon.js b/lib/cylon.js index 24c6b39..f56c1ed 100644 --- a/lib/cylon.js +++ b/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) { - for (var o in opts) { - Config[o] = opts[o]; +// 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 diff --git a/lib/driver.js b/lib/driver.js index 6b1757d..f763272 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -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 = {}; }; diff --git a/test/specs/adaptor.spec.js b/test/specs/adaptor.spec.js index bd9d178..1ef73da 100644 --- a/test/specs/adaptor.spec.js +++ b/test/specs/adaptor.spec.js @@ -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; - }); - }); }); diff --git a/test/specs/cylon.spec.js b/test/specs/cylon.spec.js index 6379a47..5a8041d 100644 --- a/test/specs/cylon.spec.js +++ b/test/specs/cylon.spec.js @@ -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() { diff --git a/test/specs/driver.spec.js b/test/specs/driver.spec.js index caa98cb..02c2c79 100644 --- a/test/specs/driver.spec.js +++ b/test/specs/driver.spec.js @@ -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() { diff --git a/test/support/env.js b/test/support/env.js index 4abe5fb..014e587 100644 --- a/test/support/env.js +++ b/test/support/env.js @@ -28,7 +28,7 @@ global.source = function(module) { var Cylon = source('cylon'); -Cylon.setConfig({ +Cylon.config({ auto_start: false });