forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotorMixerRuleCollection.js
77 lines (61 loc) · 1.72 KB
/
motorMixerRuleCollection.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
const MotorMixRule = require('./motorMixRule');
var MotorMixerRuleCollection = function () {
let self = {},
data = [],
inactiveData = [],
maxMotorCount = 8;
self.setMotorCount = function (value) {
maxMotorCount = value;
};
self.getMotorCount = function () {
return maxMotorCount;
};
self.put = function (element) {
if (data.length < self.getMotorCount()){
data.push(element);
}else{
inactiveData.push(element); //store the data for mixer_profile 2
}
};
self.get = function () {
return data;
};
self.drop = function (index) {
data[index].setThrottle(0);
self.cleanup();
};
self.flush = function () {
data = [];
inactiveData = [];
};
self.cleanup = function () {
var tmpData = [];
var tmpInactiveData = [];
data.forEach(function (element) {
if (element.isUsed()) {
tmpData.push(element);
}
});
inactiveData.forEach(function (element) {
if (element.isUsed()) {
tmpInactiveData.push(element);
}
});
data = tmpData;
inactiveData = tmpInactiveData;
};
self.inflate = function () {
while (self.hasFreeSlots()) {
self.put(new MotorMixRule(0, 0, 0, 0));
}
};
self.hasFreeSlots = function () {
return data.length < self.getMotorCount();
};
self.getNumberOfConfiguredMotors = function () {
return data.length > inactiveData.length ? data.length : inactiveData.length;
};
return self;
};
module.exports = MotorMixerRuleCollection;