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

simple_smooth_filter.js « js - github.com/iNavFlight/inav-configurator.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ae8ca74f1f399780e60dc328954c4c85b8328dfc (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
'use strict';

var classes = classes || {};

classes.SimpleSmoothFilter = function (initialValue, smoothingFactor) {

    var self = {};

    self.value = initialValue;
    self.smoothFactor = smoothingFactor;

    if (self.smoothFactor >= 1) {
        self.smoothFactor = 0.99;
    }

    if (self.smoothFactor <= 0) {
        self.smoothFactor = 0;
    }

    self.apply = function (newValue) {
        self.value = (newValue * (1 - self.smoothFactor)) + (self.value  *  self.smoothFactor);

        return self;
    };

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

    return self;
};