1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-14 11:59:51 +03:00

major port handler rework

This commit is contained in:
cTn 2014-02-21 21:12:19 +01:00
parent 801ed36fd7
commit 38d6a80ae2
3 changed files with 115 additions and 108 deletions

View file

@ -226,7 +226,7 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
});
break;
case 'sensors':
GUI.interval_kill_all(['port_handler', 'port_usage']);
GUI.interval_kill_all(['port_usage']);
serial.empty_output_buffer();
// sensor data tab uses scrollbars, emptying the content before loading another tab

View file

@ -1,4 +1,5 @@
function port_handler() {
this.main_timeout_reference;
this.initial_ports = false;
this.port_detected_callbacks = [];
@ -6,10 +7,13 @@ function port_handler() {
}
port_handler.prototype.initialize = function() {
// start listening, check after 250ms
this.check();
};
port_handler.prototype.check = function() {
var self = this;
// 250ms refresh interval, fire instantly after creation
GUI.interval_add('port_handler', function() {
serial.getDevices(function(current_ports) {
// port got removed or initial_ports wasn't initialized yet
if (self.array_difference(self.initial_ports, current_ports).length > 0 || !self.initial_ports) {
@ -41,7 +45,7 @@ port_handler.prototype.initialize = function() {
var obj = self.port_removed_callbacks[i];
// remove timeout
GUI.timeout_remove(obj.name);
clearTimeout(obj.timer);
// trigger callback
obj.code(removed_ports);
@ -111,7 +115,7 @@ port_handler.prototype.initialize = function() {
var obj = self.port_detected_callbacks[i];
// remove timeout
GUI.timeout_remove(obj.name);
clearTimeout(obj.timer);
// trigger callback
obj.code(new_ports);
@ -120,8 +124,11 @@ port_handler.prototype.initialize = function() {
self.initial_ports = current_ports;
}
self.main_timeout_reference = setTimeout(function() {
self.check();
}, 250);
});
}, 250, true);
};
port_handler.prototype.update_port_select = function(ports) {
@ -141,7 +148,7 @@ port_handler.prototype.port_detected = function(name, code, timeout) {
var obj = {'name': name, 'code': code, 'timeout': timeout, 'timer': false};
if (timeout) {
obj.timer = GUI.timeout_add(name, function() {
obj.timer = setTimeout(function() {
console.log('PortHandler - port detected timeout triggered - ' + obj.name);
// trigger callback
@ -149,7 +156,7 @@ port_handler.prototype.port_detected = function(name, code, timeout) {
// reset callback array
self.port_detected_callbacks = [];
}, timeout).timer;
}, timeout);
}
this.port_detected_callbacks.push(obj);
@ -160,7 +167,7 @@ port_handler.prototype.port_removed = function(name, code, timeout) {
var obj = {'name': name, 'code': code, 'timeout': timeout, 'timer': false};
if (timeout) {
obj.timer = GUI.timeout_add(name, function() {
obj.timer = setTimeout(function() {
console.log('PortHandler - port removed timeout triggered - ' + obj.name);
// trigger callback
@ -168,7 +175,7 @@ port_handler.prototype.port_removed = function(name, code, timeout) {
// reset callback array
self.port_removed_callbacks = [];
}, timeout).timer;
}, timeout);
}
this.port_removed_callbacks.push(obj);

View file

@ -22,7 +22,7 @@ $(document).ready(function() {
serial.connect(selected_port, {bitrate: selected_baud}, onOpen);
} else {
// Disable any active "data pulling" timer
GUI.interval_kill_all(['port_handler']);
GUI.interval_kill_all();
GUI.tab_switch_cleanup();
GUI.timeout_remove('connecting');