Merge pull request #5 from hybridgroup/singleton
Master singleton class
This commit is contained in:
commit
abd742df3f
|
@ -1,4 +1,4 @@
|
|||
var Cylon = require('..');
|
||||
var Cylon = require('..').instance();
|
||||
|
||||
Cylon.robot({
|
||||
connection: { name: 'looped', adaptor: 'loopback'},
|
||||
|
|
|
@ -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()
|
|
@ -1,4 +1,4 @@
|
|||
Cylon = require '..'
|
||||
Cylon = require('..')
|
||||
|
||||
Cylon.robot
|
||||
connection:
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue