-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_client.html
162 lines (148 loc) · 5.6 KB
/
web_client.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<html>
<head>
<title>OPC Control Panel</title>
<style>
.horizontal .block {
display: block;
position: absolute;
top: 0px;
left: 0px;
width: 33%;
height: 50%;
cursor: pointer;
}
.horizontal #pot1 {
left: 34%;
}
.horizontal #pot2 {
left: 67%;
}
.horizontal #manual {
width: 34%;
}
.horizontal #range {
top: 50%;
width: 100%;
height: 50%;
}
.horizontal .bar {
background-color: gray;
position: absolute;
left: 0;
width: 100%;
z-index: 0;
}
.horizontal .text {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
font-weight: bold;
text-align: center;
z-index: 1;
}
.horizontal #range .bar {
height: 100%;
top: 0;
}
</style>
</head>
<body class="horizontal">
<div id="manual" class="block">
<div class="bar" style="top: 0;height: 100%;"></div>
<div class="text">man</div>
</div>
<div id="pot1" class="block">
<div class="bar" style="top: 20%;height: 80%;"></div>
<div class="text">80%</div>
</div>
<div id="pot2" class="block">
<div class="bar" style="top: 35%;height: 65%;"></div>
<div class="text">65%</div>
</div>
<div id="range" class="block">
<div class="bar" style="width: 33%;"></div>
<div class="text">33%</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
var socket = io();
socket.on('update', function(data) {
if (data.name == "AI0")
update_pot1(data.value);
else if (data.name == "AI1")
update_pot2(data.value);
else if (data.name == "MAN")
update_range(data.value);
else if (data.name == "web_modus")
update_modus(data.value);
});
elManual = document.getElementById("manual");
elManual.bar = elManual.querySelector(".bar");
elManual.text = elManual.querySelector(".text");
elManual.addEventListener("click", function(e) {
socket.emit('man');
});
elPot1 = document.getElementById("pot1");
elPot1.bar = elPot1.querySelector(".bar");
elPot1.text = elPot1.querySelector(".text");
elPot1.addEventListener("click", function(e) {
socket.emit('pot1');
});
elPot2 = document.getElementById("pot2");
elPot2.bar = elPot2.querySelector(".bar");
elPot2.text = elPot2.querySelector(".text");
elPot2.addEventListener("click", function(e) {
socket.emit('pot2');
});
elRange = document.getElementById("range");
elRange.bar = elRange.querySelector(".bar");
elRange.text = elRange.querySelector(".text");
window.addEventListener("resize", ajuistFonts);
ajuistFonts();
elRange.addEventListener("click", function(e) {
var p = ((e.x / window.innerWidth) * 100 + 0.5) | 0;
socket.emit('update', p);
});
function ajuistFonts() {
var line = (window.innerHeight / 2),
font = (window.innerHeight / 6);
elPot1.text.style.lineHeight = line + "px";
elPot1.text.style.fontSize = font + "px";
elPot2.text.style.lineHeight = line + "px";
elPot2.text.style.fontSize = font + "px";
elManual.text.style.lineHeight = line + "px";
elManual.text.style.fontSize = font + "px";
elRange.text.style.lineHeight = line + "px";
elRange.text.style.fontSize = font + "px";
}
function update_pot1(value) {
elPot1.bar.style.top = (100 - value) + "%";
elPot1.bar.style.height = value + "%";
elPot1.text.innerHTML = value + "%";
}
function update_pot2(value) {
elPot2.bar.style.top = (100 - value) + "%";
elPot2.bar.style.height = value + "%";
elPot2.text.innerHTML = value + "%";
}
function update_range(value){
elRange.bar.style.width = elRange.text.innerHTML = value + "%";
}
function update_modus(value) {
Array.prototype.forEach.call(document.body.querySelectorAll(".bar"), function(el) {
el.style.backgroundColor = "gray";
});
if (value == "AI0")
elPot1.bar.style.backgroundColor = "blue";
else if (value == "AI1")
elPot2.bar.style.backgroundColor = "blue";
else if (value == "MAN") {
elManual.bar.style.backgroundColor = "blue";
elRange.bar.style.backgroundColor = "blue";
}
}
</script>
</body>
</html>