2013-12-23 04:22:54 +00:00
|
|
|
Promise = require 'bluebird'
|
|
|
|
fs = Promise.promisifyAll require 'fs'
|
|
|
|
utils = require './utils'
|
2013-12-14 05:18:20 +00:00
|
|
|
express = require 'express'
|
2013-12-29 18:07:58 +00:00
|
|
|
application = require './application'
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
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)
|
2014-03-19 19:54:39 +00:00
|
|
|
.then -> utils.delay(ms)
|
|
|
|
.then -> fs.writeFileAsync(LED_FILE, 0)
|
2013-12-14 05:18:20 +00:00
|
|
|
|
2014-03-19 19:54:39 +00:00
|
|
|
api.post '/v1/blink', (req, res) ->
|
2013-12-14 05:18:20 +00:00
|
|
|
interval = setInterval(blink, 400)
|
2013-12-17 06:04:53 +00:00
|
|
|
setTimeout(->
|
|
|
|
clearInterval(interval)
|
|
|
|
, 5000)
|
2013-12-14 05:18:20 +00:00
|
|
|
res.send(200)
|
|
|
|
|
2014-03-19 19:54:39 +00:00
|
|
|
api.post '/v1/update', (req, res) ->
|
2013-12-29 18:07:58 +00:00
|
|
|
console.log("Got application update")
|
|
|
|
application.update()
|
2013-12-23 04:31:33 +00:00
|
|
|
res.send(204)
|
2013-12-14 05:18:20 +00:00
|
|
|
|
|
|
|
module.exports = api
|