Subversion Repositories HomeAutomation

Rev

Rev 1422 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1422 Rev 1424
Line 25... Line 25...
25
LED_dimmer.prototype.pwmValue = 50;
25
LED_dimmer.prototype.pwmValue = 50;
26
LED_dimmer.prototype.outputStatus = "Low";
26
LED_dimmer.prototype.outputStatus = "Low";
27
LED_dimmer.prototype.myInterval = null;
27
LED_dimmer.prototype.myInterval = null;
28
LED_dimmer.prototype.oldPwmValue = 0;
28
LED_dimmer.prototype.oldPwmValue = 0;
29
LED_dimmer.prototype.turnOffCnt = 0;
29
LED_dimmer.prototype.turnOffCnt = 0;
30
const MovementTimeout = 45;
30
const MovementTimeout = 120;
31
const AdjustTimeout = 180;
31
const AdjustTimeout = 240;
32
/*  */
32
/*  */
33
/*  */
33
/*  */
34
 
34
 
35
 
35
 
36
/* This function must always be declared, this is where all the startup code
36
/* This function must always be declared, this is where all the startup code
Line 48... Line 48...
48
    {
48
    {
49
        log(this.myName + ":" + this.myId + "> Failed to initialize, RotaryHex-config missing from config.\n");
49
        log(this.myName + ":" + this.myId + "> Failed to initialize, RotaryHex-config missing from config.\n");
50
        return;
50
        return;
51
    }
51
    }
52
 
52
   
53
    if (!this.myInitialArguments["hwPWM"])
-
 
54
    {
-
 
55
        log(this.myName + ":" + this.myId + "> Failed to initialize, hwPWM-config missing from config.\n");
-
 
56
        return;
-
 
57
    }
-
 
58
   
-
 
59
    if (!this.myInitialArguments["output"])
53
    if (!this.myInitialArguments["output"])
60
    {
54
    {
61
        log(this.myName + ":" + this.myId + "> Failed to initialize, output-config missing from config.\n");
55
        log(this.myName + ":" + this.myId + "> Failed to initialize, output-config missing from config.\n");
62
        return;
56
        return;
63
    }
57
    }
64
    if (!this.myInitialArguments["input"])
58
    if (!this.myInitialArguments["input"])
65
    {
59
    {
66
        log(this.myName + ":" + this.myId + "> Failed to initialize, input-config missing from config.\n");
60
        log(this.myName + ":" + this.myId + "> Failed to initialize, input-config missing from config.\n");
67
        return;
61
        return;
68
    }
62
    }
69
 
63
 
70
    this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
64
    this.myInterval = new Interval(function() { self.timerUpdate() }, 5000);
71
    this.myInterval.start();
65
    this.myInterval.start();
72
 
66
 
73
    /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
67
    /* Get the Rotary service that we want from the ServiceManager, it takes type, service name, service id */
74
    this.myRotaryService = ServiceManager.getService("Can", "RotaryHex", this.myInitialArguments["RotaryHex"]["Id"]);
68
    this.myRotaryService = ServiceManager.getService("Can", "RotaryHex", this.myInitialArguments["RotaryHex"]["Id"]);
75
    /* Add a callback for when the encoder reports a new position */
69
    /* Add a callback for when the encoder reports a new position */
76
    this.myRotaryService.registerEventCallback("newPosition", function(args) { self.rotaryPosUpdate(args); });
70
    this.myRotaryService.registerEventCallback("newPosition", function(args) { self.rotaryPosUpdate(args); });
77
    /* Add a callback for when the encoder reports a new button status */
71
    /* Add a callback for when the encoder reports a new button status */
Line 79... Line 73...
79
    /* Add a callback for when the service goes online */
73
    /* Add a callback for when the service goes online */
80
    this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
74
    this.myRotaryService.registerEventCallback("online", function(args) { self.rotaryOnline(); });
81
    /* If the service is already online we should call the handler here */
75
    /* If the service is already online we should call the handler here */
82
    this.rotaryOnline();
76
    this.rotaryOnline();
83
 
77
 
84
    this.myPWM = ServiceManager.getService("Can", "hwPWM", this.myInitialArguments["hwPWM"]["Id"]);
78
    //this.myPWM = ServiceManager.getService("Can", "hwPWM", this.myInitialArguments["hwPWM"]["Id"]);
85
    this.myOutput = ServiceManager.getService("Can", "output", this.myInitialArguments["output"]["Id"]);
79
    this.myOutput = ServiceManager.getService("Can", "output", this.myInitialArguments["output"]["Id"]);
86
    this.myInput = ServiceManager.getService("Can", "input", this.myInitialArguments["input"]["Id"]);
80
    this.myInput = ServiceManager.getService("Can", "input", this.myInitialArguments["input"]["Id"]);
87
    /* Add a callback for when the PIR reports detection */
81
    /* Add a callback for when the PIR reports detection */
88
    this.myInput.registerEventCallback("newValue", function(args) { self.pirUpdate(args); });
82
    this.myInput.registerEventCallback("newValue", function(args) { self.pirUpdate(args); });
89
   
83
   
Line 97... Line 91...
97
            this.turnOffCnt = 0;
91
            this.turnOffCnt = 0;
98
        }
92
        }
99
        if (this.turnOffCnt == 0) {
93
        if (this.turnOffCnt == 0) {
100
            //Turn off light
94
            //Turn off light
101
            log(this.myName + ":" + this.myId + "> Light off.\n");
95
            log(this.myName + ":" + this.myId + "> Light off.\n");
102
            this.oldPwmValue = this.myPWM.getValue(2);
96
            this.oldPwmValue = getDimmerValue('Badrum');
103
            this.myPWM.setPWMValue(0,2);
97
            //this.myPWM.setPWMValue(0,2);
-
 
98
            getDimmerService('Badrum').absFade(2,129, 0);
104
        }
99
        }
105
    }
100
    }
106
}
101
}
107
 
102
 
108
LED_dimmer.prototype.rotaryOnline = function()
103
LED_dimmer.prototype.rotaryOnline = function()
Line 111... Line 106...
111
 
106
 
112
LED_dimmer.prototype.rotaryPosUpdate = function(SwitchId)
107
LED_dimmer.prototype.rotaryPosUpdate = function(SwitchId)
113
{
108
{
114
   
109
   
115
    for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
110
    for (var i = 0; i < this.myRotaryService.getSteps(SwitchId); i++)
116
    {
111
    {
117
        if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
112
        if (this.myRotaryService.getDirection(SwitchId) == "Clockwise")
118
        {
113
        {
-
 
114
            getDimmerService('Badrum').relFade(2,132, "Increase", 25);
119
            this.pwmValue = this.pwmValue +10;
115
this.pwmValue = this.pwmValue +10;
120
            if (this.pwmValue > 100) {
116
            if (this.pwmValue > 100) {
121
                this.pwmValue = 100;
117
                this.pwmValue = 100;
122
            }
118
            }
123
        }
119
        }
124
        else
120
        else
125
        {
121
        {
-
 
122
            getDimmerService('Badrum').relFade(2,132, "Decrease", 25);
126
            this.pwmValue = this.pwmValue -10;
123
            this.pwmValue = this.pwmValue -10;
127
            if (this.pwmValue < 0) {
124
            if (this.pwmValue < 0) {
128
                this.pwmValue = 0;
125
                this.pwmValue = 0;
129
            }
126
            }
130
        }
127
        }
131
    }
128
    }
132
    if (this.turnOffCnt <  AdjustTimeout) {
129
    if (this.turnOffCnt <  AdjustTimeout) {
133
        this.turnOffCnt = AdjustTimeout;
130
        this.turnOffCnt = AdjustTimeout;
134
    }
131
    }
135
//log(this.myName + ":" + this.myId + "> Sent pwm value: "+ this.pwmValue+"\n");
132
//log(this.myName + ":" + this.myId + "> Sent pwm value: "+ this.pwmValue+"\n");
136
    this.myPWM.setPWMValue(this.pwmValue,2);
133
    //this.myPWM.setPWMValue(this.pwmValue,2);
137
    this.myPWM.setPWMValue(this.pwmValue,1);
-
 
-
 
134
   
138
}
135
}
139
 
136
 
140
LED_dimmer.prototype.rotaryBtnUpdate = function(SwitchId)
137
LED_dimmer.prototype.rotaryBtnUpdate = function(SwitchId)
141
{
138
{
142
    if (this.myRotaryService.getButtonStatus(SwitchId) == "Pressed") {
139
    if (this.myRotaryService.getButtonStatus(SwitchId) == "Pressed") {
143
        if (this.myPWM.getValue(2) == 0) {
140
        if (getDimmerValue('Badrum') == 0) {
144
            if (this.oldPwmValue == 0) {
141
            if (this.oldPwmValue == 0) {
145
                this.oldPwmValue = 50;
142
                this.oldPwmValue = 50;
146
            }
143
            }
-
 
144
            getDimmerService('Badrum').absFade(2,129, 128);
147
            this.myPWM.setPWMValue(this.oldPwmValue,2);
145
            //this.myPWM.setPWMValue(this.oldPwmValue,2);
148
        }
146
        }
149
        if (this.turnOffCnt <  AdjustTimeout) {
147
        if (this.turnOffCnt <  AdjustTimeout) {
150
            this.turnOffCnt = AdjustTimeout;
148
            this.turnOffCnt = AdjustTimeout;
151
        }
149
        }
152
        if (this.myOutput.getValue(0) == "High") {
150
        if (this.myOutput.getValue(0) == "High") {
Line 159... Line 157...
159
 
157
 
160
LED_dimmer.prototype.pirUpdate = function(SwitchId)
158
LED_dimmer.prototype.pirUpdate = function(SwitchId)
161
{
159
{
162
    //log(this.myName + ":" + this.myId + "> Value is: "+ this.myInput.getValue(SwitchId)+"\n");
160
    //log(this.myName + ":" + this.myId + "> Value is: "+ this.myInput.getValue(SwitchId)+"\n");
163
    if (this.myInput.getValue(SwitchId) == "Low") {
161
    if (this.myInput.getValue(SwitchId) == "Low") {
-
 
162
          getDimmerService('Badrum').absFade(1,129, 255);
164
        //this.myOutput.setPin("High",0);
163
        //this.myOutput.setPin("High",0);
165
        log(this.myName + ":" + this.myId + "> Trigg.\n");
164
        log(this.myName + ":" + this.myId + "> Trigg.\n");
166
        if (this.myPWM.getValue(2) == 0) {
165
        if (getDimmerValue('Badrum') == 0) {
167
            log(this.myName + ":" + this.myId + "> Light on.\n");
166
            log(this.myName + ":" + this.myId + "> Light on.\n");
168
            if (this.oldPwmValue == 0) {
167
            if (this.oldPwmValue == 0) {
169
                this.oldPwmValue = 50;
168
                this.oldPwmValue = 50;
170
            }
169
            }
171
            this.myPWM.setPWMValue(this.oldPwmValue,2);
170
            //this.myPWM.setPWMValue(this.oldPwmValue,2);
-
 
171
            getDimmerService('Badrum').absFade(2,129, 128);
-
 
172
        }
-
 
173
    } else {
-
 
174
        getDimmerService('Badrum').absFade(1,129, 0);
-
 
175
    }
172
            if (this.turnOffCnt <  MovementTimeout) {
176
    if (this.turnOffCnt <  MovementTimeout) {
173
                this.turnOffCnt = MovementTimeout;
177
        this.turnOffCnt = MovementTimeout;
174
            }
-
 
175
        }
-
 
176
    }
178
    }
177
}
179
}