This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
index_html.h
256 lines (242 loc) · 8.43 KB
/
index_html.h
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
String INDEX_HTML = R"(<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Cache-Control' content='no-cache, no-store, must-revalidate' />
<meta http-equiv='Pragma' content='no-cache' />
<meta http-equiv='Expires' content='0' />
<title>{NAME}</title>
<link rel='stylesheet' href='https://unpkg.com/onsenui/css/onsenui.css'>
<link rel='stylesheet' href='https://unpkg.com/onsenui/css/onsen-css-components.min.css'>
<script src='https://unpkg.com/onsenui/js/onsenui.min.js'></script>
<script src='https://unpkg.com/jquery/dist/jquery.min.js'></script>
<script>
var cversion = '{VERSION}';
var wsUri = 'ws://'+location.host+':81/';
var repo = 'motor-on-roller-blind-ws';
window.fn = {};
window.fn.open = function() {
var menu = document.getElementById('menu');
menu.open();
};
window.fn.load = function(page) {
var content = document.getElementById('content');
var menu = document.getElementById('menu');
content.load(page)
.then(menu.close.bind(menu)).then(setActions());
};
var gotoPos = function(percent){
doSend(percent);
};
var instr = function(action){
doSend('('+action+')');
};
var setActions = function(){
doSend('(update)');
$.get('https://api.github.com/repos/nidayand/'+repo+'/releases', function(data){
if (data.length>0 && data[0].tag_name !== cversion){
$('#cversion').text(cversion);
$('#nversion').text(data[0].tag_name);
$('#update-card').show();
}
});
setTimeout(function(){
$('#arrow-close').on('click', function(){$('#setrange').val(100);gotoPos(100);});
$('#arrow-open').on('click', function(){$('#setrange').val(0);gotoPos(0);});
$('#setrange').on('change', function(){gotoPos($('#setrange').val())});
$('#arrow-up-man').on('click', function(){instr('-1')});
$('#arrow-down-man').on('click', function(){instr('1')});
$('#arrow-stop-man').on('click', function(){instr('0')});
$('#set-start').on('click', function(){instr('start')});
$('#set-max').on('click', function(){instr('max');});
}, 200);
};
$(document).ready(function(){
setActions();
});
var websocket;
var timeOut;
function retry(){
clearTimeout(timeOut);
timeOut = setTimeout(function(){
websocket=null; init();},5000);
};
function init(){
ons.notification.toast({message: 'Connecting...', timeout: 1000});
try{
websocket = new WebSocket(wsUri);
websocket.onclose = function () {};
websocket.onerror = function(evt) {
ons.notification.toast({message: 'Cannot connect to device', timeout: 2000});
retry();
};
websocket.onopen = function(evt) {
ons.notification.toast({message: 'Connected to device', timeout: 2000});
setTimeout(function(){doSend('(update)');}, 1000);
};
websocket.onclose = function(evt) {
ons.notification.toast({message: 'Disconnected. Retrying', timeout: 2000});
retry();
};
websocket.onmessage = function(evt) {
try{
var msg = JSON.parse(evt.data);
if (typeof msg.position !== 'undefined'){
$('#pbar').attr('value', msg.position);
};
if (typeof msg.set !== 'undefined'){
$('#setrange').val(msg.set);
};
} catch(err){}
};
} catch (e){
ons.notification.toast({message: 'Cannot connect to device. Retrying...', timeout: 2000});
retry();
};
};
function doSend(msg){
if (websocket && websocket.readyState == 1){
websocket.send(msg);
}
};
window.addEventListener('load', init, false);
window.onbeforeunload = function() {
if (websocket && websocket.readyState == 1){
websocket.close();
};
};
</script>
</head>
<body>
<ons-splitter>
<ons-splitter-side id='menu' side='left' width='220px' collapse swipeable>
<ons-page>
<ons-list>
<ons-list-item onclick='fn.load("home.html")' tappable>
Home
</ons-list-item>
<ons-list-item onclick='fn.load("settings.html")' tappable>
Settings
</ons-list-item>
<ons-list-item onclick='fn.load("about.html")' tappable>
About
</ons-list-item>
</ons-list>
</ons-page>
</ons-splitter-side>
<ons-splitter-content id='content' page='home.html'></ons-splitter-content>
</ons-splitter>
<template id='home.html'>
<ons-page>
<ons-toolbar>
<div class='left'>
<ons-toolbar-button onclick='fn.open()'>
<ons-icon icon='md-menu'></ons-icon>
</ons-toolbar-button>
</div>
<div class='center'>
{NAME}
</div>
</ons-toolbar>
<ons-card>
<div class='title'>Adjust position</div>
<div class='content'><p>Move the slider to the wanted position or use the arrows to open/close to the max positions</p></div>
<ons-row>
<ons-col width='40px' style='text-align: center; line-height: 31px;'>
</ons-col>
<ons-col>
<ons-progress-bar id='pbar' value='75'></ons-progress-bar>
</ons-col>
<ons-col width='40px' style='text-align: center; line-height: 31px;'>
</ons-col>
</ons-row>
<ons-row>
<ons-col width='40px' style='text-align: center; line-height: 31px;'>
<ons-icon id='arrow-open' icon='fa-arrow-up' size='2x'></ons-icon>
</ons-col>
<ons-col>
<ons-range id='setrange' style='width: 100%;' value='25'></ons-range>
</ons-col>
<ons-col width='40px' style='text-align: center; line-height: 31px;'>
<ons-icon id='arrow-close' icon='fa-arrow-down' size='2x'></ons-icon>
</ons-col>
</ons-row>
</ons-card>
<ons-card id='update-card' style='display:none'>
<div class='title'>Update available</div>
<div class='content'>You are running <span id='cversion'></span> and <span id='nversion'></span> is the latest. Go to <a href='https://github.com/nidayand/motor-on-roller-blind-ws/releases'>the repo</a> to download</div>
</ons-card>
</ons-page>
</template>
<template id='settings.html'>
<ons-page>
<ons-toolbar>
<div class='left'>
<ons-toolbar-button onclick='fn.open()'>
<ons-icon icon='md-menu'></ons-icon>
</ons-toolbar-button>
</div>
<div class='center'>
Settings
</div>
</ons-toolbar>
<ons-card>
<div class='title'>Instructions</div>
<div class='content'>
<p>
<ol>
<li>Use the arrows and stop button to navigate to the top position i.e. the blind is opened</li>
<li>Click the START button</li>
<li>Use the down arrow to navigate to the max closed position</li>
<li>Click the MAX button</li>
<li>Calibration is completed!</li>
</ol>
</p>
</div>
</ons-card>
<ons-card>
<div class='title'>Control</div>
<ons-row style='width:100%'>
<ons-col style='text-align:center'><ons-icon id='arrow-up-man' icon='fa-arrow-up' size='2x'></ons-icon></ons-col>
<ons-col style='text-align:center'><ons-icon id='arrow-stop-man' icon='fa-stop' size='2x'></ons-icon></ons-col>
<ons-col style='text-align:center'><ons-icon id='arrow-down-man' icon='fa-arrow-down' size='2x'></ons-icon></ons-col>
</ons-row>
</ons-card>
<ons-card>
<div class='title'>Store</div>
<ons-row style='width:100%'>
<ons-col style='text-align:center'><ons-button id='set-start'>Set Start</ons-button></ons-col>
<ons-col style='text-align:center'> </ons-col>
<ons-col style='text-align:center'><ons-button id='set-max'>Set Max</ons-button></ons-col>
</ons-row>
</ons-card>
</ons-page>
</template>
<template id='about.html'>
<ons-page>
<ons-toolbar>
<div class='left'>
<ons-toolbar-button onclick='fn.open()'>
<ons-icon icon='md-menu'></ons-icon>
</ons-toolbar-button>
</div>
<div class='center'>
About
</div>
</ons-toolbar>
<ons-card>
<div class='title'>Motor on a roller blind</div>
<div class='content'>
<p>
<ul>
<li>3d print files and instructions: <a href='https://www.thingiverse.com/thing:2392856' target='_blank'>https://www.thingiverse.com/thing:2392856</a></li>
<li>Github: <a href='https://github.com/nidayand/motor-on-roller-blind-ws' target='_blank'>https://github.com/nidayand/motor-on-roller-blind-ws</a></li>
<li>Licensed under <a href='https://raw.githubusercontent.com/nidayand/motor-on-roller-blind-ws/master/LICENSE' target='_blank'>MIT License</a></li>
</ul>
</p>
</div>
</ons-card>
</ons-page>
</template>
</body>
</html>
)";