Commit 31c60dcf authored by Carlos Pereira Atencio's avatar Carlos Pereira Atencio Committed by carlospamg

Update to the "Arduino" app:

  Removed generators for js, python and dard.
  Added Arduino specif js block generators
  Change javascript namespace to the name of this app (from "code", the old app name)
parent 056bb99e
/**
* Blockly Apps: Code
* Blockly Apps: Arduino Code
*
* Copyright 2012 Google Inc.
* https://blockly.googlecode.com/
* Based on the "Code" app developed by: fraser@google.com (Neil Fraser)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview JavaScript for Blockly's Code application.
* @author fraser@google.com (Neil Fraser)
*/
// Supported languages.
......@@ -33,21 +17,21 @@ document.write('<script type="text/javascript" src="generated/' +
/**
* Create a namespace for the application.
*/
var Code = {};
var Arduino = {};
/**
* List of tab names.
* @private
*/
Code.TABS_ = ['blocks', 'arduino', 'javascript', 'python', 'dart', 'xml'];
Arduino.TABS_ = ['blocks', 'arduino', 'xml'];
Code.selected = 'blocks';
Arduino.selected = 'blocks';
/**
* Switch the visible pane when a tab is clicked.
* @param {string} clickedName Name of tab clicked.
*/
Code.tabClick = function(clickedName) {
Arduino.tabClick = function(clickedName) {
// If the XML tab was open, save and render the content.
if (document.getElementById('tab_xml').className == 'tabon') {
var xmlTextarea = document.getElementById('content_xml');
......@@ -70,27 +54,27 @@ Code.tabClick = function(clickedName) {
}
// Deselect all tabs and hide all panes.
for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i];
for (var i = 0; i < Arduino.TABS_.length; i++) {
var name = Arduino.TABS_[i];
document.getElementById('tab_' + name).className = 'taboff';
document.getElementById('content_' + name).style.visibility = 'hidden';
}
// Select the active tab.
Code.selected = clickedName;
Arduino.selected = clickedName;
document.getElementById('tab_' + clickedName).className = 'tabon';
// Show the selected pane.
document.getElementById('content_' + clickedName).style.visibility =
'visible';
Code.renderContent();
Arduino.renderContent();
Blockly.fireUiEvent(window, 'resize');
};
/**
* Populate the currently selected pane with content generated from the blocks.
*/
Code.renderContent = function() {
var content = document.getElementById('content_' + Code.selected);
Arduino.renderContent = function() {
var content = document.getElementById('content_' + Arduino.selected);
// Initialize the pane.
if (content.id == 'content_xml') {
var xmlTextarea = document.getElementById('content_xml');
......@@ -106,45 +90,21 @@ Code.renderContent = function() {
code = prettyPrintOne(code, 'js');
content.innerHTML = code;
}
} else if (content.id == 'content_javascript') {
var code = Blockly.JavaScript.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'js');
content.innerHTML = code;
}
} else if (content.id == 'content_python') {
code = Blockly.Python.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'py');
content.innerHTML = code;
}
} else if (content.id == 'content_dart') {
code = Blockly.Dart.workspaceToCode();
content.textContent = code;
if (typeof prettyPrintOne == 'function') {
code = content.innerHTML;
code = prettyPrintOne(code, 'dart');
content.innerHTML = code;
}
}
};
/**
* Initialize Blockly. Called on page load.
*/
Code.init = function() {
Arduino.init = function() {
BlocklyApps.init();
var rtl = BlocklyApps.isRtl();
var container = document.getElementById('content_area');
var onresize = function(e) {
var bBox = BlocklyApps.getBBox_(container);
for (var i = 0; i < Code.TABS_.length; i++) {
var el = document.getElementById('content_' + Code.TABS_[i]);
for (var i = 0; i < Arduino.TABS_.length; i++) {
var el = document.getElementById('content_' + Arduino.TABS_[i]);
el.style.top = bBox.y + 'px';
el.style.left = bBox.x + 'px';
// Height and width need to be set, read back, then set again to
......@@ -169,10 +129,6 @@ Code.init = function() {
rtl: rtl,
toolbox: toolbox});
// Add to reserved word list: Local variables in execution evironment (runJS)
// and the infinite loop detection function.
Blockly.JavaScript.addReservedWords('code,timeouts,checkTimeout');
BlocklyApps.loadBlocks('');
if ('BlocklyStorage' in window) {
......@@ -180,17 +136,17 @@ Code.init = function() {
BlocklyStorage.backupOnUnload();
}
Code.tabClick(Code.selected);
Arduino.tabClick(Arduino.selected);
Blockly.fireUiEvent(window, 'resize');
BlocklyApps.bindClick('trashButton',
function() {Code.discard(); Code.renderContent();});
BlocklyApps.bindClick('runButton', Code.runJS);
function() {Arduino.discard(); Arduino.renderContent();});
BlocklyApps.bindClick('runButton', Arduino.loadToArduino);
for (var i = 0; i < Code.TABS_.length; i++) {
var name = Code.TABS_[i];
for (var i = 0; i < Arduino.TABS_.length; i++) {
var name = Arduino.TABS_[i];
BlocklyApps.bindClick('tab_' + name,
function(name_) {return function() {Code.tabClick(name_);};}(name));
function(name_) {return function() {Arduino.tabClick(name_);};}(name));
}
// Lazy-load the syntax-highlighting.
......@@ -200,34 +156,21 @@ Code.init = function() {
if (window.location.pathname.match(/readonly.html$/)) {
window.addEventListener('load', BlocklyApps.initReadonly);
} else {
window.addEventListener('load', Code.init);
window.addEventListener('load', Arduino.init);
}
/**
* Execute the user's code.
* Just a quick and dirty eval. Catch infinite loops.
*/
Code.runJS = function() {
Blockly.JavaScript.INFINITE_LOOP_TRAP = ' checkTimeout();\n';
var timeouts = 0;
var checkTimeout = function() {
if (timeouts++ > 1000000) {
throw BlocklyApps.getMsg('Code_timeout');
}
};
var code = Blockly.JavaScript.workspaceToCode();
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
try {
eval(code);
} catch (e) {
alert(BlocklyApps.getMsg('Code_badCode').replace('%1', e));
}
Arduino.loadToArduino = function() {
// TODO
};
/**
* Discard all blocks from the workspace.
*/
Code.discard = function() {
Arduino.discard = function() {
var count = Blockly.mainWorkspace.getAllBlocks().length;
if (count < 2 ||
window.confirm(BlocklyApps.getMsg('Code_discard').replace('%1', count))) {
......
This diff is collapsed.
......@@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta name="google" value="notranslate">
<title>Blockly : Code</title>
<title>Blockly : Arduino Code</title>
<link rel="stylesheet" type="text/css" href="../common.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="../_soy/soyutils.js"></script>
<script type="text/javascript" src="../common.js"></script>
<script type="text/javascript" src="code.js"></script>
<script type="text/javascript" src="arduino.js"></script>
<!--script type="text/javascript" src="/storage.js"></script-->
</head>
<body>
......
......@@ -27,28 +27,26 @@
*/
{template .start}
{call .messages /}
<script type="text/javascript" src="../../blockly_compressed.js"></script>
<script type="text/javascript" src="../../blockly_uncompressed.js"></script>
<script type="text/javascript" src="../../blocks_compressed.js"></script>
<script type="text/javascript" src="../../generators/arduino.js"></script>
<script type="text/javascript" src="../../generators/arduino/control.js"></script>
<script type="text/javascript" src="../../generators/arduino/base.js"></script>
<script type="text/javascript" src="../../generators/arduino/io.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/logic.js"></script>
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/colour.js"></script>
<script type="text/javascript" src="../../generators/arduino/time.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../javascript_compressed.js"></script>
<script type="text/javascript" src="../../python_compressed.js"></script>
<script type="text/javascript" src="../../dart_compressed.js"></script>
<script type="text/javascript" src="../../{$ij.langSrc}"></script>
<table width="100%" height="100%">
<tr>
<td>
<h1>
<span id="title">
<a href="../index.html?lang={$ij.lang}">{msg meaning="Apps.blocklyMessage" desc="IBID"}Blockllllly{/msg}</a>
<a href="../index.html?lang={$ij.lang}">{msg meaning="Apps.blocklyMessage" desc="IBID"}Blockly{/msg}</a>
{sp}:{sp}
{{msg meaning="Code.title" desc="title - Title of this application, indicating that it is for writing arbitrary programs.\n{lb}{lb}Identical|Code{rb}{rb}"}}
Code
......@@ -68,12 +66,6 @@
<td class="tabmin">&nbsp;</td>
<td id="tab_arduino" class="taboff">Arduino</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_javascript" class="taboff">JavaScript</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_python" class="taboff">Python</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_dart" class="taboff">Dart</td>
<td class="tabmin">&nbsp;</td>
<td id="tab_xml" class="taboff">XML</td>
<td class="tabmax">
<button id="trashButton" class="notext" title="{msg meaning="Code.trashTooltip" desc="tooltip - Clicking on this causes the user program to be discarded."}Discard all blocks.{/msg}">
......@@ -98,9 +90,6 @@
</table>
<div id="content_blocks" class="content"></div>
<pre id="content_arduino" class="content"></pre>
<pre id="content_javascript" class="content"></pre>
<pre id="content_python" class="content"></pre>
<pre id="content_dart" class="content"></pre>
<textarea id="content_xml" class="content" wrap="off"></textarea>
{call apps.dialog /}
{call apps.storageDialog /}
......@@ -191,6 +180,7 @@
</value>
</block>
<block type="math_random_float"></block>
<block type="base_map"></block>
</category>
<category name="{msg meaning="Apps.catText" desc="IBID"}Text{/msg}">
<block type="text"></block>
......@@ -273,14 +263,22 @@
</value>
</block>
</category>
<category name="{msg meaning="Apps.catColour" desc="IBID"}Colour{/msg}">
<block type="colour_picker"></block>
<block type="colour_random"></block>
<block type="colour_rgb"></block>
<block type="colour_blend"></block>
</category>
<category name="{msg meaning="Apps.catVariables" desc="IBID"}Variables{/msg}" custom="VARIABLE"></category>
<category name="{msg meaning="Apps.catProcedures" desc="IBID"}Functions{/msg}" custom="PROCEDURE"></category>
<category name="{msg meaning="Apps.catIO" desc="IBID"}Input/Output{/msg}">
<block type="io_digitalwrite"></block>
<block type="io_digitalread"></block>
<block type="io_builtin_led"></block>
<block type="io_analogwrite"></block>
<block type="io_analogread"></block>
<block type="io_highlow"></block>
</category>
<category name="{msg meaning="Apps.catIO" desc="IBID"}Time{/msg}">
<block type="time_delay"></block>
<block type="time_delaymicros"></block>
<block type="time_millis"></block>
<block type="time_micros"></block>
</category>
</xml>
{/template}
......@@ -292,6 +290,17 @@
<script type="text/javascript" src="../../blockly_compressed.js"></script>
<script type="text/javascript" src="../../blocks_compressed.js"></script>
<script type="text/javascript" src="../../generators/arduino.js"></script>
<script type="text/javascript" src="../../generators/arduino/base.js"></script>
<script type="text/javascript" src="../../generators/arduino/io.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script>
<script type="text/javascript" src="../../generators/arduino/logic.js"></script>
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/time.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
<script type="text/javascript" src="../../{$ij.langSrc}"></script>
<div id="blockly"></div>
{/template}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment