Skip to content

Commit

Permalink
Merge pull request #1 from bitfocus/master
Browse files Browse the repository at this point in the history
Update CWD
  • Loading branch information
krocheck committed Dec 23, 2018
2 parents c328665 + affcb62 commit 5ad2e39
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,6 @@
[submodule "lib/module/cockos-reaper"]
path = lib/module/cockos-reaper
url = https://github.com/bitfocus/companion-module-cockos-reaper.git
[submodule "lib/module/neodarque-stagetimer2"]
path = lib/module/neodarque-stagetimer2
url = https://github.com/bitfocus/companion-module-neodarque-stagetimer2.git
8 changes: 6 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ system.on('skeleton-start-minimised', function(minimised) {

system.on('skeleton-ready', function() {

var http = require('./lib/http')(system);
var io = require('./lib/io')(system, http);
var server_http= require('./lib/server_http')(system);
var io = require('./lib/io')(system, server_http);
var log = require('./lib/log')(system,io);
var db = require('./lib/db')(system,cfgDir);
var userconfig = require('./lib/userconfig')(system)
Expand All @@ -108,8 +108,12 @@ system.on('skeleton-ready', function() {
var action = require('./lib/action')(system);
var instance = require('./lib/instance')(system);
var osc = require('./lib/osc')(system);
var server_api = require('./lib/server_api')(system);
var server_tcp = require('./lib/server_tcp')(system);
var server_udp = require('./lib/server_udp')(system);
var artnet = require('./lib/artnet')(system);
var rest = require('./lib/rest')(system);
var rest_poll = require('./lib/rest_poll')(system);
var loadsave = require('./lib/loadsave')(system);
var preset = require('./lib/preset')(system);
var tablet = require('./lib/tablet')(system);
Expand Down
25 changes: 24 additions & 1 deletion lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,29 @@ function device(_system, panel) {

system.on('elgato_ready',self.on_elgato_ready);

system.on('device_set_page', function (deviceid, page) {
system.on('device_page_set', function (deviceid, page) {
if (self.panel.serialnumber == deviceid) {
self.page = page;
if (self.page == 100) { self.page = 1; }
if (self.page == 0) { self.page = 99; }
self.updatePagedevice();
}
});

system.on('device_page_down', function (deviceid) {
if (self.panel.serialnumber == deviceid) {
self.page--;
if (self.page == 100) { self.page = 1; }
if (self.page == 0) { self.page = 99; }
self.updatePagedevice();
}
});

system.on('device_page_up', function (deviceid) {
if (self.panel.serialnumber == deviceid) {
self.page++;
if (self.page == 100) { self.page = 1; }
if (self.page == 0) { self.page = 99; }
self.updatePagedevice();
}
});
Expand All @@ -135,6 +152,12 @@ function device(_system, panel) {
self.updatePagedevice();
}

// Home button function
if (key == 5) {
self.page = 1;
self.updatePagedevice();
}

if (bank_map[key] !== undefined) {
system.emit('bank-pressed', self.page, bank_map[key], true, self.panel.serialnumber);
system.emit('log', 'device('+self.panel.serialnumber+')', 'debug', 'Button '+self.page+'.' + bank_map[key] + ' pressed');
Expand Down
2 changes: 1 addition & 1 deletion lib/module/bitfocus-companion
Submodule bitfocus-companion updated 1 files
+1 −1 index.js
1 change: 1 addition & 0 deletions lib/module/neodarque-stagetimer2
Submodule neodarque-stagetimer2 added at 47c13c
2 changes: 0 additions & 2 deletions lib/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function rest(system) {
};

client.get(url, function (data, response) {
debug('success response:', data, response);
cb(null, { data: data, response: response });
}).on('error', function(error) {
debug('error response:', error);
Expand All @@ -54,7 +53,6 @@ function rest(system) {
};

client.post(url, args, function (data, response) {
debug('success response:', data, response);
cb(null, { data: data, response: response });
}).on('error', function(error) {
debug('error response:', error);
Expand Down
120 changes: 120 additions & 0 deletions lib/rest_poll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* This file is part of the Companion project
* Copyright (c) 2018 Bitfocus AS
* Authors: William Viker <william@bitfocus.io>, Håkon Nessjøen <haakon@bitfocus.io>
*
* This program is free software.
* You should have received a copy of the MIT licence as well as the Bitfocus
* Individual Contributor License Agreement for companion along with
* this program.
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial activities involving the Companion software without
* disclosing the source code of your own applications.
*
*/

var debug = require('debug')('lib/rest_poll');
var shortid = require('shortid');

function rest_poll(system) {
var self = this;

self.running = {};

system.on('rest_poll', function(instance_id, interval, url, data, poll_obj_cb, result_cb) {
var poll_id = shortid.generate();

if (self.running[instance_id] === undefined) {
self.running[instance_id] = {};
}

self.running[instance_id][poll_id] = {
instance: instance_id,
id: poll_id,
interval: interval,
url: url,
type: 'post',
waiting: false,
data: data,
result_cb: result_cb,
timer: setInterval(function(instance_id, poll_id) {
var obj = self.running[instance_id][poll_id];
if (obj.waiting === true) {
debug("Skipping this cycle for",poll_id);
}
else {
system.emit('rest', obj.url, obj.data, function(err, res) {
debug("got reply for",obj.id,obj.url);
obj.waiting = false;
obj.result_cb(err, res);
});
}
}.bind(null, instance_id, poll_id), interval)
};

poll_obj_cb(null, self.running[instance_id][poll_id]);

console.log("Rest poll added", self.running);

});

system.on('rest_poll_get', function(instance_id, interval, url, poll_obj_cb, result_cb) {
var poll_id = shortid.generate();

if (self.running[instance_id] === undefined) {
self.running[instance_id] = {};
}

self.running[instance_id][poll_id] = {
instance: instance_id,
id: poll_id,
type: 'get',
interval: interval,
url: url,
waiting: false,
result_cb: result_cb,
timer: setInterval(function(instance_id, poll_id) {
var obj = self.running[instance_id][poll_id];
if (obj.waiting === true) {
debug("Skipping this cycle for",poll_id);
}
else {
system.emit('rest_get', obj.url, function(err, res) {
debug("got reply for",obj.id,obj.url);
obj.waiting = false;
obj.result_cb(err, res);
});
}
}.bind(null, instance_id, poll_id), interval)
};

poll_obj_cb(null, self.running[instance_id][poll_id]);

console.log("Rest poll added", self.running);

});



system.on('rest_poll_destroy', function(instance_id) {
debug("Clearing poll intervals for",instance_id);
if (self.running[instance_id] !== undefined) {
for (var poll_id in self.running[instance_id]) {
var poll = self.running[instance_id][poll_id];
if (poll.timer !== undefined) {
debug("Killing interval for",poll.instance,poll.url);
clearInterval(poll.timer);
delete self.running[instance_id][poll_id];
}
}
}
});

return self;
}

exports = module.exports = function (system) {
return new rest_poll(system);
};
100 changes: 100 additions & 0 deletions lib/server_api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* This file is part of the Companion project
* Copyright (c) 2018 Bitfocus AS
* Authors: William Viker <william@bitfocus.io>, Håkon Nessjøen <haakon@bitfocus.io>
*
* This program is free software.
* You should have received a copy of the MIT licence as well as the Bitfocus
* Individual Contributor License Agreement for companion along with
* this program.
*
* You can be released from the requirements of the license by purchasing
* a commercial license. Buying such a license is mandatory as soon as you
* develop commercial activities involving the Companion software without
* disclosing the source code of your own applications.
*
*/

var debug = require('debug')('lib/server_api');
var net = require('net');

function server_api(system) {

var self = this;

system.on('server_api_command', function(data, response_cb) {

debug("API parsing command:",data.trim());
var command = data.toString();
var match;

if (match = command.match(/^page-set (\d+) ([a-z0-9]{3,32})\n?$/i)) {
var page = parseInt(match[1]);
var deviceid = match[2];
system.emit('device_page_set', deviceid, page);
response_cb(null, "+OK Probably?");
}

else if (match = command.match(/^page-up ([a-z0-9]{3,32})\n?$/i)) {
var page = parseInt(match[1]);
var deviceid = match[2];
system.emit('device_page_up', deviceid);
response_cb(null, "+OK Probably?");
}

else if (match = command.match(/^page-down ([a-z0-9]{3,32})\n?$/i)) {
var page = parseInt(match[1]);
var deviceid = match[2];
system.emit('device_page_down', deviceid);
response_cb(null, "+OK Probably?");
}

else if (match = command.match(/^(bank-press|bank-up|bank-down) (\d+) (\d+)\n?$/i)) {

var func = match[1].toLowerCase();
var page = parseInt(match[2]);
var bank = parseInt(match[3]);

if (page > 0 && page <= 99 && bank > 0 && bank <= 15) {
system.emit('log', 'TCP Server', 'debug', func + ': ' + page + "." + bank);

if (func == 'bank-press') {

debug("Got /press/bank/ (trigger)",page,"button",bank);
system.emit('bank-pressed', page, bank, true);

setTimeout(function (){
debug("Auto releasing /press/bank/ (trigger)",page,"button",bank);
system.emit('bank-pressed', page, bank, false);
}, 20);

}

else if (func == 'bank-down') {
system.emit('bank-pressed', page, bank, true);
}

else if (func == 'bank-up') {
system.emit('bank-pressed', page, bank, false);
}

response_cb(null, "+OK");
}

else {
response_cb(true, "-ERR Page/bank out of range");
}

}

else {
response_cb(true, "-ERR Syntax error");
}

});
};


exports = module.exports = function (system) {
return new server_api(system);
};
10 changes: 5 additions & 5 deletions lib/http.js → lib/server_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var express = Express();
var _http = require('http');
var util = require('util');
var fs = require('fs');
var debug = require('debug')('lib/http');
var debug = require('debug')('lib/server_http');
var path = require('path');

var system;
Expand Down Expand Up @@ -58,7 +58,7 @@ express.use('/js/moment', Express.static(require('app-root-path') + '/node_modul

require('app-root-path') + '';

function http(system) {
function server_http(system) {
var self = this;

_http.Server.call(self, express);
Expand Down Expand Up @@ -146,9 +146,9 @@ function http(system) {
return self;

}
util.inherits(http, _http.Server);
util.inherits(server_http, _http.Server);

http.prototype.log = function () {
server_http.prototype.log = function () {
var self = this;
var args = Array.prototype.slice.call(arguments);
args.unshift('log', 'http');
Expand All @@ -159,5 +159,5 @@ http.prototype.log = function () {
//exports = module.exports = http;

exports = module.exports = function (system) {
return new http(system);
return new server_http(system);
};
Loading

0 comments on commit 5ad2e39

Please sign in to comment.