adding method to empty send buffer, limits

10.3.x-maintenance
cTn 2014-01-26 21:37:19 +01:00
parent c7dae0f5e3
commit c389a71ece
3 changed files with 18 additions and 4 deletions

View File

@ -204,7 +204,8 @@ GUI_control.prototype.tab_switch_cleanup = function(callback) {
if (callback) callback();
break;
case 'sensors':
GUI.interval_kill_all(['port-update', 'port_usage', 'serial_read']);
GUI.interval_kill_all(['port-update', 'port_usage']);
serial.empty_output_buffer();
// sensor data tab uses scrollbars, emptying the content before loading another tab
// prevents scrollbar exposure to any of the tabs while new content is loaded in

View File

@ -59,11 +59,20 @@ var serial = {
self.transmitting = true;
var sending = function() {
chrome.serial.send(self.connectionId, self.output_buffer[0].data, function(sendInfo) {
self.output_buffer[0].callback(sendInfo);
// store inside separate variables in case array gets destroyed
var data = self.output_buffer[0].data;
var callback = self.output_buffer[0].callback;
chrome.serial.send(self.connectionId, data, function(sendInfo) {
callback(sendInfo);
self.output_buffer.shift();
if (self.output_buffer.length) {
// keep the buffer withing reasonable limits
while (self.output_buffer.length > 500) {
self.output_buffer.pop();
}
sending();
} else {
self.transmitting = false;
@ -83,5 +92,9 @@ var serial = {
removeListener: function(function_reference) {
chrome.serial.onReceive.removeListener(function_reference);
}
},
empty_output_buffer: function() {
this.output_buffer = [];
this.transmitting = false;
}
};

View File

@ -209,7 +209,7 @@ function tab_initialize_sensors() {
}
// timer initialization
GUI.interval_kill_all(['port-update', 'port_usage', 'serial_read']);
GUI.interval_kill_all(['port-update', 'port_usage']);
// data pulling timers
GUI.interval_add('status_pull', function() {