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)
|
- [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
|
## 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
|
## Contributing
|
||||||
In lieu of a formal styleguide, take care to maintain the existing coding style.
|
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
|
## Release History
|
||||||
Version 0.1.0 - Initial release for ongoing development
|
Version 0.1.0 - Initial release for ongoing development
|
||||||
|
|
||||||
|
Version 0.2.0 - Cylon.Basestar to help develop external adaptors/drivers
|
||||||
|
|
||||||
## License
|
## License
|
||||||
Copyright (c) 2013 The Hybrid Group. Licensed under the Apache 2.0 license.
|
Copyright (c) 2013 The Hybrid Group. Licensed under the Apache 2.0 license.
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
this.name = opts.name;
|
this.name = opts.name;
|
||||||
this.pin = opts.pin;
|
this.pin = opts.pin;
|
||||||
this.connection = this.determineConnection(opts.connection) || this.defaultConnection();
|
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);
|
proxyFunctionsToObject(this.driver.commands(), this.driver, klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,12 @@
|
||||||
return first;
|
return first;
|
||||||
};
|
};
|
||||||
|
|
||||||
Device.prototype.requireDriver = function(driverName) {
|
Device.prototype.requireDriver = function(opts) {
|
||||||
Logger.debug("Loading driver '" + driverName + "'");
|
if (opts == null) {
|
||||||
return this.robot.requireDriver(driverName, this.self);
|
opts = {};
|
||||||
|
}
|
||||||
|
Logger.debug("Loading driver '" + opts.driver + "'");
|
||||||
|
return this.robot.requireDriver(opts.driver, this.self, opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
return Device;
|
return Device;
|
||||||
|
|
|
@ -157,19 +157,24 @@
|
||||||
return this.adaptors[adaptorName] = moduleName;
|
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 (this.robot.drivers[driverName] != null) {
|
||||||
if (typeof this.robot.drivers[driverName] === 'string') {
|
if (typeof this.robot.drivers[driverName] === 'string') {
|
||||||
this.robot.drivers[driverName] = require(this.robot.drivers[driverName]).driver({
|
this.robot.drivers[driverName] = require(this.robot.drivers[driverName]).driver({
|
||||||
name: driverName,
|
name: driverName,
|
||||||
device: device
|
device: device,
|
||||||
|
extraParams: opts
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
require("cylon-" + driverName).register(this);
|
require("cylon-" + driverName).register(this);
|
||||||
this.robot.drivers[driverName] = require("cylon-" + driverName).driver({
|
this.robot.drivers[driverName] = require("cylon-" + driverName).driver({
|
||||||
name: driverName,
|
name: driverName,
|
||||||
device: device
|
device: device,
|
||||||
|
extraParams: opts
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return this.robot.drivers[driverName];
|
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",
|
"name": "cylon",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"main": "dist/cylon.js",
|
"main": "dist/cylon.js",
|
||||||
"description": "A JavaScript robotics framework using node.js",
|
"description": "A JavaScript robotics framework using node.js",
|
||||||
"homepage": "http://cylonjs.com",
|
"homepage": "http://cylonjs.com",
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.exports = class Device extends EventEmitter
|
||||||
@name = opts.name
|
@name = opts.name
|
||||||
@pin = opts.pin
|
@pin = opts.pin
|
||||||
@connection = @determineConnection(opts.connection) or @defaultConnection()
|
@connection = @determineConnection(opts.connection) or @defaultConnection()
|
||||||
@driver = @requireDriver(opts.driver)
|
@driver = @requireDriver(opts)
|
||||||
proxyFunctionsToObject @driver.commands(), @driver, klass
|
proxyFunctionsToObject @driver.commands(), @driver, klass
|
||||||
|
|
||||||
start: (callback) =>
|
start: (callback) =>
|
||||||
|
@ -38,6 +38,6 @@ module.exports = class Device extends EventEmitter
|
||||||
first or= v
|
first or= v
|
||||||
first
|
first
|
||||||
|
|
||||||
requireDriver: (driverName) ->
|
requireDriver: (opts = {}) ->
|
||||||
Logger.debug "Loading driver '#{driverName}'"
|
Logger.debug "Loading driver '#{ opts.driver }'"
|
||||||
@robot.requireDriver(driverName, @self)
|
@robot.requireDriver(opts.driver, @self, opts)
|
||||||
|
|
|
@ -93,13 +93,13 @@ module.exports = class Robot
|
||||||
return if @adaptors[adaptorName]?
|
return if @adaptors[adaptorName]?
|
||||||
@adaptors[adaptorName] = moduleName
|
@adaptors[adaptorName] = moduleName
|
||||||
|
|
||||||
requireDriver: (driverName, device) ->
|
requireDriver: (driverName, device, opts = {}) ->
|
||||||
if @robot.drivers[driverName]?
|
if @robot.drivers[driverName]?
|
||||||
if typeof @robot.drivers[driverName] is 'string'
|
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
|
else
|
||||||
require("cylon-#{driverName}").register(this)
|
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]
|
return @robot.drivers[driverName]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue