Welcome to mirror list, hosted at ThFree Co, Russian Federation.

motorMixerRuleCollection.js « js - github.com/iNavFlight/inav-configurator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6a5a6c4091141fff0ea619baa7636659191501a7 (plain)
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
/*global $, MotorMixRule*/
'use strict';

var MotorMixerRuleCollection = function () {

    let self = {},
        data = [],
        maxMotorCount = 8;

    self.setMotorCount = function (value) {
        maxMotorCount = value;
    };

    self.getMotorCount = function () {
        return maxMotorCount;
    };

    self.put = function (element) {
        data.push(element);
    };

    self.get = function () {
        return data;
    };

    self.drop = function (index) {
        data[index].setThrottle(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 MotorMixRule(0, 0, 0, 0));
        }
    };

    self.hasFreeSlots = function () {
        return data.length < self.getMotorCount();
    };

    self.getNumberOfConfiguredMotors = function () {
        return data.length;
    };

    return self;
};