balena-supervisor/src/api.coffee

31 lines
627 B
CoffeeScript
Raw Normal View History

2013-12-23 04:22:54 +00:00
Promise = require 'bluebird'
fs = Promise.promisifyAll require 'fs'
utils = require './utils'
express = require 'express'
application = require './application'
api = express()
LED_FILE = '/sys/class/leds/led0/brightness'
2013-12-23 04:22:54 +00:00
blink = (ms = 200) ->
fs.writeFileAsync(LED_FILE, 1)
.then(-> utils.delay(ms))
.then(-> fs.writeFileAsync(LED_FILE, 0))
2013-12-23 04:29:48 +00:00
api.post('/v1/blink', (req, res) ->
interval = setInterval(blink, 400)
2013-12-17 06:04:53 +00:00
setTimeout(->
clearInterval(interval)
, 5000)
res.send(200)
)
2013-12-23 04:29:48 +00:00
api.post('/v1/update', (req, res) ->
console.log("Got application update")
application.update()
res.send(204)
)
module.exports = api