From 5f71e48c385973e8ad46e4c3812f9fe00c6c77a7 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Thu, 8 Feb 2018 15:31:48 -0500 Subject: [PATCH] Restart, update and reset all have ble and restify endpoints --- app/www/static/js/intval.mobile.js | 18 ++++++++++++- index.js | 42 +++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/app/www/static/js/intval.mobile.js b/app/www/static/js/intval.mobile.js index 4f26c42..26990a8 100644 --- a/app/www/static/js/intval.mobile.js +++ b/app/www/static/js/intval.mobile.js @@ -618,9 +618,25 @@ mobile.resetSuccess = function () { }; mobile.update = function () { - + const reset = confirm(`Check for updates? You will be disconnected from the INTVAL3 during this process.`); + if (!reset) return false; + let opts = { + type : 'reset' + }; + ble.write(mobile.ble.device.id, + mobile.ble.SERVICE_ID, + mobile.ble.CHAR_ID, + stringToBytes(JSON.stringify(opts)), + mobile.updateSuccess, + mobile.ble.onError); }; +mobile.updateSuccess = function () { + alert() +}; + +mobile.restart = function () {} + /** * Mobile helper functions */ diff --git a/index.js b/index.js index 2ac5532..f342427 100644 --- a/index.js +++ b/index.js @@ -38,8 +38,12 @@ function createServer () { app.get( '/sequence', rSequence) app.post('/sequence', rSequence) - app.post('/reset', rReset) app.get( '/status', rStatus) + app.post('/reset', rReset) + app.get('/update', rUpdate) + app.get('/restart', rRestart) + + app.listen(PORT, () => { log.info('server', { name : APPNAME, port : PORT }) }) @@ -55,7 +59,10 @@ function createBLE () { ble.on('delay', bDelay) ble.on('counter', bCounter) ble.on('sequence', bSequence) + ble.on('reset', bReset) + ble.on('update', bUpdate) + ble.on('restart', bRestart) } //Restify functions @@ -337,6 +344,18 @@ function rSequence (req, res, next) { } } +function rUpdate (req, res, next) { + exec('sh ./scripts/update.sh', (err, stdio, stderr) => { + res.send({ success : true }) + process.exit(0) + }) +} + +function rRestart (req, res, next) { + res.send({ success : true }) + process.exit(0) +} + //Ble functions function bFrame (obj, cb) { @@ -509,6 +528,21 @@ function bReset (obj, cb) { setTimeout(cb, 10) } +function bUpdate (obj, cb) { + cb() + setTimeout(() => { + exec('sh ./scripts/update.sh', (err, stdio, stderr) => { + process.exit(0) + }) + }, 20) +} +function bRestart (obj, cb) { + cb() + setTimeout(() => { + process.exit(0) + }, 20) +} + function seq () { let dir = intval._state.frame.dir let exposure = intval._state.frame.exposure @@ -539,12 +573,6 @@ function seq () { } } -function update (req, res, next) { - exec('sh ./scripts/update.sh', (err, stdio, stderr) => { - process.exit() - }) -} - function index (req, res, next) { fs.readFile(INDEXPATH, 'utf8', (err, data) => { if (err) {