forked from lionello/nodemcu-httpd
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrgb.html
152 lines (143 loc) · 3.84 KB
/
rgb.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
<!DOCTYPE html>
<html>
<head>
<title>DSL lights RGB</title>
<meta name="mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" sizes="82x99" href="http://www.dimsumlabs.com/wp-content/uploads/2014/08/logo_dsl_text_82x99.png"/>
<style>
body {
background: #FFFFFF;
}
.slidercontainer {
margin:20px;
margin-top:50px;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 25px;
height: 25px;
border-radius: 50%;
cursor: pointer;
}
#red::-webkit-slider-thumb {
background: #FF0000;
}
#red::-moz-range-thumb {
background: #FF0000;
}
#green::-webkit-slider-thumb {
background: #008800;
}
#green::-moz-range-thumb {
background: #008800;
}
#blue::-webkit-slider-thumb {
background: #0000FF;
}
#blue::-moz-range-thumb {
background: #0000FF;
}
.colorvalue {
text-align: center;
}
</style>
</head>
<body style="margin:5">
<p class="slidercontainer">
<input type="range" min="0" max="1023" value="199" class="slider" id="red"/>
</p>
<div class="colorvalue">R: <span id="red_val">X</span></div>
<p class="slidercontainer">
<input type="range" min="0" max="1023" value="199" class="slider" id="green"/>
</p>
<div class="colorvalue">G: <span id="green_val">X</span></div>
<p class="slidercontainer">
<input type="range" min="0" max="1023" value="199" class="slider" id="blue"/>
</p>
<div class="colorvalue">B: <span id="blue_val">X</span></div>
</body>
<script type="text/javascript">
(function (){
var redslider = document.getElementById("red");
var redout = document.getElementById("red_val");
var greenslider = document.getElementById("green");
var greenout = document.getElementById("green_val");
var blueslider = document.getElementById("blue");
var blueout = document.getElementById("blue_val");
var host = location.hostname;
var canSend = false;
// Get existing values
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
var rgb = req.responseText.split("\n");
redslider.value = 1023 - rgb[0];
greenslider.value = 1023 - rgb[1];
blueslider.value = 1023 - rgb[2];
redout.innerHTML = redslider.value;
greenout.innerHTML = greenslider.value;
blueout.innerHTML = blueslider.value;
canSend = true;
}
}
req.open("GET", 'http://'+host+'/rgb', true);
req.send();
function sendColour() {
if (!canSend) {
return;
}
var params = [
'r=' + (1023-redslider.value),
'g=' + (1023-greenslider.value),
'b=' + (1023-blueslider.value)
].join('&');
canSend = false;
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4) {
setTimeout(function() { canSend = true; }, 100);
}
}
req.open("POST", 'http://'+host+'/rgb.lua?' + params, true);
req.send();
}
redslider.oninput = function() {
redout.innerHTML = this.value;
}
redslider.onchange = function() {
sendColour();
}
greenslider.oninput = function() {
greenout.innerHTML = this.value;
}
greenslider.onchange = function() {
sendColour();
}
blueslider.oninput = function() {
blueout.innerHTML = this.value;
}
blueslider.onchange = function() {
sendColour();
}
})();
</script>
</html>