-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
186 lines (165 loc) · 5.01 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
---
layout: default
title: HearthTub
---
<div class="header">
<h1 id="title">
HearthTub
</h1>
<!--<a class="extra" href="/">home</a> -->
</div>
<p id='error' class='error'>
Waiting for <a href='http://172.168.1.75'>hottube</a>...
Are you on Hearth WiFi?
</p>
<div id='hottub' class='hide'>
<div class='row'>
<div class='col-sm-6'>
<div id='controls'>
<div class='panel'>
<h1 id='temp'>
<div><span class='f'></span> °F</div>
<small><span class='c'></span> °C</small>
</h1>
</div>
<div class='panel'>
<h1 id='set'>
<span class='pull-left btn-group-vertical'>
<button class='btn btn-default' id='plus-set'>
<span class="glyphicon glyphicon-plus"></span>
</button>
<button class='btn btn-default' id='minus-set'>
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<button class='btn btn-default btn-lg pull-right' id='flame-on' >
<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>
</button>
<div><span class='f'></span> °F</div>
<small><span class='c'></span> °C</small>
</h1>
</div>
<div class='panel clearfix'>
<h1 id='jets'>
<span class='pull-left btn-group-vertical'>
<button class='btn btn-default' id='plus-jets'>
<span class="glyphicon glyphicon-plus"></span>
</button>
<button class='btn btn-default' id='minus-jets'>
<span class="glyphicon glyphicon-minus"></span>
</button>
</span>
<button id='jets-on' class='pull-right btn btn-lg btn-default' >
<span class="glyphicon glyphicon-tint" aria-hidden="true"></span>
</button>
<div><span id='time'>0</span> min</div>
<small><span id='ms'></span> ms</small>
</h1>
</div>
</div>
</div>
</div>
</div>
<script>
function updateTemp(temperature) {
$('#temp .f').text(temperature.fahrenheit);
$('#temp .c').text(temperature.celsius);
}
function updateSet(deg_f) {
var deg_c = Math.round(((deg_f - 32)*5.0/9.0)*100)/100;
$('#set .f').text(deg_f);
$('#set .c').text(deg_c);
updateHeat(getTemp() <= getSetTemp());
}
function getTemp() {
return parseFloat($('#temp .f').text());
}
function getSetTemp() {
return parseFloat($('#set .f').text());
}
function incrementSet(increment) {
var increment = increment || 1;
updateSet(getSetTemp() + increment);
}
function incrementJets(increment) {
var increment = increment || 1;
updateJets((getJetsMinutes() + increment) * 60000);
}
function updateHeat(heat) {
$('#flame-on').toggleClass('on', heat);
}
function getJetsMillis() {
return parseInt($('#ms').text());
}
function getJetsMinutes() {
return parseInt($('#time').text());
}
function updateJets(ms) {
$('#ms').text(ms);
$('#time').text((ms / 60000).toFixed());
$('#jets-on').toggleClass('on', ms > 0);
}
function update() {
$.ajax('http://192.168.1.75/sensors.json').then(function(response) {
updateTemp(response.temperature);
$('#title').toggleClass('on', response.heater_pump);
var deg_f = getSetTemp();
if(response.set_temp.fahrenheit != deg_f) {
$.ajax('http://192.168.1.75/sf/' + deg_f);
} else {
updateHeat(response.heater_pump);
}
var ms = getJetsMillis();
var minutes = getJetsMinutes();
if(ms === 0 && response.jets > 0) {
$.ajax('http://192.168.1.75/j/off');
}
else if(Math.abs(response.jets - ms) >= 60000) {
$.ajax('http://192.168.1.75/j/on/' + minutes );
} else {
updateJets(response.jets);
}
setTimeout(update, 3000);
}).fail(function(request) {
$('#error').text(request.statusText).show();
});
};
$.ajax('http://192.168.1.75/sensors.json').then(function(response) {
$('#set .f').text(response.set_temp.fahrenheit);
$('#set .c').text(response.set_temp.celsius);
updateTemp(response.temperature);
updateHeat(response.heater_pump);
updateJets(response.jets);
$('#hottub').removeClass('hide');
$('#error').text('');
update();
$('#plus-set').click(function(e) {
incrementSet(1);
});
$('#minus-set').click(function(e) {
incrementSet(-1);
});
$('#plus-jets').click(function(e) {
incrementJets(1);
});
$('#minus-jets').click(function(e) {
incrementJets(-1);
});
$('#jets-on').click(function(e) {
if (getJetsMillis() > 0) {
updateJets(0);
} else {
updateJets(15 * 60000);
}
});
$('#flame-on').click(function(e) {
if (getSetTemp() === 104) {
updateSet(32);
} else {
updateSet(104);
}
});
}).fail(function(request) {
$('#error').text(request.statusText).show();
});
</script>