1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 11:29:53 +03:00
inav-configurator/js/servoMixerRuleCollection.js
Darren Lines 47a9f4b36e Updated mixer
- Tidied up the code a little and grouped mixer types in model.js.
- Removed second motor from all fixed wing mixers that aren't differential thrust. A bug was discovered that if an FC only has a single motor output, and 2 motors are set in the mixer, the motors won't work.
- Added mixer for V-Tail with differential thrust
- Enhanced the new servo button. Clicking it now selects the next available servo number, rather than just 0.
2022-02-14 19:55:00 +00:00

118 lines
No EOL
2.5 KiB
JavaScript

/*global ServoMixRule*/
'use strict';
let ServoMixerRuleCollection = function () {
let self = {},
data = [],
maxServoCount = 16;
self.setServoCount = function (value) {
maxServoCount = value;
};
self.getServoCount = function () {
return maxServoCount;
}
self.getServoRulesCount = function () {
return self.getServoCount() * 2;
}
self.put = function (element) {
data.push(element);
};
self.get = function () {
return data;
};
self.drop = function (index) {
data[index].setRate(0);
self.cleanup();
};
self.flush = function () {
data = [];
};
self.cleanup = function () {
var tmpData = [];
data.forEach(function (element) {
if (element.isUsed()) {
tmpData.push(element);
}
});
data = tmpData;
};
self.inflate = function () {
while (self.hasFreeSlots()) {
self.put(new ServoMixRule(0, 0, 0, 0));
}
};
self.hasFreeSlots = function () {
return data.length < self.getServoRulesCount();
};
self.isServoConfigured = function(servoId) {
for (let ruleIndex in data) {
if (data.hasOwnProperty(ruleIndex)) {
let rule = data[ruleIndex];
if (rule.getTarget() == servoId && rule.isUsed()) {
return true;
}
}
}
return false;
};
self.getNumberOfConfiguredServos = function () {
let count = 0;
for (let i = 0; i < self.getServoCount(); i ++) {
if (self.isServoConfigured(i)) {
count++;
}
}
return count;
};
self.getUsedServoIndexes = function () {
let out = [];
for (let ruleIndex in data) {
if (data.hasOwnProperty(ruleIndex)) {
let rule = data[ruleIndex];
out.push(rule.getTarget());
}
}
let unique = [...new Set(out)];
return unique.sort(function(a, b) {
return a-b;
});
}
self.getNextUnusedIndex = function() {
let nextTarget = 0;
for (let ruleIndex in data) {
if (data.hasOwnProperty(ruleIndex)) {
let target = data[ruleIndex].getTarget();
if (target > nextTarget) {
nextTarget = target;
}
}
}
return nextTarget+1;
}
return self;
};