-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgarage2.html
379 lines (347 loc) · 11.3 KB
/
garage2.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!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="height = device-height, width = device-width, user-scalable = no"/>
<title>Garage Door Opener</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
var contentl, contentl2, buttonl;
contentl = $("#contentl");
contentl2 = $("#openCloseButtonl");
var contentr, contentr2, buttonr;
contentr = $("#contentr");
contentr2 = $("#openCloseButtonr");
var l_garage_op='', r_garage_op='';
var l_garage_log=[], r_garage_log=[];
var l_garage_cnt=0, r_garage_cnt=0;
var max_cnt=10;
$(checkStatus);
webiopi().setFunction(17,"in"); //Left garage door button
webiopi().setFunction(7,"in"); //left garage door sensor
webiopi().setFunction(18,"in"); //right garage door button
webiopi().setFunction(8,"in"); //right garage door sensor
// create an "OPEN" labeled button for GPIO
buttonl = webiopi().createGPIOButton(7, "");
contentl2.append(buttonl); // append button to content div
// create button that calls the mousedown function below
buttonl = webiopi().createButton("button", "LEFT GARAGE DOOR", showConfirml );
contentl.append(buttonl); // append button to content div
// create an "OPEN" labeled button for GPIO
buttonr = webiopi().createGPIOButton(8, "");
contentr2.append(buttonr); // append button to content div
// create button that calls the mousedown function below
buttonr = webiopi().createButton("button", "RIGHT GARAGE DOOR", showConfirmr );
contentr.append(buttonr); // append button to content div
hideConfirml();
hideConfirmr();
var update_l_log = function l_log_info(macro,args,data){
l_garage_log = data.split('++');
l_garage_cnt = l_garage_log.length;
if(l_garage_cnt > 0){
str1=l_garage_log[0].split(' ');
l_garage_log[0]=str1[0].substr(0,16)+' '+str1[1];
}
var cnt=1;
while(cnt < l_garage_log.length-1){
str1=l_garage_log[cnt].split(' ');
l_garage_log[cnt]=str1[0].substr(0,17)+' '+str1[1];
cnt++;
}
var res=build_log(l_garage_log,l_garage_cnt-1);
document.getElementById('logl').innerHTML = res
}
webiopi().callMacro('l_log_read',' ',update_l_log);
var update_r_log = function r_log_info(macro,args,data){
r_garage_log = data.split('++');
r_garage_cnt = r_garage_log.length;
if(r_garage_cnt > 0){
str1=r_garage_log[0].split(' ');
r_garage_log[0]=str1[0].substr(0,16)+' '+str1[1];
}
var cnt=1;
while(cnt < r_garage_log.length-1){
str1=r_garage_log[cnt].split(' ');
r_garage_log[cnt]=str1[0].substr(0,17)+' '+str1[1];
cnt++;
}
var res=build_log(r_garage_log,r_garage_cnt-1);
document.getElementById('logr').innerHTML = res
}
webiopi().callMacro('r_log_read',' ',update_r_log);
function checkStatus() {
if ($('#gpio7').hasClass('LOW')){
$("#gpio7").html('CLOSED');
}else {
$("#gpio7").html('OPEN');
}
if ($('#gpio8').hasClass('LOW')){
$("#gpio8").html('CLOSED');
}else {
$("#gpio8").html('OPEN');
}
setTimeout(checkStatus,1000)
}
// add new data on top of array
function push_log(g_log,g_cnt,data){
var cnt=g_cnt;
while(cnt!=0){
if(cnt<=max_cnt){
g_log[cnt]=g_log[cnt-1];
}
cnt--;
}
g_log[0]=data;
var new_cnt=max_cnt+1;
if(g_cnt <= max_cnt){
new_cnt=g_cnt+1;
}
return new_cnt;
}
// Build garage log
function build_log(g_log,g_cnt) {
var res='<table align=center>';
var cnt=0;
while(cnt < g_cnt){
res+='<tr><td>'+g_log[cnt]+'</td></tr>';
cnt++
}
res+='<table>';
return res;
}
// this function gets called by the mousedown function below - it sets gpio7 back to 'IN'
function mouseupl() {
webiopi().setFunction(17,"in");
//document.getElementById('buttonl').disable = "false";
}
// this function sets gpio7 to 'OUT' which will trip the relay. After .5 second it calls mouseup above.
// hides the confirmation div and makes doge face change
function mousedownl() {
webiopi().setFunction(17,"out");
//window.alert("RELAY CLOSED");
document.getElementById('yesl').style.visibility = "hidden";
document.getElementById('nol').style.visibility = "hidden"
document.getElementById('confirmTextl').style.visibility = "hidden";
setTimeout(mouseupl, 500);
}
// after pressing no hide the confirmation div
function hideConfirml() {
//document.getElementById('buttonl').disable = "false";
document.getElementById('yesl').style.visibility = "hidden";
document.getElementById('nol').style.visibility = "hidden";
document.getElementById('confirmTextl').style.visibility = "hidden";
}
// show confirmation div after pressing garage door button
function showConfirml() {
//document.getElementById('buttonl').disabled="true";
document.getElementById('yesl').onclick = mousedownl;
document.getElementById('nol').onclick = hideConfirml;
document.getElementById('yesl').style.visibility = "visible";
document.getElementById('nol').style.visibility = "visible";
document.getElementById('confirmTextl').style.visibility = "visible";
}
// this function gets called by the mousedown function below - it sets gpio8 back to 'IN'
function mouseupr() {
webiopi().setFunction(18,"in");
}
// this function sets gpio8 to 'OUT' which will trip the relay. After .5 second it calls mouseup above.
// hides the confirmation div and makes doge face change
function mousedownr() {
//document.getElementById('buttonr').disabled="false";
webiopi().setFunction(18,"out");
//window.alert("RELAY CLOSED");
document.getElementById('yesr').style.visibility = "hidden";
document.getElementById('nor').style.visibility = "hidden";
document.getElementById('confirmTextr').style.visibility = "hidden";
setTimeout(mouseupr, 500);
}
// after pressing no hide the confirmation div
function hideConfirmr() {
//document.getElementById('buttonr').disable = "false";
document.getElementById('yesr').style.visibility = "hidden";
document.getElementById('nor').style.visibility = "hidden";
document.getElementById('confirmTextr').style.visibility = "hidden";
}
// show confirmation div after pressing garage door button
function showConfirmr() {
//document.getElementById('buttonr').disabled="true";
document.getElementById('yesr').onclick = mousedownr;
document.getElementById('nor').onclick = hideConfirmr;
document.getElementById('yesr').style.visibility = "visible";
document.getElementById('nor').style.visibility = "visible";
document.getElementById('confirmTextr').style.visibility = "visible";
}
// constantly refresh status to see if door is open or closed
webiopi().refreshGPIO(true)
});
</script>
<style type="text/css">
body {
font-family: Arial, Helvetica, Sans-Serif;
padding: 0px;
margin: 0px;
background: #CCCCCC;
}
#content {
width: 150px;
height: 150px;
}
button {
display: block;
margin: 10px 10px;
margin-left: auto;
margin-right: auto;
padding: 0px;
width: 150px;
height: 50px;
font-size: 12pt;
font-weight: bold;
color: black;
border-radius: 10px !important;
}
button#button {
height: 150px !important;
background: #808080 url('doge-static.png') no-repeat center bottom;
border-radius: 10px !important;
cursor: pointer !important;
}
#gpio8.LOW {
color: #FFFFFF !important;
}
#gpio8.HIGH {
color: #FFFFFF !important;
}
#gpio7.LOW {
color: #FFFFFF !important;
}
#gpio7.HIGH {
color: #FFFFFF !important;
}
#header {
margin-left: auto;
margin-right: auto;
margin-top: 0px !important;
padding-top: 0px !important;
}
#confirmText {
margin-left: auto;
margin-right: auto;
padding: 0px;
margin-top: 0px;
visibility: hidden;
width: 300px;
}
#log {
text-align: center;
margin-top: 0px !important;
margin-bottom: 10px !important;
font-size: 6pt;
}
h3 {
text-align: center;
margin-top: 0px !important;
margin-bottom: 10px !important;
}
#confirmBox {
height: 60px;
width: 150px;
margin-left: auto;
margin-right: auto;
position:relative;
visibility: hidden;
}
#yesl {
background-color: green;
float: center;
}
#nol {
background-color: red;
float: center;
}
#yesr {
background-color: green;
float: center;
}
#nor {
background-color: red;
float: center;
}
.confirmButton {
border: 3px solid #000000;
border-radius: 10px;
cursor: pointer;
height: 50px;
width: 150px;
font-size: 12pt;
font-weight: bold;
text-align: center;
line-height: 50px;
}
#openCloseButton {
width: 150px;
height: 60px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>
<div id="headerl"><h3>Left Door</h3></div>
</th>
<th>
<div id="headerr"><h3>Right Door</h3></div>
</th>
</tr>
<tr>
<td>
<div id="openCloseButtonl" style="margin-left: auto; margin-right: auto; position:relative"></div>
</td>
<td>
<div id="openCloseButtonr" style="margin-left: auto; margin-right: auto; position:relative"></div>
</td>
</tr>
<tr>
<td>
<div id="contentl" style="margin-left: auto; margin-right: auto; position:relative"></div>
</td>
<td>
<div id="contentr" style="margin-left: auto; margin-right: auto; position:relative"></div>
</td>
</tr>
<tr>
<td>
<div id="confirmTextl"><h3>Are you sure?</h3></div>
</td>
<td>
<div id="confirmTextr"><h3>Are you sure?</h3></div>
</td>
</tr>
<tr>
<td>
<div id="yesl" style="margin-left: auto; margin-right: auto; position:relative" class="confirmButton">YES</div>
</td>
<td>
<div id="yesr" style="margin-left: auto; margin-right: auto; position:relative" class="confirmButton">YES</div>
</td>
</tr>
<tr>
<td>
<div id="nol" style="margin-left: auto; margin-right: auto; position:relative" class="confirmButton">NO</div>
</td>
<td>
<div id="nor" style="margin-left: auto; margin-right: auto; position:relative" class="confirmButton">NO</div>
</td>
</tr>
<tr>
<td>
<div id="logl" style="margin-left: auto; margin-right: auto; position:relative" class="log"> </div>
</td>
<td>
<div id="logr" style="margin-left: auto; margin-right: auto; position:relative" class="log"> </div>
</td>
</tr>
</table>
</body>
</html>