Rev 1786 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 1786 | Rev 2300 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | 1 | ||
| 2 | 2 | ||
| 3 | function skohylla(aliasnameSensor, aliasnameDimmer) |
3 | function skohylla(aliasnameSensor, aliasnameDimmer, triggerstate, defaultValue) |
| 4 | { |
4 | { |
| 5 | /* We must always call the parent constructor, initialization |
5 | /* We must always call the parent constructor, initialization |
| 6 | of variables could be done here, but initialize is a better place */ |
6 | of variables could be done here, but initialize is a better place */ |
| 7 | var self = this; |
7 | var self = this; |
| 8 | this.mySensor = aliasnameSensor; |
8 | this.mySensor = aliasnameSensor; |
| 9 | this.myDimmer = aliasnameDimmer; |
9 | this.myDimmer = aliasnameDimmer; |
| 10 | - | ||
| - | 10 | this.triggstate = triggerstate; |
|
| - | 11 | this.defaultValue = defaultValue; |
|
| 11 | Module_RegisterToOnMessage(aliasnameSensor, function(alias_name, command, variables) { self.sensorOnMessage(alias_name, command, variables) }); |
12 | Module_RegisterToOnMessage(aliasnameSensor, function(alias_name, command, variables) { self.sensorOnMessage(alias_name, command, variables) }); |
| 12 | Module_RegisterToOnChange( aliasnameSensor, function(alias_name, available,test) { self.sensorOnline(alias_name, available,test) }); |
13 | Module_RegisterToOnChange( aliasnameSensor, function(alias_name, available,test) { self.sensorOnline(alias_name, available,test) }); |
| 13 | Module_RegisterToOnChange( aliasnameDimmer, function(alias_name, available) { self.dimmerOnline(alias_name, available) }); |
14 | Module_RegisterToOnChange( aliasnameDimmer, function(alias_name, available) { self.dimmerOnline(alias_name, available) }); |
| 14 | 15 | ||
| 15 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
16 | /* Start interval timer for sending timestamp to network. Arguments are the callback function and time in milliseconds |
| Line 19... | Line 20... | ||
| 19 | 20 | ||
| 20 | } |
21 | } |
| 21 | 22 | ||
| 22 | /* Declaration of instance variables, for static variables remove prototype */ |
23 | /* Declaration of instance variables, for static variables remove prototype */ |
| 23 | skohylla.prototype.myDimmer = null; |
24 | skohylla.prototype.myDimmer = null; |
| - | 25 | skohylla.prototype.triggstate = null; |
|
| 24 | skohylla.prototype.mySensor = null; |
26 | skohylla.prototype.mySensor = null; |
| 25 | skohylla.prototype.outputStatus = "Low"; |
27 | skohylla.prototype.outputStatus = "Low"; |
| 26 | skohylla.prototype.myInterval = null; |
28 | skohylla.prototype.myInterval = null; |
| 27 | skohylla.prototype.oldPwmValue = 0; |
29 | skohylla.prototype.oldPwmValue = 0; |
| 28 | skohylla.prototype.turnOffCnt = 0; |
30 | skohylla.prototype.turnOffCnt = 0; |
| - | 31 | skohylla.prototype.defaultValue = 255; |
|
| 29 | const SkoMovementTimeout = 100; |
32 | const SkoMovementTimeout = 100; |
| 30 | 33 | ||
| 31 | skohylla.prototype.sensorOnline = function(alias_name, available) |
34 | skohylla.prototype.sensorOnline = function(alias_name, available) |
| 32 | { |
35 | { |
| 33 | 36 | ||
| Line 44... | Line 47... | ||
| 44 | switch (command) |
47 | switch (command) |
| 45 | { |
48 | { |
| 46 | case "PinStatus": |
49 | case "PinStatus": |
| 47 | { |
50 | { |
| 48 | 51 | ||
| 49 | if (variables["Status"] == |
52 | if (variables["Status"] == this.triggstate) { |
| 50 | //Log("\033[33mPin low.\033[0m\n"); |
53 | //Log("\033[33mPin low.\033[0m\n"); |
| 51 | var last_value_string = Storage_GetParameter("LastValues", this.myDimmer); |
54 | var last_value_string = Storage_GetParameter("LastValues", this.myDimmer); |
| 52 | var last_value = eval("(" + last_value_string + ")"); |
55 | var last_value = eval("(" + last_value_string + ")"); |
| 53 | if (last_value["Level"]["value"] == 0) { |
56 | if (last_value["Level"]["value"] == 0) { |
| 54 | //log(this.myName + ":" + this.myId + "> Light on.\n"); |
57 | //log(this.myName + ":" + this.myId + "> Light on.\n"); |
| 55 | if (this.oldPwmValue == 0) { |
58 | if (this.oldPwmValue == 0) { |
| 56 | this.oldPwmValue = |
59 | this.oldPwmValue = this.defaultValue; |
| 57 | } |
60 | } |
| 58 | Dimmer_AbsoluteFade(this.myDimmer, 129, this.oldPwmValue); |
61 | Dimmer_AbsoluteFade(this.myDimmer, 129, this.oldPwmValue); |
| 59 | } |
62 | } |
| 60 | 63 | ||
| 61 | } else { |
64 | } else { |