Merge pull request #5 from hybridgroup/singleton

Master singleton class
This commit is contained in:
Ron Evans 2013-10-23 20:01:07 -07:00
commit abd742df3f
4 changed files with 46 additions and 5 deletions

View File

@ -1,4 +1,4 @@
var Cylon = require('..');
var Cylon = require('..').instance();
Cylon.robot({
connection: { name: 'looped', adaptor: 'loopback'},

25
examples/master.coffee Normal file
View File

@ -0,0 +1,25 @@
Cylon = require '..'
RobotInfo =
connection:
name: 'Sphero', adaptor: 'sphero'
work: -> every 2.seconds(), -> Logger.info "Required cylon-sphero adaptor!"
huey = Object.create(RobotInfo)
huey.connection['port'] = '/dev/cu.Sphero-RGB'
huey.name = "Huey"
dewey = Object.create(RobotInfo)
dewey.connection['port'] = '/dev/cu.Sphero-GRB'
dewey.name = "Dewey"
louie = Object.create(RobotInfo)
louie.connection['port'] = '/dev/cu.Sphero-BRG'
louie.name = "Louie"
Cylon.robot(huey)
Cylon.robot(dewey)
Cylon.robot(louie)
Cylon.start()

View File

@ -1,4 +1,4 @@
Cylon = require '..'
Cylon = require('..')
Cylon.robot
connection:

View File

@ -15,6 +15,22 @@ require('./logger')
Logger.setup()
exports.robot = (opts = {}) ->
opts.master = this
new Robot(opts)
class Cylon
instance = null
@getInstance: (args...) ->
instance ?= new Master(args...)
class Master
robots = []
robot: (opts) =>
opts.master = this
robot = new Robot(opts)
robots.push robot
robot
start: ->
robot.start() for robot in robots
module.exports = Cylon.getInstance()