WIP on refactoring adaptor/driver base classes

This commit is contained in:
deadprogram 2013-12-15 10:52:09 -08:00
parent 4a058742c4
commit 4cb8742fc3
11 changed files with 40 additions and 22 deletions

4
dist/adaptor.js vendored
View File

@ -15,6 +15,8 @@
namespace = require('node-namespace'); namespace = require('node-namespace');
require('./basestar');
namespace('Cylon.Adaptors', function() { namespace('Cylon.Adaptors', function() {
return this.Adaptor = (function(_super) { return this.Adaptor = (function(_super) {
__extends(Adaptor, _super); __extends(Adaptor, _super);
@ -44,6 +46,4 @@
})(Cylon.Basestar); })(Cylon.Basestar);
}); });
module.exports = Cylon.Adaptors.Adaptor;
}).call(this); }).call(this);

4
dist/cylon.js vendored
View File

@ -19,6 +19,10 @@
require('./api'); require('./api');
require('./driver');
require('./adaptor');
Logger.setup(); Logger.setup();
Cylon = (function() { Cylon = (function() {

11
dist/driver.js vendored
View File

@ -15,6 +15,8 @@
namespace = require('node-namespace'); namespace = require('node-namespace');
require('./basestar');
namespace('Cylon.Drivers', function() { namespace('Cylon.Drivers', function() {
return this.Driver = (function(_super) { return this.Driver = (function(_super) {
__extends(Driver, _super); __extends(Driver, _super);
@ -25,8 +27,11 @@
this.device = opts.device; this.device = opts.device;
} }
Driver.prototype.start = function() { Driver.prototype.start = function(callback) {
return Logger.info("Driver " + this.name + " started"); Logger.info("Driver " + this.name + " started");
callback(null);
this.device.emit('start');
return true;
}; };
Driver.prototype.stop = function() { Driver.prototype.stop = function() {
@ -42,6 +47,4 @@
})(Cylon.Basestar); })(Cylon.Basestar);
}); });
module.exports = Cylon.Drivers.Driver;
}).call(this); }).call(this);

View File

@ -29,13 +29,11 @@
}; };
namespace('Cylon.Adaptors', function() { namespace('Cylon.Adaptors', function() {
var _ref;
return this.Loopback = (function(_super) { return this.Loopback = (function(_super) {
__extends(Loopback, _super); __extends(Loopback, _super);
function Loopback() { function Loopback(opts) {
_ref = Loopback.__super__.constructor.apply(this, arguments); Loopback.__super__.constructor.apply(this, arguments);
return _ref;
} }
Loopback.prototype.commands = function() { Loopback.prototype.commands = function() {
@ -44,7 +42,7 @@
return Loopback; return Loopback;
})(this.Adaptor); })(Cylon.Adaptors.Adaptor);
}); });
}).call(this); }).call(this);

8
dist/test/ping.js vendored
View File

@ -29,13 +29,11 @@
}; };
namespace('Cylon.Drivers', function() { namespace('Cylon.Drivers', function() {
var _ref;
return this.Ping = (function(_super) { return this.Ping = (function(_super) {
__extends(Ping, _super); __extends(Ping, _super);
function Ping() { function Ping(opts) {
_ref = Ping.__super__.constructor.apply(this, arguments); Ping.__super__.constructor.apply(this, arguments);
return _ref;
} }
Ping.prototype.commands = function() { Ping.prototype.commands = function() {
@ -48,7 +46,7 @@
return Ping; return Ping;
})(this.Driver); })(Cylon.Drivers.Driver);
}); });
}).call(this); }).call(this);

View File

@ -1,6 +1,6 @@
{ {
"name": "cylon", "name": "cylon",
"version": "0.7.0", "version": "0.8.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",

View File

@ -10,6 +10,8 @@
namespace = require 'node-namespace' namespace = require 'node-namespace'
require './basestar'
namespace 'Cylon.Adaptors', -> namespace 'Cylon.Adaptors', ->
class @Adaptor extends Cylon.Basestar class @Adaptor extends Cylon.Basestar
constructor: (opts) -> constructor: (opts) ->
@ -28,4 +30,4 @@ namespace 'Cylon.Adaptors', ->
disconnect: -> disconnect: ->
Logger.info "Disconnecting from adaptor '#{@name}'..." Logger.info "Disconnecting from adaptor '#{@name}'..."
module.exports = Cylon.Adaptors.Adaptor #module.exports = Cylon.Adaptor

View File

@ -11,6 +11,8 @@
require './utils' require './utils'
require './logger' require './logger'
require './api' require './api'
require './driver'
require './adaptor'
Logger.setup() Logger.setup()

View File

@ -10,6 +10,8 @@
namespace = require 'node-namespace' namespace = require 'node-namespace'
require './basestar'
namespace 'Cylon.Drivers', -> namespace 'Cylon.Drivers', ->
class @Driver extends Cylon.Basestar class @Driver extends Cylon.Basestar
constructor: (opts) -> constructor: (opts) ->
@ -17,8 +19,11 @@ namespace 'Cylon.Drivers', ->
@name = opts.name @name = opts.name
@device = opts.device @device = opts.device
start: -> start: (callback) ->
Logger.info "Driver #{@name} started" Logger.info "Driver #{@name} started"
(callback)(null)
@device.emit 'start'
true
stop: -> stop: ->
Logger.info "Driver #{@name} stopped" Logger.info "Driver #{@name} stopped"
@ -26,4 +31,4 @@ namespace 'Cylon.Drivers', ->
commands: -> commands: ->
[] []
module.exports = Cylon.Drivers.Driver #module.exports = Cylon.Driver

View File

@ -15,6 +15,9 @@ module.exports =
new Cylon.Adaptors.Loopback(args...) new Cylon.Adaptors.Loopback(args...)
namespace 'Cylon.Adaptors', -> namespace 'Cylon.Adaptors', ->
class @Loopback extends @Adaptor class @Loopback extends Cylon.Adaptors.Adaptor
constructor: (opts) ->
super
commands: -> commands: ->
['ping'] ['ping']

View File

@ -15,7 +15,10 @@ module.exports =
new Cylon.Drivers.Ping(args...) new Cylon.Drivers.Ping(args...)
namespace 'Cylon.Drivers', -> namespace 'Cylon.Drivers', ->
class @Ping extends @Driver class @Ping extends Cylon.Drivers.Driver
constructor: (opts) ->
super
commands: -> commands: ->
['ping'] ['ping']