| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="UTF-8"> |
| 5 |
<meta name="viewport" content="width=device-width,height=device-width, initial-scale=0.9, maximum-scale=1"> |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
<link rel="stylesheet" type="text/css" href="semantic.min.css"> |
| 18 |
|
| 19 |
<script src="jquery.min.js"></script> |
| 20 |
<script src="semantic.min.js"></script> |
| 21 |
|
| 22 |
<link rel="stylesheet" type="text/css" href="style.css"> |
| 23 |
<script src="blocks/api.js"></script> |
| 24 |
<script src="blocks/acorn_interpreter.js"></script> |
| 25 |
|
| 26 |
<link rel="stylesheet" type="text/css" href="uplot/uPlot.min.css" /> |
| 27 |
<script type="text/javascript" src="uplot/uPlot.iife.js"></script> |
| 28 |
<script type="text/javascript" src="plots.js"></script> |
| 29 |
<script type="text/javascript" src="game.js"></script> |
| 30 |
|
| 31 |
|
| 32 |
<title>Editor</title> |
| 33 |
<style type="text/css" media="screen"> |
| 34 |
body { |
| 35 |
overflow: hidden; |
| 36 |
} |
| 37 |
|
| 38 |
#editor { |
| 39 |
margin: 0; |
| 40 |
position: absolute; |
| 41 |
top: 0; |
| 42 |
bottom: 0; |
| 43 |
left: 0; |
| 44 |
right: 0; |
| 45 |
} |
| 46 |
</style> |
| 47 |
</head> |
| 48 |
<body> |
| 49 |
|
| 50 |
<div class="ui content" style="top:0%;bottom:2%;"> |
| 51 |
<div class="ui icon warning small hidden message missingdevice"> |
| 52 |
<div class="content"> |
| 53 |
<div class="header"> |
| 54 |
Missing Hardware! |
| 55 |
</div> |
| 56 |
<p>Is a SEELab3/ExpEYES17 Device Connected to the USB port?</p> |
| 57 |
</div> |
| 58 |
</div> |
| 59 |
|
| 60 |
<div class="ui hidden divider"></div> |
| 61 |
<div class="ui fluid container"> |
| 62 |
<a onclick="startStep()" class="ui mini primary button "><i class="play icon"></i>Run!</a> |
| 63 |
|
| 64 |
<a onclick="saveXMLtoDisc()" class="ui mini red button right floated" ><i class="save icon"></i>Save</a> |
| 65 |
<a onclick="saveXML()" class="ui mini red button right floated" ><i class="download icon"></i></a> |
| 66 |
<a onclick="loadXML(MyJavascriptInterface.loadLocalXML('eyeseditor'))" class="ui mini teal button right floated" ><i class="upload icon"></i></a> |
| 67 |
</div> |
| 68 |
|
| 69 |
<div class = "ui clearing green segment" style="height:40em;"> |
| 70 |
<div class="ui content" style="bottom:10%;top:10%;"> |
| 71 |
<pre id="editor"> |
| 72 |
var i; |
| 73 |
for (i = 0; i < 100; i++) { |
| 74 |
plot(get_voltage('A1')); |
| 75 |
sleep(0.01); |
| 76 |
} |
| 77 |
|
| 78 |
</pre> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
|
| 82 |
</div> |
| 83 |
|
| 84 |
<div class="ui basic modal results" style="top:0%;bottom:2%;"> |
| 85 |
<i class="close icon" onclick="off()"></i> |
| 86 |
<div class="header"> |
| 87 |
Output |
| 88 |
</div> |
| 89 |
<div class="ui divider"></div> |
| 90 |
<div class="ui content" style="padding:0.2rem ! important;"> |
| 91 |
<div class="ui two column stackable top aligned grid"> |
| 92 |
<div class="ui vertical divider"></div> |
| 93 |
<div class="top aligned row"> |
| 94 |
<div class="column resplotarea" style="background:#fffc;"> |
| 95 |
<div id="#resplot" class="ui description resplot"> |
| 96 |
</div> |
| 97 |
</div> |
| 98 |
|
| 99 |
<div class="column" > |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
<div class="ui icon header" style="color:white;"> |
| 108 |
Results |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
<div class="ui scrolling content description printarea" style="color:white;scrollable:true;"> |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
|
| 115 |
|
| 116 |
</div> |
| 117 |
</div> |
| 118 |
|
| 119 |
</div> |
| 120 |
|
| 121 |
</div> |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
<script src="ace/ace.js" type="text/javascript" charset="utf-8"></script> |
| 126 |
<script> |
| 127 |
var editor = ace.edit("editor"); |
| 128 |
editor.setTheme("ace/theme/github"); |
| 129 |
editor.session.setMode("ace/mode/javascript"); |
| 130 |
</script> |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
<script type="text/javascript"> |
| 136 |
|
| 137 |
var results = $('.description.printarea'); |
| 138 |
var command = $('.description.cmdarea'); |
| 139 |
var resultModal = $('.modal.results'); |
| 140 |
|
| 141 |
//var registers = $('.list.registers'); |
| 142 |
//var regvals = []; |
| 143 |
var resplotarea = $('.resplotarea'); |
| 144 |
var resultplots = $('.description.resplot'); |
| 145 |
/* |
| 146 |
function showReg(reg, val){ |
| 147 |
if(regvals.indexOf(reg)!=-1){ // Register is already shown in the results segment. update it. |
| 148 |
registers.find('.'+reg).text(reg+"="+val); |
| 149 |
}else{ |
| 150 |
registers.append(`<div class="item ${reg}">${reg}=${val}</div>`) |
| 151 |
regvals.push(reg); |
| 152 |
} |
| 153 |
} |
| 154 |
*/ |
| 155 |
function on() { |
| 156 |
results.html(""); |
| 157 |
resultModal.modal('show'); |
| 158 |
|
| 159 |
} |
| 160 |
|
| 161 |
function off() { |
| 162 |
resultModal.modal('hide'); |
| 163 |
resetInterpreter(); |
| 164 |
MyJavascriptInterface.closeFiles(); |
| 165 |
stopGame(); |
| 166 |
} |
| 167 |
|
| 168 |
function resetInterpreter() { |
| 169 |
myInterpreter = null; |
| 170 |
if (runner) { |
| 171 |
clearTimeout(runner); |
| 172 |
runner = null; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
var myInterpreter; |
| 177 |
|
| 178 |
var runner; |
| 179 |
var latestCode = ''; |
| 180 |
|
| 181 |
var devState = false; |
| 182 |
if(typeof MyJavascriptInterface != 'undefined') |
| 183 |
devState = MyJavascriptInterface.get_device_status(); |
| 184 |
|
| 185 |
if(!devState){$('.message.missingdevice').closest('.message').transition('fade in','1000mS').transition('glow');} |
| 186 |
function deviceConnected(){ |
| 187 |
$('.message.missingdevice').closest('.message').transition('fade out','300mS'); |
| 188 |
} |
| 189 |
function deviceDisconnected(){ |
| 190 |
$('.message.missingdevice').closest('.message').transition('fade in','1000mS').transition('glow'); |
| 191 |
} |
| 192 |
|
| 193 |
function startStep() { |
| 194 |
|
| 195 |
|
| 196 |
latestCode = editor.getValue(); |
| 197 |
|
| 198 |
on(); |
| 199 |
clearPlot(); |
| 200 |
resplotarea.show(); |
| 201 |
|
| 202 |
if(latestCode.indexOf('plot_xy(')>=0) |
| 203 |
addPlot('xy'); // indicate XY |
| 204 |
else if(latestCode.indexOf('plot_radar(')>=0) |
| 205 |
addPolarPlot(); |
| 206 |
else if(latestCode.indexOf('plot(')>=0) |
| 207 |
addPlot(''); |
| 208 |
else if(latestCode.indexOf('plot_xyarray(')>=0) |
| 209 |
addPlot(''); |
| 210 |
else if(latestCode.indexOf('plot_xyyarray(')>=0) |
| 211 |
addPlot('xyy'); |
| 212 |
else |
| 213 |
resplotarea.hide(); |
| 214 |
|
| 215 |
runCode(); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
function runCode() { |
| 220 |
if (!myInterpreter) { |
| 221 |
// First statement of this code. |
| 222 |
// Clear the program output. |
| 223 |
|
| 224 |
// And then show generated code in an alert. |
| 225 |
// In a timeout to allow the outputArea.value to reset first. |
| 226 |
setTimeout(function() { |
| 227 |
// Begin execution |
| 228 |
highlightPause = false; |
| 229 |
myInterpreter = new Interpreter(latestCode, initApi); |
| 230 |
if(latestCode.search("alert") != -1) // -1 means not found |
| 231 |
on(); |
| 232 |
|
| 233 |
runner = function() { |
| 234 |
if (myInterpreter) { |
| 235 |
var hasMore = myInterpreter.run(); |
| 236 |
if (hasMore) { |
| 237 |
// Execution is currently blocked by some async call. |
| 238 |
// Try again later. |
| 239 |
setTimeout(runner, 10); |
| 240 |
} else { |
| 241 |
// Program is complete. |
| 242 |
resetInterpreter(); |
| 243 |
resetStepUi(); |
| 244 |
} |
| 245 |
} |
| 246 |
}; |
| 247 |
runner(); |
| 248 |
}, 1); |
| 249 |
return; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
function saveXML(){ |
| 258 |
MyJavascriptInterface.saveXML("eyeseditor",editor.getValue()); |
| 259 |
} |
| 260 |
function saveXMLtoDisc(){ |
| 261 |
MyJavascriptInterface.saveXMLtoDisc("eyeseditor",editor.getValue()); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
function loadXML(xml) { |
| 266 |
editor.setValue(xml); |
| 267 |
} |
| 268 |
|
| 269 |
// Loads js file contents passed by OnlineExplorer.java . |
| 270 |
if(typeof MyJavascriptInterface != 'undefined') |
| 271 |
loadXML(MyJavascriptInterface.loadXMLFile("js")); |
| 272 |
|
| 273 |
|
| 274 |
</script> |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
</body> |
| 283 |
</html> |
| 284 |
|