Merge pull request #1820 from iNavFlight/mmosca-smarter-pwm-assignment

Smarter pwm timer allocation, configurator changes
pull/1822/head
Marcelo Bezerra 1 year ago committed by GitHub
commit dae2b82f65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4491,7 +4491,7 @@
"message": "This will reset all PID settings to firmware default values and save.\nDo you want to continue?"
},
"mappingTableOutput": {
"message": "Output"
"message": "Output (timer)"
},
"mappingTableFunction": {
"message": "Function"
@ -5474,5 +5474,8 @@
},
"targetPrefetchFailNoPort": {
"message": "Cannot prefetch target: No port"
},
"timerOutputs": {
"message": "Timer outputs"
}
}

@ -180,6 +180,11 @@ var MSPCodes = {
MSPV2_INAV_SET_RATE_PROFILE: 0x2008,
MSPV2_INAV_AIR_SPEED: 0x2009,
MSPV2_INAV_OUTPUT_MAPPING: 0x200A,
MSP2_INAV_MC_BRAKING: 0x200B,
MSP2_INAV_SET_MC_BRAKING: 0x200C,
MSPV2_INAV_OUTPUT_MAPPING_EXT: 0x200D,
MSP2_INAV_TIMER_OUTPUT_MODE: 0x200E,
MSP2_INAV_SET_TIMER_OUTPUT_MODE: 0x200F,
MSP2_INAV_MIXER: 0x2010,
MSP2_INAV_SET_MIXER: 0x2011,
@ -191,9 +196,6 @@ var MSPCodes = {
MSP2_INAV_OSD_PREFERENCES: 0x2016,
MSP2_INAV_OSD_SET_PREFERENCES: 0x2017,
MSP2_INAV_MC_BRAKING: 0x200B,
MSP2_INAV_SET_MC_BRAKING: 0x200C,
MSP2_INAV_SELECT_BATTERY_PROFILE: 0x2018,
MSP2_INAV_DEBUG: 0x2019,
@ -217,6 +219,7 @@ var MSPCodes = {
MSP2_INAV_SET_PROGRAMMING_PID: 0x2029,
MSP2_INAV_PROGRAMMING_PID_STATUS: 0x202A,
MSP2_PID: 0x2030,
MSP2_SET_PID: 0x2031,

@ -1482,7 +1482,32 @@ var mspHelper = (function (gui) {
case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING:
OUTPUT_MAPPING.flush();
for (i = 0; i < data.byteLength; ++i)
OUTPUT_MAPPING.put(data.getUint8(i));
OUTPUT_MAPPING.put({
'timerId': i,
'usageFlags': data.getUint8(i)});
break;
case MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT:
OUTPUT_MAPPING.flush();
for (i = 0; i < data.byteLength; i += 2) {
timerId = data.getUint8(i);
usageFlags = data.getUint8(i + 1);
OUTPUT_MAPPING.put(
{
'timerId': timerId,
'usageFlags': usageFlags
});
}
break;
case MSPCodes.MSP2_INAV_TIMER_OUTPUT_MODE:
if(data.byteLength > 2) {
OUTPUT_MAPPING.flushTimerOverrides();
}
for (i = 0; i < data.byteLength; i += 2) {
timerId = data.getUint8(i);
outputMode = data.getUint8(i + 1);
OUTPUT_MAPPING.setTimerOverride(timerId, outputMode);
}
break;
case MSPCodes.MSP2_INAV_MC_BRAKING:
@ -2820,6 +2845,47 @@ var mspHelper = (function (gui) {
MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING, false, false, callback);
};
self.loadOutputMappingExt = function (callback) {
MSP.send_message(MSPCodes.MSPV2_INAV_OUTPUT_MAPPING_EXT, false, false, callback);
};
self.loadTimerOutputModes = function(callback) {
MSP.send_message(MSPCodes.MSP2_INAV_TIMER_OUTPUT_MODE, false, false, callback);
}
self.sendTimerOutputModes = function(callback) {
var nextFunction = send_next_output_mode;
var idIndex = 0;
var overrideIds = OUTPUT_MAPPING.getUsedTimerIds();
if (overrideIds.length == 0) {
onCompleteCallback();
} else {
send_next_output_mode();
}
function send_next_output_mode() {
var timerId = overrideIds[idIndex];
var outputMode = OUTPUT_MAPPING.getTimerOverride(timerId);
var buffer = [];
buffer.push(timerId);
buffer.push(outputMode);
// prepare for next iteration
idIndex++;
if (idIndex == overrideIds.length) {
nextFunction = callback;
}
MSP.send_message(MSPCodes.MSP2_INAV_SET_TIMER_OUTPUT_MODE, buffer, false, nextFunction);
}
}
self.loadBatteryConfig = function (callback) {
MSP.send_message(MSPCodes.MSPV2_BATTERY_CONFIG, false, false, callback);
};

@ -3,7 +3,8 @@
let OutputMappingCollection = function () {
let self = {},
data = [];
data = [],
timerOverrides = {};
const TIM_USE_ANY = 0;
const TIM_USE_PPM = 0;
@ -19,6 +20,34 @@ let OutputMappingCollection = function () {
const OUTPUT_TYPE_MOTOR = 0;
const OUTPUT_TYPE_SERVO = 1;
self.TIMER_OUTPUT_MODE_AUTO = 0;
self.TIMER_OUTPUT_MODE_MOTORS = 1;
self.TIMER_OUTPUT_MODE_SERVOS = 2;
self.flushTimerOverrides = function() {
timerOverrides = {};
}
self.setTimerOverride = function (timer, outputMode) {
timerOverrides[timer] = outputMode;
}
self.getTimerOverride = function (timer) {
return timerOverrides[timer];
}
self.getUsedTimerIds = function (timer) {
let used = {};
let outputCount = self.getOutputCount();
for (let i = 0; i < outputCount; ++i) {
let timerId = self.getTimerId(i);
used[timerId] = 1;
}
return Object.keys(used).sort((a, b) => a - b);
}
function getTimerMap(isMR, motors, servos) {
let timerMap = [],
motorsToGo = motors,
@ -31,20 +60,19 @@ let OutputMappingCollection = function () {
if (servosToGo > 0 && bit_check(data[i], TIM_USE_MC_SERVO)) {
servosToGo--;
timerMap[i] = OUTPUT_TYPE_SERVO;
} else if (motorsToGo > 0 && bit_check(data[i], TIM_USE_MC_MOTOR)) {
} else if (motorsToGo > 0 && bit_check(data[i]['usageFlags'], TIM_USE_MC_MOTOR)) {
motorsToGo--;
timerMap[i] = OUTPUT_TYPE_MOTOR;
}
} else {
if (servosToGo > 0 && bit_check(data[i], TIM_USE_FW_SERVO)) {
if (servosToGo > 0 && bit_check(data[i]['usageFlags'], TIM_USE_FW_SERVO)) {
servosToGo--;
timerMap[i] = OUTPUT_TYPE_SERVO;
} else if (motorsToGo > 0 && bit_check(data[i], TIM_USE_FW_MOTOR)) {
} else if (motorsToGo > 0 && bit_check(data[i]['usageFlags'], TIM_USE_FW_MOTOR)) {
motorsToGo--;
timerMap[i] = OUTPUT_TYPE_MOTOR;
}
}
}
return timerMap;
@ -89,10 +117,10 @@ let OutputMappingCollection = function () {
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)
bit_check(data[i]['usageFlags'], TIM_USE_MC_MOTOR) ||
bit_check(data[i]['usageFlags'], TIM_USE_MC_SERVO) ||
bit_check(data[i]['usageFlags'], TIM_USE_FW_MOTOR) ||
bit_check(data[i]['usageFlags'], TIM_USE_FW_SERVO)
) {
retVal++;
};
@ -104,10 +132,10 @@ let OutputMappingCollection = function () {
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)
bit_check(data[i]['usageFlags'], TIM_USE_MC_MOTOR) ||
bit_check(data[i]['usageFlags'], TIM_USE_MC_SERVO) ||
bit_check(data[i]['usageFlags'], TIM_USE_FW_MOTOR) ||
bit_check(data[i]['usageFlags'], TIM_USE_FW_SERVO)
) {
return i;
}
@ -115,6 +143,10 @@ let OutputMappingCollection = function () {
return 0;
}
function getTimerId(outputIndex) {
return data[outputIndex]['timerId'];
}
function getOutput(servoIndex, bit) {
let offset = getFirstOutputOffset();
@ -122,7 +154,7 @@ let OutputMappingCollection = function () {
let lastFound = 0;
for (let i = offset; i < data.length; i++) {
if (bit_check(data[i], bit)) {
if (bit_check(data[i]['usageFlags'], bit)) {
if (lastFound == servoIndex) {
return i - offset + 1;
} else {
@ -134,6 +166,10 @@ let OutputMappingCollection = function () {
return null;
}
self.getTimerId = function(outputIndex) {
return getTimerId(outputIndex)
}
self.getFwServoOutput = function (servoIndex) {
return getOutput(servoIndex, TIM_USE_FW_SERVO);
};

@ -28,6 +28,14 @@
</div>
</div>
</div>
<div class="platform-type gui_box grey">
<div class="gui_box_titlebar">
<div class="spacer_box_title" data-i18n="timerOutputs"></div>
</div>
<div class="spacer_box" id="timerOutputsList"></div>
</div>
</div>
<div class="rightWrapper">
<div class="platform-type gui_box grey">

@ -27,7 +27,8 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
mspHelper.loadMotors,
mspHelper.loadServoMixRules,
mspHelper.loadMotorMixRules,
mspHelper.loadOutputMapping,
mspHelper.loadOutputMappingExt,
mspHelper.loadTimerOutputModes,
mspHelper.loadLogicConditions
]);
loadChainer.setExitPoint(loadHtml);
@ -37,6 +38,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
mspHelper.saveMixerConfig,
mspHelper.sendServoMixer,
mspHelper.sendMotorMixer,
mspHelper.sendTimerOutputModes,
saveSettings,
mspHelper.saveToEeprom
]);
@ -74,7 +76,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
$functionRow.append('<th data-i18n="mappingTableFunction"></th>');
for (let i = 1; i <= outputCount; i++) {
$outputRow.append('<td>S' + i + '</td>');
$outputRow.append('<td>S' + i + ' (T' + (OUTPUT_MAPPING.getTimerId(i -1)) + ')</td>');
$functionRow.append('<td id="function-' + i +'">-</td>');
}
@ -82,6 +84,44 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
}
function updateTimerOverride() {
let timers = OUTPUT_MAPPING.getUsedTimerIds();
for(let i =0; i < timers.length;++i) {
let timerId = timers[i];
$select = $('#timer-output-' + timerId);
if(!$select) {
continue;
}
OUTPUT_MAPPING.setTimerOverride(timerId, $select.val());
}
}
function renderTimerOverride() {
let outputCount = OUTPUT_MAPPING.getOutputCount(),
$container = $('#timerOutputsList'), timers = {};
let usedTimers = OUTPUT_MAPPING.getUsedTimerIds();
for (t of usedTimers) {
var usageMode = OUTPUT_MAPPING.getTimerOverride(t);
$container.append(
'<div class="select">' +
'<select id="timer-output-' + t + '">' +
'<option value=' + OUTPUT_MAPPING.TIMER_OUTPUT_MODE_AUTO + '' + (usageMode == OUTPUT_MAPPING.TIMER_OUTPUT_MODE_AUTO ? ' selected' : '')+ '>AUTO</option>'+
'<option value=' + OUTPUT_MAPPING.TIMER_OUTPUT_MODE_MOTORS + '' + (usageMode == OUTPUT_MAPPING.TIMER_OUTPUT_MODE_MOTORS ? ' selected' : '')+ '>MOTORS</option>'+
'<option value=' + OUTPUT_MAPPING.TIMER_OUTPUT_MODE_SERVOS + '' + (usageMode == OUTPUT_MAPPING.TIMER_OUTPUT_MODE_SERVOS ? ' selected' : '')+ '>SERVOS</option>'+
'</select>' +
'<label for="timer-output-' + t + '">' +
'<span> T' + t + '</span>' +
'</label>' +
'</div>'
);
}
}
function renderOutputMapping() {
let outputMap = OUTPUT_MAPPING.getOutputTable(
MIXER_CONFIG.platformType == PLATFORM_MULTIROTOR || MIXER_CONFIG.platformType == PLATFORM_TRICOPTER,
@ -437,6 +477,9 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
SERVO_RULES.inflate();
MOTOR_RULES.cleanup();
MOTOR_RULES.inflate();
updateTimerOverride();
saveChainer.execute();
}
@ -704,6 +747,7 @@ TABS.mixer.initialize = function (callback, scrollPosition) {
renderOutputTable();
renderOutputMapping();
renderTimerOverride();
LOGIC_CONDITIONS.init($('#logic-wrapper'));

Loading…
Cancel
Save