1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

removal of char_counter, new port_usage, i18n

added bitrate to serial object, removed last bits of 'port_handler'
interval code forgotten in the kill routines, new port_usage is now
saved in a separate file
This commit is contained in:
cTn 2014-03-29 00:59:39 +01:00
parent 241b44e893
commit 58d43c381b
11 changed files with 73 additions and 27 deletions

View file

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

View file

@ -51,9 +51,6 @@ var MSP_codes = {
MSP_GPSSVINFO: 164 // get Signal Strength (only U-Blox)
};
var char_counter = 0; // this need to be redone or removed
var MSP = {
state: 0,
message_status: 1,
@ -155,8 +152,6 @@ MSP.read = function(readInfo) {
this.state = 0;
break;
}
char_counter++;
}
};

32
js/port_usage.js Normal file
View file

@ -0,0 +1,32 @@
var PortUsage = {
previous_received: 0,
previous_sent: 0,
initialize: function() {
var self = this;
self.main_timer_reference = setInterval(function() {
self.update();
}, 1000);
},
update: function() {
if (serial.bitrate) {
var port_usage_down = parseInt(((serial.bytes_received - this.previous_received) * 10 / serial.bitrate) * 100);
var port_usage_up = parseInt(((serial.bytes_sent - this.previous_sent) * 10 / serial.bitrate) * 100);
this.previous_received = serial.bytes_received;
this.previous_sent = serial.bytes_sent;
// update UI
$('span.port_usage_down').text(chrome.i18n.getMessage('statusbar_usage_download', [port_usage_down]));
$('span.port_usage_up').text(chrome.i18n.getMessage('statusbar_usage_upload', [port_usage_up]));
}
},
reset: function() {
this.previous_received = 0;
this.previous_sent = 0;
$('span.port_usage_down').text(chrome.i18n.getMessage('statusbar_usage_download', [0]));
$('span.port_usage_up').text(chrome.i18n.getMessage('statusbar_usage_upload', [0]));
}
};

View file

@ -1,10 +1,11 @@
var serial = {
connectionId: -1,
connectionId: -1,
bitrate: 0,
bytes_received: 0,
bytes_sent: 0,
bytes_sent: 0,
transmitting: false,
output_buffer: [],
transmitting: false,
output_buffer: [],
connect: function(path, options, callback) {
var self = this;
@ -12,6 +13,7 @@ var serial = {
chrome.serial.connect(path, options, function(connectionInfo) {
if (connectionInfo !== undefined) {
self.connectionId = connectionInfo.connectionId;
self.bitrate = connectionInfo.bitrate;
self.bytes_received = 0;
self.bytes_sent = 0;
@ -48,6 +50,7 @@ var serial = {
console.log('SERIAL: Statistics - Sent: ' + self.bytes_sent + ' bytes, Received: ' + self.bytes_received + ' bytes');
self.connectionId = -1;
self.bitrate = 0;
callback(result);
});

View file

@ -32,11 +32,11 @@ $(document).ready(function() {
GUI.connected_to = false;
// Reset various UI elements
$('span.port-usage').html('0%');
$('.software-version').html('0.0');
$('span.cycle-time').html('0');
MSP.disconnect_cleanup();
PortUsage.reset();
configuration_received = false; // reset valid config received variable (used to block tabs while not connected properly)
// unlock port select & baud
@ -109,7 +109,9 @@ $(document).ready(function() {
chrome.storage.local.set({'auto_connect': GUI.auto_connect});
});
});
PortHandler.initialize();
PortUsage.initialize();
});
function onOpen(openInfo) {
@ -142,7 +144,6 @@ function onOpen(openInfo) {
});
serial.onReceive.addListener(read_serial);
GUI.interval_add('port_usage', port_usage, 1000, true);
// disconnect after 10 seconds with error if we don't get IDENT data
GUI.timeout_add('connecting', function() {
@ -203,14 +204,6 @@ function read_serial(info) {
}
}
function port_usage() {
var port_usage = (char_counter * 10 / parseInt($('div#port-picker #baud').val())) * 100;
$('span.port-usage').html(parseInt(port_usage) + '%');
// reset counter
char_counter = 0;
}
function sensor_status(sensors_detected) {
// initialize variable (if it wasn't)
if (typeof sensor_status.previous_sensors_detected == 'undefined') {

View file

@ -616,6 +616,8 @@ STM32_protocol.prototype.upload_procedure = function(step) {
} else { // Something went wrong
}
PortUsage.reset();
// unlocking connect button
GUI.connect_lock = false;
});