lowpass: add set() method to set current average
light: - only trigger switch action if switch state actually changed - simplify loop
This commit is contained in:
parent
c5ac5639a0
commit
eff0eecb8f
1 changed files with 14 additions and 10 deletions
|
@ -181,6 +181,7 @@ light = {
|
||||||
}
|
}
|
||||||
m.continuous = 0;
|
m.continuous = 0;
|
||||||
m.loopid = 0;
|
m.loopid = 0;
|
||||||
|
m.switch = -1;
|
||||||
m.switchL = setlistener(m.switchN, func { m._switch_() }, 1);
|
m.switchL = setlistener(m.switchN, func { m._switch_() }, 1);
|
||||||
return m;
|
return m;
|
||||||
},
|
},
|
||||||
|
@ -202,11 +203,15 @@ light = {
|
||||||
blink : func { if (me.continuous) { me.continuous = 0; me._switch_(); } me },
|
blink : func { if (me.continuous) { me.continuous = 0; me._switch_(); } me },
|
||||||
|
|
||||||
_switch_ : func {
|
_switch_ : func {
|
||||||
var state = me.switchN.getBoolValue();
|
var switch = me.switchN.getBoolValue();
|
||||||
|
if (me.switch == switch) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
me.switch = switch;
|
||||||
me.loopid += 1;
|
me.loopid += 1;
|
||||||
if (me.continuous) {
|
if (me.continuous) {
|
||||||
me.stateN.setBoolValue(state);
|
me.stateN.setBoolValue(switch);
|
||||||
} elsif (state) {
|
} elsif (switch) {
|
||||||
me._loop_(me.loopid);
|
me._loop_(me.loopid);
|
||||||
} else {
|
} else {
|
||||||
me.stateN.setBoolValue(0);
|
me.stateN.setBoolValue(0);
|
||||||
|
@ -217,13 +222,8 @@ light = {
|
||||||
if (id != me.loopid) {
|
if (id != me.loopid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (me.stateN.getBoolValue()) {
|
me.stateN.setBoolValue(var state = !me.stateN.getBoolValue());
|
||||||
me.stateN.setBoolValue(0);
|
settimer(func { me._loop_(id) }, state ? me.ontime : me.offtime);
|
||||||
settimer(func { me._loop_(id) }, me.offtime);
|
|
||||||
} else {
|
|
||||||
me.stateN.setBoolValue(1);
|
|
||||||
settimer(func { me._loop_(id) }, me.ontime);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -260,6 +260,10 @@ lowpass = {
|
||||||
get : func {
|
get : func {
|
||||||
me.value;
|
me.value;
|
||||||
},
|
},
|
||||||
|
# set() -> sets new average
|
||||||
|
set : func(v) {
|
||||||
|
me.value = v;
|
||||||
|
},
|
||||||
_filter_ : func(v) {
|
_filter_ : func(v) {
|
||||||
var dt = me.dtN.getValue();
|
var dt = me.dtN.getValue();
|
||||||
var c = dt / (me.coeff + dt);
|
var c = dt / (me.coeff + dt);
|
||||||
|
|
Loading…
Reference in a new issue