diff --git a/daemons/bluetooth/characteristic.js b/daemons/bluetooth/characteristic.js index a9edb72..68cc2a2 100644 --- a/daemons/bluetooth/characteristic.js +++ b/daemons/bluetooth/characteristic.js @@ -1,5 +1,6 @@ var util = require('util'); var spawn = require("child_process").spawn; +var fs = require("fs"); var bleno = require('bleno'); @@ -40,24 +41,35 @@ buttonStream.prototype.onSubscribe = function (maxValueSize, updateValueCallback gpio.on('change', function (channel, value) { if (value) { + var currentTimeStamp = parseInt(new Date().getTime() / 1000).toString(); + + // save currentTimestamp in the db + var savedVideosPath = '/home/Cardigan/modules/video/savedVideos.json' + fs.appendFile(savedVideosPath, ',' + currentTimeStamp, function (err) { + if (err) throw err; + console.log('Saved!'); + }); + // push videoId to app - var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/buttonPress.py"]); - + if (ex){ + var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/standalone.py", "buttonPress"]); - var currentTimeStamp = parseInt(new Date().getTime() / 1000).toString(); - var data = new Buffer(Buffer.byteLength(currentTimeStamp, 'utf8') + 2); + var data = new Buffer(Buffer.byteLength(currentTimeStamp, 'utf8') + 2); - data.writeUInt32LE(currentTimeStamp, 0); + data.writeUInt32LE(currentTimeStamp, 0); - console.log('NotifyOnlyCharacteristic update value: ' + currentTimeStamp); - ex(data); + console.log('NotifyOnlyCharacteristic update value: ' + currentTimeStamp); + ex(data); + }else{ + var process = spawn('python',["/home/Cardigan/modules/indicators/python/states/standalone.py", "buttonPressOffline"]); + } } }); - buttonStream.prototype.onUnsubscribe = function () { this._updateValueCallback = null; + ex = null }; diff --git a/dride-ws b/dride-ws index 263cf1a..3856ce2 160000 --- a/dride-ws +++ b/dride-ws @@ -1 +1 @@ -Subproject commit 263cf1a63bc37b5b808e139641dc5042532899bb +Subproject commit 3856ce213b1b6828721686a3a53199e04bc3f845