2014-08-09 17:38:46 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-03-28 23:59:39 +00:00
|
|
|
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) {
|
2014-11-22 05:31:46 +00:00
|
|
|
var port_usage_down = parseInt(((serial.bytesReceived - this.previous_received) * 10 / serial.bitrate) * 100);
|
|
|
|
var port_usage_up = parseInt(((serial.bytesSent - this.previous_sent) * 10 / serial.bitrate) * 100);
|
2014-03-28 23:59:39 +00:00
|
|
|
|
2014-11-22 05:31:46 +00:00
|
|
|
this.previous_received = serial.bytesReceived;
|
|
|
|
this.previous_sent = serial.bytesSent;
|
2014-03-28 23:59:39 +00:00
|
|
|
|
|
|
|
// 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]));
|
2014-05-15 11:47:05 +00:00
|
|
|
} else {
|
|
|
|
$('span.port_usage_down').text(chrome.i18n.getMessage('statusbar_usage_download', [0]));
|
|
|
|
$('span.port_usage_up').text(chrome.i18n.getMessage('statusbar_usage_upload', [0]));
|
2014-03-28 23:59:39 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
reset: function() {
|
|
|
|
this.previous_received = 0;
|
|
|
|
this.previous_sent = 0;
|
|
|
|
}
|
|
|
|
};
|