Accept the pattern as an argument for the blink module.

This commit is contained in:
Pagan Gazzard 2014-12-17 17:54:49 +00:00 committed by Pablo Carranza Vélez
parent cd2603f228
commit b63e7fd595
2 changed files with 11 additions and 11 deletions

View File

@ -14,24 +14,19 @@ module.exports = exports = (ledFile) ->
.then(ledOff) .then(ledOff)
blink.pattern = do -> blink.pattern = do ->
pattern =
onDuration: 200
offDuration: 200
blinks: 4
pause: 1000
blinking = null blinking = null
start = -> start = (pattern) ->
Promise.resolve([0...pattern.blinks]).cancellable() Promise.resolve([0...pattern.blinks]).cancellable()
.each -> .each ->
blink(pattern.onDuration) blink(pattern.onDuration)
.delay(pattern.offDuration) .delay(pattern.offDuration)
.delay(pattern.pause) .delay(pattern.pause)
.then -> .then ->
start() start(pattern)
return { return {
start: -> start: (pattern) ->
return false if blinking? return false if blinking?
blinking = start() blinking = start(pattern)
return return
stop: -> stop: ->
return false if not blinking? return false if not blinking?

View File

@ -60,8 +60,13 @@ exports.findIpAddrs = ->
return ipAddr return ipAddr
.filter(Boolean) .filter(Boolean)
exports.blink = blink networkPattern =
onDuration: 200
offDuration: 200
blinks: 4
pause: 1000
exports.blink = blink
exports.connectivityCheck = _.once -> exports.connectivityCheck = _.once ->
networkCheck.monitorURL networkCheck.monitorURL
url: config.heartbeatEndpoint url: config.heartbeatEndpoint
@ -72,4 +77,4 @@ exports.connectivityCheck = _.once ->
blink.pattern.stop() blink.pattern.stop()
else else
console.log('Waiting for connectivity...') console.log('Waiting for connectivity...')
blink.pattern.start() blink.pattern.start(networkPattern)