|
|
|
@ -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);
|
|
|
|
|
};
|
|
|
|
|