-
-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from bitfocus/master
Update CWD
- Loading branch information
Showing
14 changed files
with
463 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule neodarque-stagetimer2
added at
47c13c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.