mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-14 20:10:11 +03:00
corrections of inline functions
This commit is contained in:
parent
20e6ad0074
commit
f16b3a479a
2 changed files with 45 additions and 46 deletions
|
@ -158,7 +158,6 @@ MSP.read = function (readInfo) {
|
||||||
};
|
};
|
||||||
|
|
||||||
MSP.process_data = function(code, message_buffer, message_length) {
|
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)
|
var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union)
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
|
90
js/serial.js
90
js/serial.js
|
@ -27,30 +27,30 @@ var serial = {
|
||||||
console.error(info);
|
console.error(info);
|
||||||
googleAnalytics.sendException('Serial: ' + info.error, false);
|
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) {
|
switch (info.error) {
|
||||||
case 'system_error': // we might be able to recover from this one
|
case 'system_error': // we might be able to recover from this one
|
||||||
chrome.serial.setPaused(self.connectionId, false, get_status);
|
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;
|
break;
|
||||||
case 'timeout':
|
case 'timeout':
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -127,33 +127,33 @@ var serial = {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.output_buffer.push({'data': data, 'callback': callback});
|
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) {
|
if (!self.transmitting) {
|
||||||
self.transmitting = true;
|
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();
|
sending();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue