1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-23 16:25:19 +03:00

Servo output in Servo tab

This commit is contained in:
Pawel Spychalski (DzikuVx) 2018-05-24 20:28:04 +02:00
parent 3b4c4f00cc
commit f5e60cc40e
7 changed files with 115 additions and 8 deletions

View file

@ -1226,6 +1226,9 @@
"servosReverse": {
"message": "Reverse"
},
"servoOutput": {
"message": "Output"
},
"servosRate": {
"message": "Rate (%)"
},

View file

@ -84,6 +84,7 @@ sources.js = [
'./js/serial.js',
'./js/servoMixRule.js',
'./js/motorMixRule.js',
'./js/outputMapping.js',
'./js/model.js',
'./js/serial_backend.js',
'./js/data_storage.js',

View file

@ -495,7 +495,7 @@ var FC = {
RXFAIL_CONFIG = [];
OUTPUT_MAPPING = [];
OUTPUT_MAPPING = new OutputMappingCollection();
},
getOutputUsages: function() {
return {

View file

@ -1339,9 +1339,9 @@ var mspHelper = (function (gui) {
console.log('OSD preferences saved');
break;
case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING:
OUTPUT_MAPPING = [];
OUTPUT_MAPPING.flush();
for (i = 0; i < data.byteLength; ++i)
OUTPUT_MAPPING.push(data.getUint8(i));
OUTPUT_MAPPING.put(data.getUint8(i));
break;
default:
console.log('Unknown code detected: ' + dataHandler.code);
@ -2546,7 +2546,7 @@ var mspHelper = (function (gui) {
if (semver.gte(CONFIG.flightControllerVersion, '2.0.0'))
MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING, false, false, callback);
else {
OUTPUT_MAPPING = [];
OUTPUT_MAPPING.flush();
return false;
}
};

77
js/outputMapping.js Normal file
View file

@ -0,0 +1,77 @@
/*global bit_check*/
'use strict';
let OutputMappingCollection = function () {
let self = {},
data = [];
const TIM_USE_ANY = 0;
const TIM_USE_PPM = 0;
const TIM_USE_PWM = 1;
const TIM_USE_MC_MOTOR = 2; // Multicopter motor output
const TIM_USE_MC_SERVO = 3; // Multicopter servo output (i.e. TRI)
const TIM_USE_MC_CHNFW = 4; // Deprecated and not used after removal of CHANNEL_FORWARDING feature
const TIM_USE_FW_MOTOR = 5;
const TIM_USE_FW_SERVO = 6;
const TIM_USE_LED = 24;
const TIM_USE_BEEPER = 25;
self.flush = function () {
data = [];
};
self.put = function (element) {
data.push(element);
};
function getFirstOutputOffset() {
for (let i = 0; i < data.length; i++) {
if (
bit_check(data[i], TIM_USE_MC_MOTOR) ||
bit_check(data[i], TIM_USE_MC_SERVO) ||
bit_check(data[i], TIM_USE_FW_MOTOR) ||
bit_check(data[i], TIM_USE_FW_SERVO)
) {
return i;
}
}
return 0;
}
function getOutput(servoIndex, bit) {
let offset = getFirstOutputOffset();
let lastFound = 0;
for (let i = offset; i < data.length; i++) {
if (bit_check(data[i], bit)) {
if (lastFound == servoIndex) {
return i - offset + 1;
} else {
lastFound++;
}
}
}
return null;
}
self.getFwServoOutput = function (servoIndex) {
return getOutput(servoIndex, TIM_USE_FW_SERVO);
};
self.getFwMotorOutput = function (index) {
return getOutput(index, TIM_USE_FW_MOTOR);
};
self.getMrMotorOutput = function (index) {
return getOutput(index, TIM_USE_MC_MOTOR);
};
self.getMrServoOutput = function (index) {
return getOutput(index, TIM_USE_MC_SERVO);
};
return self;
}

View file

@ -1,4 +1,4 @@
/*global $, ServoMixRule*/
/*global ServoMixRule*/
'use strict';
var ServoMixerRuleCollection = function () {

View file

@ -1,4 +1,4 @@
/*global fc,mspHelper,TABS*/
/*global $,fc,mspHelper,TABS*/
'use strict';
TABS.servos = {};
@ -14,6 +14,8 @@ TABS.servos.initialize = function (callback) {
loadChainer.setChain([
mspHelper.loadServoMixRules,
mspHelper.loadServoConfiguration,
mspHelper.loadOutputMapping,
mspHelper.loadMixerConfig,
mspHelper.loadRcData,
mspHelper.loadBfConfig,
]);
@ -74,6 +76,7 @@ TABS.servos.initialize = function (callback) {
<th data-i18n="servosMax"></th>\
<th data-i18n="servosRate"></th>\
<th data-i18n="servosReverse"></th>\
<th data-i18n="servoOutput"></th>\
');
}
@ -118,9 +121,30 @@ TABS.servos.initialize = function (callback) {
}
});
} else {
$currentRow.append('<td class="text-center output"></td>');
let output,
outputString;
if (MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER) {
output = OUTPUT_MAPPING.getMrServoOutput(usedServoIndex);
} else {
output = OUTPUT_MAPPING.getFwServoOutput(usedServoIndex);
}
if (output === null) {
outputString = "-";
} else {
outputString = "S" + output;
}
$currentRow.find('.output').html(outputString);
//For 2.0 and above hide a row when servo is not configured
if (!SERVO_RULES.isServoConfigured(obj)) {
$servoConfigTable.find('tr:last').hide();
$currentRow.hide();
} else {
usedServoIndex++;
}
}
}
@ -154,8 +178,10 @@ TABS.servos.initialize = function (callback) {
// drop previous table
$servoConfigTable.find('tr:not(:first)').remove();
let usedServoIndex = 0;
for (let servoIndex = 0; servoIndex < 8; servoIndex++) {
process_servos('Servo ' + servoIndex, '', servoIndex, false);
process_servos('Servo ' + servoIndex, '', servoIndex);
}
// UI hooks for dynamically generated elements