-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
224 lines (204 loc) · 6.87 KB
/
index.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<title>Watch Floor</title>
</head>
<body onload="onCreationComplete()">
<script language="JavaScript" type="text/javascript">
var danceFloorIsActuallyBuiltAndIsInFrontOfYouOnTheGroundAndPeopleAreDancingOnIt = true;
var howManyArms = 10;
var whichOne = "huzzah1/"
var totalTimeTimerIntervalUsedForCanceling = window.setInterval(onTimerTick, 35);
// handles the click event, sends the query
var mqttMessageQueue = [];
var boxArray1 = [];
var boxArray2 = [];
var boxArray3 = [];
var boxArray4 = [];
var boxArray5 = [];
var boxArray6 = [];
var boxArray7 = [];
var boxArray8 = [];
var boxArray9 = [];
var boxArray10 = [];
var huzzah1;
var huzzah2;
var huzzah3;
var huzzah4;
var huzzah5;
var huzzah6;
var huzzah7;
var huzzah8;
var huzzah9;
var huzzah10;
function onCreationComplete(){
var numberOfColumns = 10;
var lengthOfColumns = 10;
for(var i = 1; i <= 10; i++){
for(var j = 1; j <= 10; j++){
var canvasTag = '<canvas id="column'+i+'Box'+j+'" style="position:absolute; border:2px solid #000000;"></canvas>';
//$('body').append(canvasTag)
var myLightBox = new lightBox();
myLightBox.init(i, j);
this["boxArray"+i].push(myLightBox);
}
var myHuzzah = new huzzah();
myHuzzah.init(i, this["boxArray"+i]);
this["huzzah"+i] = myHuzzah;
}
huzzah2.setLightsToAColor("#00ff00");
huzzah5.turboRainbow();
huzzah6.nyanCat();
huzzah9.testBuffer();
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function grbToHex(g, r, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function onTimerTick(){
if(mqttMessageQueue.length > 0){
var node = mqttMessageQueue.shift();
dispatch(node.topic, node.message);
}
}
function queueMessage(obj){
mqttMessageQueue.push(obj);
}
function getOutput() {
if(danceFloorIsActuallyBuiltAndIsInFrontOfYouOnTheGroundAndPeopleAreDancingOnIt){
$.ajax({
url:'domqtt.php?topic='+document.getElementById('topicTxt').value+'&message='+document.getElementById('messageTxt').value,
complete: function (response) {
$('#output').html(response.responseText);
},
error: function () {
$('#output').html('Bummer: there was an error!');
}
});
//return false;
}
//virtualDispatch(document.getElementById('topicTxt').value, document.getElementById('messageTxt').value);
return false;
}
function dispatch(topic, message){
if(danceFloorIsActuallyBuiltAndIsInFrontOfYouOnTheGroundAndPeopleAreDancingOnIt){
$.ajax({
url:'domqtt.php?topic='+topic+'&message='+message,
complete: function (response) {
$('#output').html(response.responseText);
},
error: function () {
$('#output').html('Bummer: there was an error!');
}
});
//return;
}
//virtualDispatch(topic, message);
}
function virtualDispatch(topic, message){
console.log(topic);
console.log(message);
var arr = topic.split("/");
var huzzah = arr[0];
var method = arr[1];
this[huzzah][method](message);
}
function publish(topic, message){
if(whichOne == "all"){
for(var i = 1; i <= howManyArms; i++){
var obj = {};
obj.topic = "huzzah"+i+"/"+topic;
obj.message = message;
queueMessage(obj);
}
}else{
var obj = {};
obj.topic = whichOne+topic;
obj.message = message;
queueMessage(obj);
}
}
function chooseWhichOne(str){
whichOne = str;
}
function turboRainbow(){
publish("turboRainbow", "true");
}
function nyanCat(){
publish("nyanCat", "true");
}
function whiteTrain(){
publish("whiteTrain", "true");
}
function tenRotate(){
publish("tenRotate", "true");
}
function slideAway(){
publish("slideAway", "true");
}
function turnOffLights(){
publish("turnOffLights", "true");
}
function sparkle(){
publish("sparkle", "true");
}
function twinkleToes(){
publish("twinkleToes", "true");
}
</script>
<center><h1>Dance Floor Interface</h1></center>
<div id="dfi" style="position:absolute; left:10px; top:100px;">
<br/>
Topic: <input id="topicTxt" type="text" maxlength="128" size="100"//>
<br/>
Message: <input id="messageTxt" type="text" maxlength="128" size="100"/>
<br/>
<a href="#" onclick="return getOutput();"> Publish </a>
<br/>
<div id="output"></div>
<button onclick="chooseWhichOne('all');"> All </button>
<button onclick="chooseWhichOne('huzzah1/');"> Huzzah 1 </button>
<button onclick="chooseWhichOne('huzzah2/');"> Huzzah 2 </button>
<button onclick="chooseWhichOne('huzzah3/');"> Huzzah 3 </button>
<button onclick="chooseWhichOne('huzzah4/');"> Huzzah 4 </button>
<button onclick="chooseWhichOne('huzzah5/');"> Huzzah 5 </button>
<button onclick="chooseWhichOne('huzzah6/');"> Huzzah 6 </button>
<button onclick="chooseWhichOne('huzzah7/');"> Huzzah 7 </button>
<button onclick="chooseWhichOne('huzzah8/');"> Huzzah 8 </button>
<button onclick="chooseWhichOne('huzzah9/');"> Huzzah 9 </button>
<button onclick="chooseWhichOne('huzzah10/');"> Huzzah 10 </button>
<br/>
<button onclick="turnOffLights();"> turnOffLights </button>
<button onclick="randomSquares();"> randomSquares </button>
<button onclick="thirtyToOne();"> thirtyToOne </button>
<button onclick="turboRainbow();"> turboRainbow </button>
<button onclick="nyanCat();"> nyanCat </button>
<button onclick="whiteTrain();"> whiteTrain </button>
<button onclick="tenRotate();"> tenRotate </button>
<button onclick="slideAway();"> slideAway </button>
<button onclick="sparkle();"> sparkle </button>
<button onclick="twinkleToes();"> twinkleToes </button>
<br/><br/>
<br/><br/>
Box: <input id="boxTxt" type="text" maxlength="2" size="5"/>
Red: <input id="redTxt" type="text" maxlength="3" size="5"/>
Green: <input id="greenTxt" type="text" maxlength="3" size="5"/>
Blue: <input id="blueTxt" type="text" maxlength="3" size="5"/>
<button onclick="fireBullet();"> fireBullet </button>
<button onclick="setRowToColor();"> setBoxToColor </button>
<button onclick="setColumnToColor();"> setColumnToColor </button>
<button onclick="randomColorWipes();"> randomColorWipes </button>
<button onclick="wipeToColor();"> wipeToColor </button>
</div>
<script src="jquery-3.1.1.js" language="javascript"></script>
<script src="lightbox.js" language="javascript"></script>
<script src="huzzah.js" language="javascript"></script>
<script src="danceFunctions.js"></script>
</body>
</html>