-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebRelais.html
132 lines (103 loc) · 4.49 KB
/
WebRelais.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "width = 420, user-scalable = no" />
<title>MultiIO Relais</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
function generateButtonName(Module,Pin)
{
return("M" + Module.toString() + "IO" + Pin.toString());
}
webiopi().ready(function(){
// read pin onfo to start
for ( nModule = 0 ; nModule < 3 ; nModule++)
webiopi().callMacro("readAllPins",[nModule], readAllIOcallback);
// for ( nPin = 0 ; nPin < 8 ; nPin++)
// {
// webiopi().callMacro("readPin",[nModule,nPin],readcallback);
// }
});
var readAllIOcallback = function(macro,args,response){
var returnvalue = parseInt(response);
var moduleid = parseInt(args[0]);
// let's fill up the button info
for( nPin = 0 ; nPin < 8 ; nPin++)
{
// let's build the button name
var buttonid = generateButtonName(moduleid,nPin);
var buttoncolor = "#c0c0c0";
if((returnvalue&1) ==1)
{
buttoncolor= "#B0FFB0";
}
returnvalue/=2;
document.getElementById(buttonid).style.background=buttoncolor;
}
}
var readcallback = function(macro,args,response){
var returnvalue = parseInt(response);
var moduleid = parseInt(args[0]);
var pinid = parseInt(args[1]);
// let's build the button name
var buttonid = generateButtonName(moduleid,pinid);
var buttoncolor = "#c0c0c0";
if(returnvalue ==1)
{
buttoncolor= "#B0FFB0";
}
document.getElementById(buttonid).style.background=buttoncolor;
}
function togglePin(click_id,module,Pin)
{
webiopi().callMacro("togglePin",[module,Pin],readcallback);
}
function allOFF()
{
for ( nModule = 0 ; nModule < 3 ; nModule++)
{
webiopi().callMacro("allOFF",[nModule]);
for ( i = 0 ; i < 8 ; i++)
{
var buttonid = generateButtonName(nModule,i);
document.getElementById(buttonid).style.background= "#C0C0C0";
}
}
}
</script>
<style type="text/css">
button {
margin: 1px 1px 1px 1px;
width: auto;
height: auto;
font-size: 10pt;
font-weight: bold;
color: black;
padding:5px;
background-color:#c0c0c0;
}
</style>
</head>
<body>
<script type="text/javascript">
document.write("<p align='center'><table><br>");
for( nPin=0; nPin < 8 ; nPin++)
{
document.writeln("<tr>");
for( nModule=0 ; nModule < 3 ; nModule++)
{
document.write("<td align='center'>");
var buttonName= generateButtonName(nModule,nPin);
var abutton = "<button id='" + buttonName + "' name='" + buttonName ;
abutton += "' onclick='togglePin(this.id,";
abutton += nModule + "," + nPin + ")'>";
abutton += "Module " + nModule + " IO " + nPin + "</button></td>";
document.writeln(abutton);
}
document.writeln("</tr>");
}
document.writeln("<tr><td/><td><center><button id='alloff' name='alloff' onclick='allOFF()'>ALL OFF</button></center></td>");
document.writeln("</table></p>");
</script>
</body> </html>