77 lines
1.5 KiB
JavaScript
77 lines
1.5 KiB
JavaScript
/**
|
|
* Created by Martin on 10/02/2016.
|
|
*/
|
|
'use strict';
|
|
/**
|
|
* Created by Martin on 09/02/2016.
|
|
*/
|
|
|
|
var mqttConnect;
|
|
|
|
function doProjectorOn() {
|
|
console.log('+ projector_v1 / doProjectorOn');
|
|
mqttConnect.doConnection().projectorOn();
|
|
}
|
|
|
|
function doProjectorOff() {
|
|
console.log('+ projector_v1 / doProjectorOff');
|
|
mqttConnect.doConnection().projectorOff();
|
|
}
|
|
|
|
function setUseRef(ref) {
|
|
mqttConnect = ref;
|
|
}
|
|
|
|
function doProjectorCommand(id) {
|
|
console.log('doProjectorCommand', id);
|
|
mqttConnect.doConnection().projectorCmd(id);
|
|
}
|
|
|
|
module.exports = {
|
|
mqttConnect: null,
|
|
socket: null,
|
|
use: function(ref) {
|
|
setUseRef(ref);
|
|
},
|
|
turnoff: function(req, res) {
|
|
doProjectorOff();
|
|
res.json({});
|
|
},
|
|
turnon: function(req, res) {
|
|
doProjectorOn();
|
|
res.json({});
|
|
},
|
|
setsocket: function(socket) {
|
|
this.socket = socket;
|
|
return this;
|
|
},
|
|
command: function(req, res) {
|
|
|
|
if (!req.body.id) {
|
|
res.status(400).send({
|
|
status: 'error',
|
|
error: 'missing required parameter'
|
|
});
|
|
return;
|
|
}
|
|
|
|
console.log(req.body.id);
|
|
|
|
if (req.body.hasOwnProperty('id')) {
|
|
var id = req.body.id;
|
|
doProjectorCommand(id);
|
|
}
|
|
|
|
res.json({});
|
|
},
|
|
subscribe: function(socket) {
|
|
this.socket.subscribe('Projector','ProjectorDataReceived');
|
|
},
|
|
doProjectorOn: function() {
|
|
doProjectorOn();
|
|
}, doProjectorOff: function() {
|
|
doProjectorOff();
|
|
}
|
|
};
|
|
|