-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
157 lines (145 loc) · 6.3 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
<!DOCTYPE html>
<html>
<head>
<title>LedStripSimulator by t-vk</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="Adafruit_NeoPixel.css">
<script id="Adafruit_NeoPixel" src="Adafruit_NeoPixel.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/ace/1.2.3/min/ace.js"></script>
<style type="text/css" media="screen">
body { padding: 10px; }
html,body,#container { height:100% }
.panel { overflow: hidden; margin-bottom: 7px; }
.panel-body { height: 100%; width: 100%; background-color: #000000;}
#container {
display: flex;
flex-direction: column;
}
#editor { width: 100%; height: 100%; margin: 0; }
</style>
<script>
getFile('./Adafruit_NeoPixel.js',function (fileContent) {
window.Adafruit_NeoPixel_Script = fileContent;
});
var codeThread = undefined;
var callbackTemplate = `
if (typeof setup != "undefined")
setup();
if (typeof loop != "undefined")
setInterval(loop, 10);
`;
function StartSimulationThread() {
StopSimulation()
var blob = new Blob([Adafruit_NeoPixel_Script, editor.getValue(), callbackTemplate], { type: "text/javascript" });
codeThread = new Worker(window.URL.createObjectURL(blob));
codeThread.onmessage = function(event){
//console.log(event.data);
eval(event.data);
//console.log("ok");
};
}
function StartSimulation() {
StopSimulation()
eval(editor.getValue())
if (typeof setup != "undefined")
setup()
if (typeof loop != "undefined")
window.loopInterval = setInterval(loop, 10)
}
function StopSimulation() {
if (codeThread !== undefined) {
codeThread.terminate();
codeThread = undefined;
}
if (typeof window.loopInterval != "undefined") {
clearInterval(window.loopInterval);
window.loopInterval = undefined;
}
}
function LoadExample(file) {
getFile('./Examples/' + file + '.js',function (fileContent) {
editor.setValue(fileContent,-1)
});
}
function getFile(file,callback) {
var httpObj = new XMLHttpRequest();
httpObj.open('GET', file);
httpObj.onreadystatechange = function() {
callback(httpObj.responseText);
}
httpObj.send();
}
</script>
</head>
<body>
<div id="container">
<div class="btn-group" role="group" style="margin-bottom: 7px;">
<button type="button" style="float: left; width: 100%" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" value="MultipleAnimations" aria-haspopup="true" aria-expanded="false">
Examples/Templates
<span class="caret"></span>
</button>
<ul class="dropdown-menu" id="ExampleDropDown" style="width: 100%">
<li><a href="#!" data-value="Blink">Single LED Blink</a></li>
<li><a href="#!" data-value="MultipleAnimations">Multiple Animations</a></li>
<li><a href="#!" data-value="BasicTemplate">Basic Template</a></li>
<li><a href="#!" data-value="ColorWipeAnimations">Color Wipe Animations</a></li>
<li><a href="#!" data-value="Test">Turn first LED red</a></li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
Simulated Led Strip (Pin: 10)
</div>
<div class="panel-body" style="padding:0;">
<div class="ledStrip" data-pin="10"></div>
</div>
</div>
<div class="panel panel-primary" style="flex:1;display: flex;flex-direction: column;">
<div class="panel-heading">
Your Code
</div>
<div class="panel-body" style="padding:0;flex: 1;display: flex;flex-direction: column;">
<div id="editor" style="flex:1"></div>
</div>
</div>
<div style="text-align: center; margin-bottom: 0px; margin-top:5px;" class="alert alert-danger" role="alert">
<span style="text-align: center;">When using delay() in your code, you should always use the left button to start a new thread! Otherwise the UI or your whole browser might freeze during the delay() execution.</span>
</div>
<div class="btn-group" style="margin-top:5px;">
<button class="btn btn-primary" style="width:50%;" onclick="StartSimulationThread()">Start Simulation in new thread </button>
<button class="btn btn-danger" style="width:50%;" onclick="StartSimulation()">Start Simulation single threaded</button>
</div>
<button class="btn btn-primary" style="width:100%; margin-top:7px;" onclick="StopSimulation()">Stop Simulation</button>
<div>
<script>
var editor = ace.edit("editor");
var editorSession = editor.getSession();
editorSession.setUseWorker(false);
editorSession.setMode("ace/mode/javascript");
editorSession.setOption("tabSize", 2);
editorSession.setOption("useSoftTabs", false);
editor.$blockScrolling = Infinity;
editor.setTheme("ace/theme/monokai");
editor.setShowPrintMargin(false);
editor.focus();
</script>
<script>
$(function() {
$(".dropdown-menu li a").click(function(){
var buttonGroup = $(this).closest(".btn-group");
var button = buttonGroup.find('.btn');
var dropDown = buttonGroup.find('.dropdown-menu');
button.html($(this).text() + ' <span class="caret"></span>');
button.val($(this).data('value'));
if (dropDown.attr('id') === "ExampleDropDown") {
LoadExample($(this).data('value'));
}
});
LoadExample("Blink");
});
</script>
</body>
</html>