corrections of inline functions
parent
20e6ad0074
commit
f16b3a479a
|
@ -158,7 +158,6 @@ MSP.read = function (readInfo) {
|
|||
};
|
||||
|
||||
MSP.process_data = function(code, message_buffer, message_length) {
|
||||
'use strict';
|
||||
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
||||
|
||||
switch (code) {
|
||||
|
|
90
js/serial.js
90
js/serial.js
|
@ -27,30 +27,30 @@ var serial = {
|
|||
console.error(info);
|
||||
googleAnalytics.sendException('Serial: ' + info.error, false);
|
||||
|
||||
function get_status() {
|
||||
self.getInfo(crunch_status);
|
||||
}
|
||||
|
||||
function crunch_status(info) {
|
||||
if (!info.paused) {
|
||||
console.log('SERIAL: Connection recovered from last onReceiveError');
|
||||
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
||||
} else {
|
||||
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
||||
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
||||
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
||||
|
||||
if (GUI.connected_to || GUI.connecting_to) {
|
||||
$('a.connect').click();
|
||||
} else {
|
||||
self.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (info.error) {
|
||||
case 'system_error': // we might be able to recover from this one
|
||||
chrome.serial.setPaused(self.connectionId, false, get_status);
|
||||
|
||||
var get_status = function () {
|
||||
self.getInfo(crunch_status);
|
||||
}
|
||||
|
||||
var crunch_status = function (info) {
|
||||
if (!info.paused) {
|
||||
console.log('SERIAL: Connection recovered from last onReceiveError');
|
||||
googleAnalytics.sendException('Serial: onReceiveError - recovered', false);
|
||||
} else {
|
||||
console.log('SERIAL: Connection did not recover from last onReceiveError, disconnecting');
|
||||
GUI.log('Unrecoverable <span style="color: red">failure</span> of serial connection, disconnecting...');
|
||||
googleAnalytics.sendException('Serial: onReceiveError - unrecoverable', false);
|
||||
|
||||
if (GUI.connected_to || GUI.connecting_to) {
|
||||
$('a.connect').click();
|
||||
} else {
|
||||
self.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'timeout':
|
||||
// TODO
|
||||
|
@ -127,33 +127,33 @@ var serial = {
|
|||
var self = this;
|
||||
self.output_buffer.push({'data': data, 'callback': callback});
|
||||
|
||||
function sending() {
|
||||
// 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();
|
||||
|
||||
self.bytes_sent += sendInfo.bytesSent;
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!self.transmitting) {
|
||||
self.transmitting = true;
|
||||
|
||||
var sending = function () {
|
||||
// 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();
|
||||
|
||||
self.bytes_sent += sendInfo.bytesSent;
|
||||
|
||||
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;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
sending();
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue