-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
468 lines (425 loc) · 17.8 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
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<!--
Author: Zhizhou Li <[email protected]>
Copyright 2015 Meteroi
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<title>Editor</title>
<style type="text/css" media="screen">
.ace_editor {
position: relative !important;
border: 1px solid lightgray;
margin: 0;
height: 600px;
width: 100%;
}
.ace_editor.fullScreen {
height: auto;
width: auto;
border: 0;
margin: 0;
position: fixed !important;
top: 0;
bottom: 0;
left: 0;
right: 0;
z-index: 10;
background: white;
}
.fullScreen {
overflow: hidden
}
.scrollmargin {
height: inherit;
text-align: left;
}
</style>
</head>
<body>
<img id=broadpic alt="">
<div id="IDE" class="">
<a href="#savedialog" role="button" class="btn" data-toggle="modal" title="save the program">save</a>
<span onclick="run()" class="btn btn-success" title="run the program">
run
</span>
<span onclick="stop()" class="btn btn-warning" title="stop the progrtam">
stop
</span>
<a href="#api_doc" role="button" class="btn btn-info" data-toggle="modal" onclick="load_api()" title="show the API">API</a>
<a href="docs/index.html" role="button" class="btn btn-info" data-toggle="modal" title="show the docs">docs</a>
<span onclick="reboot()" class="btn btn-danger" title="reboot the broad">
reboot
</span>
<span>
<div class="btn-group">
<button type="button" class="btn btn-primary" title="change the broad configuration">
Configurations
</button>
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul id=version_list class="dropdown-menu" role="menu">
</ul>
<span onclick="fpga()" class="btn btn-info" title="go to the fpga designer">
FPGAdesigner
</span>
</div>
</span>
<pre id="editor">
int main(int argn, char* argv[])
{
printf("openFPGArduino\n");
return 0;
}
</pre>
</div>
<div id=Ex>
</div>
<div class="panel panel-default">
<span onclick="clean_error()" class="btn btn-warning" title="clear the error log">
Clear error
</span>
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#error">
<div class="alert alert-error" role="alert"><b>Error</b>
</div>
</a>
</div>
<div id="error" class="panel-collapse collapse in">
</div>
</div>
</div>
<div>
<div class="panel panel-default">
<span onclick="clean_console()" class="btn btn-warning" title="clear the console log">
Clear console
</span>
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#console">
<div class="alert alert-info" role="alert"><b>Console</b>
</div>
</a>
</div>
<div id="console" class="panel-collapse collapse in">
</div>
</div>
</div>
<div>
<!-- Save file dialog -->
<div class="modal hide fade" id="savedialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Save the program</h3>
</div>
<div class="modal-body">
<div class="input-group">
<input id="dialog_filename" type="text" class="form-control" placeholder="filename">
<span class="input-group-addon">.c</span>
</div>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">close</a>
<a href="#" data-dismiss="modal" class="btn btn-primary" onclick="save()">save</a>
</div>
</div>
<!-- pop dialog -->
<div class="modal hide fade" id="popdialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Are you sure to delete?</h3>
</div>
<div class="modal-body">
<div class="input-group">
<p id="pop_message"></p>
</div>
</div>
<div class="modal-footer">
<a href="#" data-dismiss="modal" class="btn">No</a>
<a href="#" data-dismiss="modal" class="btn btn-primary" onclick="do_delete_example()">Yes</a>
</div>
</div>
<!-- API reference doc-->
<div id="api_doc" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="ModalLabel">API Reference Document</h3>
</div>
<div class="modal-body">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse1">
<div class="alert alert-info" role="alert"><b>void led(int id, char r, char g, char b)</b></div>
</a>
</div>
<div id="collapse1" class="panel-collapse collapse">
<div class="panel-body">
<p>Functionality: Sleep for seconds</p>
<p>Argument: </p>
<p>id: The id of led can be 0-3</p>
<p>r: The red color of led</p>
<p>g: The greem color of led</p>
<p>b: The blue color of led</p>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">close</button>
</div>
</div>
<script src="./ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var debug = false;
function debuginf(string) {
if (debug == true) {
console.log(string);
}
}
function ajax_rest_post(url, arg1, arg2) {
var xhr = new XMLHttpRequest();
var post;
xhr.open("post", url, false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
if (arg1 != undefined)
post = encodeURIComponent("arg1") + "=" + encodeURIComponent(arg1) + "&";
else
post = null;
if (arg2 != undefined)
post += encodeURIComponent("arg2") + "=" + encodeURIComponent(arg2) + "&";
xhr.send(post);
debuginf(xhr.status);
}
function load_config_list() {
var xhr = new XMLHttpRequest();
xhr.open("get", "load_config", false);
xhr.send();
var versionlist = xhr.responseText;
debuginf(versionlist);
var list = versionlist.split(',');
var html_list = "";
debuginf(list);
for (var index in list) {
debuginf(list[index]);
var name = list[index].split('.')[0];
var ext = list[index].split('.')[1];
if (ext == 'rbf') {
html_list += "<li><a href='#' onClick= configrations(event)>" +
name + "</a></li>";
}
}
document.getElementById("version_list").innerHTML = html_list;
}
function load_example_list() {
var xhr = new XMLHttpRequest();
xhr.open("get", "load_example", false);
xhr.send();
var examplelist = xhr.responseText;
var list = examplelist.split(',');
var html_list = "";
debuginf(list);
for (var index in list) {
debuginf(list[index]);
var name = list[index].split('.')[0];
var ext = list[index].split('.')[1];
if (ext == 'c') {
html_list += "<span id=" + name + " onmousedown='mousedown(event)' onmouseup='mouseup(event)' class='btn btn-info'>" + name + "</span>";
}
}
document.getElementById("Ex").innerHTML = html_list;
}
function is_function_type(str) {
var re = new RegExp("\\.*\\s([^\\(\\s]+)\\(.*\\);");
return str.match(re);
}
function is_comments(str) {
var re = new RegExp(".*//(.*)");
return str.match(re);
}
function load_api() {
var xhr = new XMLHttpRequest();
xhr.open("get", "api/openfpgaduino.h", false);
xhr.send();
var api_doc = xhr.responseText;
debuginf(api_doc);
var api_doc_lines = api_doc.split('\n');
debuginf(api_doc_lines);
var html_list = "";
var i = 0,
j = 0;
var math;
var comments_html = "";
while (i < api_doc_lines.length) {
while (math = is_comments(api_doc_lines[i])) {
comments_html += '<p>' + math[1] + '</p>';
i++;
}
if (func = is_function_type(api_doc_lines[i])) {
html_list += '<div class="panel panel-default"> \
<div class="panel-heading"> \
<a data-toggle="collapse" data-parent="#accordion" href="#collapse' + j + '"> \
<div class="alert alert-info" role="alert"><b>' + api_doc_lines[i] + '</b></div> \
</a> \
</div> \
<div id="collapse' + j + '" class="panel-collapse collapse"> \
<div class="panel-body">'
j++;
html_list += comments_html;
html_list +=
'</div> \
</div> \
</div>'
comments_html = "";
debuginf(func[1]);
}
i++;
}
debuginf(html_list);
document.getElementById("accordion").innerHTML = html_list;
}
var dom = require("ace/lib/dom");
//add command to all new editor instaces
require("ace/commands/default_commands").commands.push({
name: "Toggle Fullscreen",
bindKey: "F11",
exec: function(editor) {
dom.toggleCssClass(document.body, "fullScreen")
dom.toggleCssClass(editor.container, "fullScreen")
editor.resize()
}
})
// create first editor
var editor = ace.edit("editor");
editor.setTheme("ace/theme/tomorrow");
editor.session.setMode("ace/mode/c_cpp");
// event handle for webpage
function save() {
var code = editor.getValue();
var file = document.getElementById("dialog_filename").value;
debuginf("save");
if (file != "") {
ajax_rest_post("save", file, code);
load_example_list();
return true;
} else
return false;
}
function run() {
var code = editor.getValue();
debuginf("run");
debuginf(code);
ajax_rest_post("run", code);
}
function stop() {
debuginf("stop");
ajax_rest_post("stop");
}
function reboot() {
debuginf("reboot");
ajax_rest_post("reboot");
}
function configrations(event) {
var version = event.srcElement.innerText;
document.getElementById('broadpic').src = 'config/' + version + '.jpg';
debuginf("configrations");
debuginf(version);
ajax_rest_post("config", version);
}
function fpga() {
window.location.port = 8686;
}
function load_example(event) {
var example = event.srcElement.innerText;
debuginf(example);
var file = example + '.c';
debuginf("load code");
var xhr = new XMLHttpRequest();
xhr.open("get", "program/" + file, false);
xhr.send();
var get = xhr.responseText;
debuginf(get);
editor.setValue(get);
editor.clearSelection();
}
var timer = null;
function mousedown(event) {
load_example(event);
timer = setTimeout(function() {
delete_example(event)
}, 1500); //set the timeout
};
function mouseup(event) {
clearTimeout(timer);
};
function delete_example(event) {
var file = event.srcElement.innerText;
debuginf(file);
document.getElementById("pop_message").innerText = file;
$("#popdialog").modal();
}
function do_delete_example() {
file = document.getElementById("pop_message").innerText;
debuginf("do delete code");
debuginf(file);
ajax_rest_post("delete", file);
load_example_list();
}
function clean_console() {
document.getElementById("console").innerHTML = " ";
};
function clean_error() {
document.getElementById("error").innerHTML = " ";
};
function console_polling() {
var xhr = new XMLHttpRequest();
xhr.open("get", "console", false);
xhr.send();
var get = xhr.responseText;
get = get.replace(/\n/gi, '</p><p>');
get = get.replace(/\r/gi, '</p><p>');
document.getElementById("console").innerHTML += "<p>" + get + "<\p>";
};
setInterval(console_polling, 1000);
function error_polling() {
var xhr = new XMLHttpRequest();
xhr.open("get", "error", false);
xhr.send();
var get = xhr.responseText;
get = get.replace(/\n/gi, '</p><p>');
get = get.replace(/\r/gi, '</p><p>');
document.getElementById("error").innerHTML += "<p>" + get + "<\p>";
};
setInterval(error_polling, 1000);
function delay_refresh() {
window.location.reload();
}
function page_refresh() {
setTimeout('delay_refresh()', 60000);
}
window.onload = function() {
load_config_list();
load_example_list();
}
</script>
</body>
</html>