Subversion Repositories HomeAutomation

Rev

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

Rev 1392 Rev 1424
Line 5... Line 5...
5
    this.myLastValue = new Array();
5
    this.myLastValue = new Array();
6
}
6
}
7
 
7
 
8
extend(hwPWM, CanService);
8
extend(hwPWM, CanService);
9
 
9
 
-
 
10
hwPWM.prototype.currentValue = 0;
10
hwPWM.prototype.myReportInterval = null;
11
hwPWM.prototype.myReportInterval = null;
11
hwPWM.prototype.myLastValue = null;
12
hwPWM.prototype.myLastValue = null;
12
 
13
 
13
hwPWM.prototype.canMessageHandler = function(canMessage)
14
hwPWM.prototype.canMessageHandler = function(canMessage)
14
{
15
{
-
 
16
    var self = this;
15
    if (canMessage.getDirectionFlag() == "From_Owner")
17
    if (canMessage.getDirectionFlag() == "From_Owner")
16
    {
18
    {
17
        switch (canMessage.getCommandName())
19
        switch (canMessage.getCommandName())
18
        {
20
        {
-
 
21
 
-
 
22
        case "Pwm":
-
 
23
                this.currentValue = canMessage.getData("Value")/39;
-
 
24
                var dataArray = new Array();
-
 
25
                dataArray["service"] = self;
-
 
26
                dataArray["channel"] = canMessage.getData("Id");
-
 
27
                dataArray["currentValue"] = (canMessage.getData("Value")/39);
-
 
28
                dataArray["moduleName"] = canMessage.getModuleName();
-
 
29
                dataArray["moduleId"] = canMessage.getModuleId();
-
 
30
                this.callEvent("newValue", dataArray);
-
 
31
                //log(this.myName + ":" + this.myId + "> Netstatus, " + connectString + frequencyString + "\n");
-
 
32
            break;
-
 
33
 
19
        /*case "hwPWM":
34
        /*case "hwPWM":
20
        log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
35
        log(this.myName + ":" + this.myId + "> New value: " + canMessage.getData("Value") + "\n");
21
        this.myLastValue[canMessage.getData("Id")] = canMessage.getData("Value");
36
        this.myLastValue[canMessage.getData("Id")] = canMessage.getData("Value");
22
        this.callEvent("newValue", canMessage.getData("Id"));
37
        this.callEvent("newValue", canMessage.getData("Id"));
23
        break;
38
        break;
24
       
39
       
25
        case "Report_Interval":
40
        case "Report_Interval":
26
        log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
41
        log(this.myName + ":" + this.myId + "> New report interval: " + canMessage.getData("Time") + "\n");
27
        this.myReportInterval = canMessage.getData("Time");
42
        this.myReportInterval = canMessage.getData("Time");
28
        break;*/
43
        break;*/
29
        }
44
        }
30
    }
45
    }
31
   
46
   
32
    this.CanService.prototype.canMessageHandler.call(this, canMessage);
47
    this.CanService.prototype.canMessageHandler.call(this, canMessage);
33
}
48
}
34
 
49
 
35
hwPWM.prototype.getValue = function(sensorId)
50
hwPWM.prototype.getValue = function(sensorId)
36
{
51
{
Line 51... Line 66...
51
hwPWM.prototype.setPWMValue = function(pwmvalue, sensorId)
66
hwPWM.prototype.setPWMValue = function(pwmvalue, sensorId)
52
{
67
{
53
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Pwm");
68
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Pwm");
54
    canMessage.setData("Id", sensorId);
69
    canMessage.setData("Id", sensorId);
55
    canMessage.setData("Value", pwmvalue*100);
70
    canMessage.setData("Value", pwmvalue*100);
56
    sendMessage(canMessage);
71
    sendMessage(canMessage);
57
   
72
   
58
    this.myLastValue[sensorId] = pwmvalue;
73
    this.myLastValue[sensorId] = pwmvalue;
59
}
74
}
60
/*hwPWM.prototype.configure = function(pwmPeriod, pwmDefaultValue, DefaultState, StartUpState)
75
/*hwPWM.prototype.configure = function(pwmPeriod, pwmDefaultValue, DefaultState, StartUpState)
61
{
76
{
Line 64... Line 79...
64
    canMessage.setData("pwmDefaultValue", pwmDefaultValue);
79
    canMessage.setData("pwmDefaultValue", pwmDefaultValue);
65
    canMessage.setData("DefaultState", DefaultState);
80
    canMessage.setData("DefaultState", DefaultState);
66
    canMessage.setData("StartUpState", StartUpState);
81
    canMessage.setData("StartUpState", StartUpState);
67
    sendMessage(canMessage);
82
    sendMessage(canMessage);
68
}*/
83
}*/
-
 
84
 
-
 
85
hwPWM.prototype.startFade = function(channel, speed, direction)
-
 
86
{
-
 
87
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Start_Fade");
-
 
88
    canMessage.setData("Channel", channel);
-
 
89
    canMessage.setData("Speed", speed);
-
 
90
    canMessage.setData("Direction", direction);
-
 
91
    sendMessage(canMessage);
-
 
92
}
-
 
93
 
-
 
94
hwPWM.prototype.stopFade = function(channel)
-
 
95
{
-
 
96
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Stop_Fade");
-
 
97
    canMessage.setData("Channel", channel);
-
 
98
    sendMessage(canMessage);
-
 
99
}
-
 
100
 
-
 
101
hwPWM.prototype.absFade = function(channel, speed, endValue)
-
 
102
{
-
 
103
log("sending: "+channel+" "+speed+" "+endValue*39+"\n");   
-
 
104
var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Abs_Fade");
-
 
105
    canMessage.setData("Channel", channel);
-
 
106
    canMessage.setData("Speed", speed);
-
 
107
    canMessage.setData("EndValue", endValue*39);
-
 
108
    sendMessage(canMessage);
-
 
109
}
-
 
110
 
-
 
111
hwPWM.prototype.relFade = function(channel, speed, direction, steps)
-
 
112
{
-
 
113
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Rel_Fade");
-
 
114
    canMessage.setData("Channel", channel);
-
 
115
    canMessage.setData("Speed", speed);
-
 
116
    canMessage.setData("Direction", direction);
-
 
117
    canMessage.setData("Steps", steps*39);
-
 
118
    sendMessage(canMessage);
-
 
119
}
-
 
120
 
-
 
121
hwPWM.prototype.demo = function(channel, speed, steps)
-
 
122
{
-
 
123
    var canMessage = new CanMessage("act", "To_Owner", this.myName, this.myId, "Demo");
-
 
124
    canMessage.setData("Channel", channel);
-
 
125
    canMessage.setData("Speed", speed);
-
 
126
    canMessage.setData("Steps", steps*39);
-
 
127
    sendMessage(canMessage);
-
 
128
}
69
 
129