mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-05-20 17:52:56 +00:00
Switch to using a separate module for blinking.
This commit is contained in:
parent
6c81066796
commit
f0682b162a
@ -8,6 +8,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"JSONStream": "~0.7.1",
|
"JSONStream": "~0.7.1",
|
||||||
|
"blinker": "git+ssh://git@bitbucket.org:rulemotion/blinker.git#v0.0.1",
|
||||||
"bluebird": "^2.6.0",
|
"bluebird": "^2.6.0",
|
||||||
"coffee-script": "~1.8.0",
|
"coffee-script": "~1.8.0",
|
||||||
"csr-gen": "~0.2.1",
|
"csr-gen": "~0.2.1",
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
Promise = require 'bluebird'
|
|
||||||
fs = Promise.promisifyAll require 'fs'
|
|
||||||
|
|
||||||
# Helps in blinking the LED from the given end point.
|
|
||||||
module.exports = exports = (ledFile) ->
|
|
||||||
ledOn = ->
|
|
||||||
fs.writeFileAsync(ledFile, 1)
|
|
||||||
ledOff = ->
|
|
||||||
fs.writeFileAsync(ledFile, 0)
|
|
||||||
|
|
||||||
blink = (ms = 200) ->
|
|
||||||
ledOn()
|
|
||||||
.delay(ms)
|
|
||||||
.then(ledOff)
|
|
||||||
|
|
||||||
blink.pattern = do ->
|
|
||||||
blinking = null
|
|
||||||
start = (pattern) ->
|
|
||||||
Promise.resolve([0...pattern.blinks]).cancellable()
|
|
||||||
.each ->
|
|
||||||
blink(pattern.onDuration)
|
|
||||||
.delay(pattern.offDuration)
|
|
||||||
.delay(pattern.pause)
|
|
||||||
.then ->
|
|
||||||
start(pattern)
|
|
||||||
return {
|
|
||||||
start: (pattern = {}) ->
|
|
||||||
return false if blinking?
|
|
||||||
fullPattern =
|
|
||||||
blinks: pattern.blinks ? 1
|
|
||||||
onDuration: pattern.onDuration ? 200
|
|
||||||
offDuration: pattern.offDuration ? 200
|
|
||||||
pause: pattern.pause ? 0
|
|
||||||
blinking = start(fullPattern)
|
|
||||||
return
|
|
||||||
stop: ->
|
|
||||||
return false if not blinking?
|
|
||||||
blinking.cancel().catch(Promise.CancellationError, ->)
|
|
||||||
ledOff()
|
|
||||||
blinking = null
|
|
||||||
}
|
|
||||||
|
|
||||||
return blink
|
|
@ -5,7 +5,7 @@ config = require './config'
|
|||||||
mixpanel = require 'mixpanel'
|
mixpanel = require 'mixpanel'
|
||||||
request = require './request'
|
request = require './request'
|
||||||
networkCheck = require './lib/network-check'
|
networkCheck = require './lib/network-check'
|
||||||
blink = require('./lib/blink')(config.ledFile)
|
blink = require('blinker')(config.ledFile)
|
||||||
|
|
||||||
utils = exports
|
utils = exports
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user