Merge branch 'master' into api
* master: Need a line break Updates for version 0.2.0 Removing DriverName param in favor of opts, which already contains it. Adding analog sensor support to cylon GPIO.
This commit is contained in:
commit
a58ed257b8
|
@ -67,10 +67,12 @@ Support for common shared device drivers, is provded using the General Purpoer I
|
|||
|
||||
- [GPIO](https://en.wikipedia.org/wiki/General_Purpose_Input/Output) <=> [Drivers](https://github.com/hybridgroup/cylon-gpio)
|
||||
|
||||
More platforms and drivers are coming soon!
|
||||
More platforms and drivers are coming soon...
|
||||
|
||||
## Documentation
|
||||
_(Coming soon)_
|
||||
We're busy adding documentation to our web site at http://cylonjs.com/ please check there as we continue to work on Cylon.js
|
||||
|
||||
Thank you!
|
||||
|
||||
## Contributing
|
||||
In lieu of a formal styleguide, take care to maintain the existing coding style.
|
||||
|
@ -80,5 +82,7 @@ using [Grunt](http://gruntjs.com/).
|
|||
## Release History
|
||||
Version 0.1.0 - Initial release for ongoing development
|
||||
|
||||
Version 0.2.0 - Cylon.Basestar to help develop external adaptors/drivers
|
||||
|
||||
## License
|
||||
Copyright (c) 2013 The Hybrid Group. Licensed under the Apache 2.0 license.
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
this.name = opts.name;
|
||||
this.pin = opts.pin;
|
||||
this.connection = this.determineConnection(opts.connection) || this.defaultConnection();
|
||||
this.driver = this.requireDriver(opts.driver);
|
||||
this.driver = this.requireDriver(opts);
|
||||
proxyFunctionsToObject(this.driver.commands(), this.driver, klass);
|
||||
}
|
||||
|
||||
|
@ -66,9 +66,12 @@
|
|||
return first;
|
||||
};
|
||||
|
||||
Device.prototype.requireDriver = function(driverName) {
|
||||
Logger.debug("Loading driver '" + driverName + "'");
|
||||
return this.robot.requireDriver(driverName, this.self);
|
||||
Device.prototype.requireDriver = function(opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
Logger.debug("Loading driver '" + opts.driver + "'");
|
||||
return this.robot.requireDriver(opts.driver, this.self, opts);
|
||||
};
|
||||
|
||||
return Device;
|
||||
|
|
|
@ -157,19 +157,24 @@
|
|||
return this.adaptors[adaptorName] = moduleName;
|
||||
};
|
||||
|
||||
Robot.prototype.requireDriver = function(driverName, device) {
|
||||
Robot.prototype.requireDriver = function(driverName, device, opts) {
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (this.robot.drivers[driverName] != null) {
|
||||
if (typeof this.robot.drivers[driverName] === 'string') {
|
||||
this.robot.drivers[driverName] = require(this.robot.drivers[driverName]).driver({
|
||||
name: driverName,
|
||||
device: device
|
||||
device: device,
|
||||
extraParams: opts
|
||||
});
|
||||
}
|
||||
} else {
|
||||
require("cylon-" + driverName).register(this);
|
||||
this.robot.drivers[driverName] = require("cylon-" + driverName).driver({
|
||||
name: driverName,
|
||||
device: device
|
||||
device: device,
|
||||
extraParams: opts
|
||||
});
|
||||
}
|
||||
return this.robot.drivers[driverName];
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
Cylon = require('..')
|
||||
|
||||
# Initialize the robot
|
||||
Cylon.robot
|
||||
connection:
|
||||
name: 'arduino', adaptor: 'firmata', port: '/dev/ttyACM0'
|
||||
|
||||
devices:
|
||||
[
|
||||
{name: 'sensor', driver: 'analogSensor', pin: 0, upperLimit: 900, lowerLimit: 100},
|
||||
]
|
||||
|
||||
work: (my) ->
|
||||
#my.sensor.on('analogRead', (val) ->
|
||||
# console.log("AnalogValue ===> #{ val }")
|
||||
#)
|
||||
my.sensor.on('upperLimit', (val) ->
|
||||
console.log("Upper limit reached ===> #{ val }")
|
||||
)
|
||||
my.sensor.on('lowerLimit', (val) ->
|
||||
console.log("Lower limit reached ===> #{ val }")
|
||||
)
|
||||
.start()
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "cylon",
|
||||
"version": "0.1.0",
|
||||
"version": "0.2.0",
|
||||
"main": "dist/cylon.js",
|
||||
"description": "A JavaScript robotics framework using node.js",
|
||||
"homepage": "http://cylonjs.com",
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = class Device extends EventEmitter
|
|||
@name = opts.name
|
||||
@pin = opts.pin
|
||||
@connection = @determineConnection(opts.connection) or @defaultConnection()
|
||||
@driver = @requireDriver(opts.driver)
|
||||
@driver = @requireDriver(opts)
|
||||
proxyFunctionsToObject @driver.commands(), @driver, klass
|
||||
|
||||
start: (callback) =>
|
||||
|
@ -38,6 +38,6 @@ module.exports = class Device extends EventEmitter
|
|||
first or= v
|
||||
first
|
||||
|
||||
requireDriver: (driverName) ->
|
||||
Logger.debug "Loading driver '#{driverName}'"
|
||||
@robot.requireDriver(driverName, @self)
|
||||
requireDriver: (opts = {}) ->
|
||||
Logger.debug "Loading driver '#{ opts.driver }'"
|
||||
@robot.requireDriver(opts.driver, @self, opts)
|
||||
|
|
|
@ -93,13 +93,13 @@ module.exports = class Robot
|
|||
return if @adaptors[adaptorName]?
|
||||
@adaptors[adaptorName] = moduleName
|
||||
|
||||
requireDriver: (driverName, device) ->
|
||||
requireDriver: (driverName, device, opts = {}) ->
|
||||
if @robot.drivers[driverName]?
|
||||
if typeof @robot.drivers[driverName] is 'string'
|
||||
@robot.drivers[driverName] = require(@robot.drivers[driverName]).driver(name: driverName, device: device)
|
||||
@robot.drivers[driverName] = require(@robot.drivers[driverName]).driver(name: driverName, device: device, extraParams: opts)
|
||||
else
|
||||
require("cylon-#{driverName}").register(this)
|
||||
@robot.drivers[driverName] = require("cylon-#{driverName}").driver(name: driverName, device: device)
|
||||
@robot.drivers[driverName] = require("cylon-#{driverName}").driver(name: driverName, device: device, extraParams: opts)
|
||||
|
||||
return @robot.drivers[driverName]
|
||||
|
||||
|
|
Loading…
Reference in New Issue