mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-24 00:35:20 +03:00
adaptive intervals
This commit is contained in:
parent
dc40b96238
commit
37738ac269
12 changed files with 87 additions and 9 deletions
|
@ -77,6 +77,7 @@ GUI_control.prototype.tab_switch_cleanup = function (callback) {
|
|||
MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive
|
||||
|
||||
helper.interval.killAll(['global_data_refresh', 'msp-load-update']);
|
||||
helper.mspBalancedInterval.flush();
|
||||
|
||||
if (this.active_tab) {
|
||||
TABS[this.active_tab].cleanup(callback);
|
||||
|
|
72
js/msp_balanced_interval.js
Normal file
72
js/msp_balanced_interval.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
'use strict';
|
||||
|
||||
var helper = helper || {};
|
||||
|
||||
helper.mspBalancedInterval = (function (mspQueue, intervalHandler) {
|
||||
|
||||
var publicScope = {},
|
||||
privateScope = {};
|
||||
|
||||
/**
|
||||
* How often balancing should be executed [Hz]
|
||||
* @type {number}
|
||||
*/
|
||||
privateScope.balancingFrequency = 0.5;
|
||||
|
||||
privateScope.intervals = [];
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {number} requestedInterval
|
||||
* @param {number} messagesInInterval
|
||||
* @param {function} code
|
||||
*/
|
||||
publicScope.add = function (name, requestedInterval, messagesInInterval, code) {
|
||||
privateScope.intervals.push({
|
||||
name: name,
|
||||
requestedInterval: requestedInterval,
|
||||
messagesInInterval: messagesInInterval,
|
||||
code: code
|
||||
});
|
||||
|
||||
intervalHandler.add(name, code, mspQueue.getIntervalPrediction(requestedInterval, messagesInInterval));
|
||||
};
|
||||
|
||||
/**
|
||||
* Periodically executed balancing handler
|
||||
*/
|
||||
publicScope.balancer = function () {
|
||||
|
||||
var interval;
|
||||
|
||||
for (var i in privateScope.intervals) {
|
||||
if (privateScope.intervals.hasOwnProperty(i)) {
|
||||
interval = privateScope.intervals[i];
|
||||
|
||||
intervalHandler.remove(interval.name);
|
||||
intervalHandler.add(
|
||||
interval.name,
|
||||
interval.code,
|
||||
mspQueue.getIntervalPrediction(
|
||||
interval.requestedInterval,
|
||||
interval.messagesInInterval
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Real interval cleaning happens win helper.interval.killAll method
|
||||
* both methods have to be executed
|
||||
*/
|
||||
publicScope.flush = function () {
|
||||
privateScope.intervals = [];
|
||||
};
|
||||
|
||||
setInterval(publicScope.balancer, Math.round(1000 / privateScope.balancingFrequency));
|
||||
|
||||
return publicScope;
|
||||
})(helper.mspQueue, helper.interval);
|
|
@ -116,6 +116,8 @@ $(document).ready(function () {
|
|||
|
||||
helper.timeout.killAll();
|
||||
helper.interval.killAll(['global_data_refresh', 'msp-load-update']);
|
||||
helper.mspBalancedInterval.flush();
|
||||
|
||||
GUI.tab_switch_cleanup();
|
||||
GUI.tab_switch_in_progress = false;
|
||||
CONFIGURATOR.connectionValid = false;
|
||||
|
|
|
@ -249,14 +249,14 @@ helper.mspQueue = (function (serial, MSP) {
|
|||
};
|
||||
|
||||
/**
|
||||
* This method return periodic for polling interval that should populate queue in 75% or less
|
||||
* This method return periodic for polling interval that should populate queue in 80% or less
|
||||
* @param {number} requestedInterval
|
||||
* @param {number} messagesInInterval
|
||||
* @returns {number}
|
||||
*/
|
||||
publicScope.getIntervalPrediction = function (requestedInterval, messagesInInterval) {
|
||||
var requestedRate = (1000 / requestedInterval) * messagesInInterval,
|
||||
availableRate = (1000 / publicScope.getRoundtrip()) * 0.75;
|
||||
availableRate = (1000 / publicScope.getRoundtrip()) * 0.8;
|
||||
|
||||
if (requestedRate < availableRate) {
|
||||
return requestedInterval;
|
||||
|
|
|
@ -97,6 +97,7 @@
|
|||
<script type="text/javascript" src="./js/eventFrequencyAnalyzer.js"></script>
|
||||
<script type="text/javascript" src="./js/periodicStatusUpdater.js"></script>
|
||||
<script type="text/javascript" src="./js/serial_queue.js"></script>
|
||||
<script type="text/javascript" src="./js/msp_balanced_interval.js"></script>
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
|
|
|
@ -274,7 +274,7 @@ TABS.adjustments.initialize = function (callback) {
|
|||
update_ui();
|
||||
|
||||
// enable data pulling
|
||||
helper.interval.add('aux_data_pull', get_rc_data, helper.mspQueue.getIntervalPrediction(50, 1));
|
||||
helper.mspBalancedInterval.add('aux_data_pull', 50, 1, get_rc_data);
|
||||
|
||||
GUI.content_ready(callback);
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ TABS.auxiliary.initialize = function (callback) {
|
|||
update_ui();
|
||||
|
||||
// enable data pulling
|
||||
helper.interval.add('aux_data_pull', get_rc_data, helper.mspQueue.getIntervalPrediction(50, 1));
|
||||
helper.mspBalancedInterval.add('aux_data_pull', 50, 1, get_rc_data);
|
||||
|
||||
GUI.content_ready(callback);
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ TABS.gps.initialize = function (callback) {
|
|||
* enable data pulling
|
||||
* GPS is usually refreshed at 5Hz, there is no reason to pull it much more often, really...
|
||||
*/
|
||||
helper.interval.add('gps_pull', function gps_update() {
|
||||
helper.mspBalancedInterval.add('gps_pull', 200, 3, function gps_update() {
|
||||
// avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support.
|
||||
if (!have_sensor(CONFIG.activeSensors, 'gps')) {
|
||||
//return;
|
||||
|
@ -114,7 +114,7 @@ TABS.gps.initialize = function (callback) {
|
|||
}
|
||||
|
||||
get_raw_gps_data();
|
||||
}, helper.mspQueue.getIntervalPrediction(200, 3), true);
|
||||
});
|
||||
|
||||
//check for internet connection on load
|
||||
if (navigator.onLine) {
|
||||
|
|
|
@ -88,6 +88,7 @@ TABS.logging.initialize = function (callback) {
|
|||
}
|
||||
} else {
|
||||
helper.interval.killAll(['global_data_refresh', 'msp-load-update']);
|
||||
helper.mspBalancedInterval.flush();
|
||||
|
||||
$('.speed').prop('disabled', false);
|
||||
$(this).text(chrome.i18n.getMessage('loggingStart'));
|
||||
|
|
|
@ -236,6 +236,7 @@ TABS.motors.initialize = function (callback) {
|
|||
|
||||
// timer initialization
|
||||
helper.interval.killAll(['motor_and_status_pull', 'global_data_refresh', 'msp-load-update']);
|
||||
helper.mspBalancedInterval.flush();
|
||||
|
||||
helper.interval.add('IMU_pull', function imu_data_pull() {
|
||||
|
||||
|
|
|
@ -460,7 +460,7 @@ TABS.receiver.initialize = function (callback) {
|
|||
samples++;
|
||||
}
|
||||
|
||||
helper.interval.add('receiver_pull', get_rc_data, helper.mspQueue.getIntervalPrediction(35, 1), true);
|
||||
helper.mspBalancedInterval.add('receiver_pull', 35, 1, get_rc_data);
|
||||
|
||||
GUI.content_ready(callback);
|
||||
}
|
||||
|
|
|
@ -179,8 +179,8 @@ TABS.setup.initialize = function (callback) {
|
|||
});
|
||||
}
|
||||
|
||||
helper.interval.add('setup_data_pull_fast', get_fast_data, helper.mspQueue.getIntervalPrediction(40, 1), true); // 25 fps
|
||||
helper.interval.add('setup_data_pull_slow', get_slow_data, helper.mspQueue.getIntervalPrediction(250, 1), true); // 4 fps
|
||||
helper.mspBalancedInterval.add('setup_data_pull_fast', 40, 1, get_fast_data);
|
||||
helper.mspBalancedInterval.add('setup_data_pull_slow', 250, 1, get_slow_data);
|
||||
|
||||
helper.interval.add('gui_analog_update', function () {
|
||||
bat_voltage_e.text(chrome.i18n.getMessage('initialSetupBatteryValue', [ANALOG.voltage]));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue