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 0f96b9dc
/** /**
* Blockly Apps: Code * Blockly Apps: Arduino Code
* *
* Copyright 2012 Google Inc. * Based on the "Code" app developed by: fraser@google.com (Neil Fraser)
* https://blockly.googlecode.com/
* *
* 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. * @fileoverview JavaScript for Blockly's Code application.
* @author fraser@google.com (Neil Fraser)
*/ */
// Supported languages. // Supported languages.
...@@ -33,21 +17,21 @@ document.write('<script type="text/javascript" src="generated/' + ...@@ -33,21 +17,21 @@ document.write('<script type="text/javascript" src="generated/' +
/** /**
* Create a namespace for the application. * Create a namespace for the application.
*/ */
var Code = {}; var Arduino = {};
/** /**
* List of tab names. * List of tab names.
* @private * @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. * Switch the visible pane when a tab is clicked.
* @param {string} clickedName Name of tab 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 the XML tab was open, save and render the content.
if (document.getElementById('tab_xml').className == 'tabon') { if (document.getElementById('tab_xml').className == 'tabon') {
var xmlTextarea = document.getElementById('content_xml'); var xmlTextarea = document.getElementById('content_xml');
...@@ -70,27 +54,27 @@ Code.tabClick = function(clickedName) { ...@@ -70,27 +54,27 @@ Code.tabClick = function(clickedName) {
} }
// Deselect all tabs and hide all panes. // Deselect all tabs and hide all panes.
for (var i = 0; i < Code.TABS_.length; i++) { for (var i = 0; i < Arduino.TABS_.length; i++) {
var name = Code.TABS_[i]; var name = Arduino.TABS_[i];
document.getElementById('tab_' + name).className = 'taboff'; document.getElementById('tab_' + name).className = 'taboff';
document.getElementById('content_' + name).style.visibility = 'hidden'; document.getElementById('content_' + name).style.visibility = 'hidden';
} }
// Select the active tab. // Select the active tab.
Code.selected = clickedName; Arduino.selected = clickedName;
document.getElementById('tab_' + clickedName).className = 'tabon'; document.getElementById('tab_' + clickedName).className = 'tabon';
// Show the selected pane. // Show the selected pane.
document.getElementById('content_' + clickedName).style.visibility = document.getElementById('content_' + clickedName).style.visibility =
'visible'; 'visible';
Code.renderContent(); Arduino.renderContent();
Blockly.fireUiEvent(window, 'resize'); Blockly.fireUiEvent(window, 'resize');
}; };
/** /**
* Populate the currently selected pane with content generated from the blocks. * Populate the currently selected pane with content generated from the blocks.
*/ */
Code.renderContent = function() { Arduino.renderContent = function() {
var content = document.getElementById('content_' + Code.selected); var content = document.getElementById('content_' + Arduino.selected);
// Initialize the pane. // Initialize the pane.
if (content.id == 'content_xml') { if (content.id == 'content_xml') {
var xmlTextarea = document.getElementById('content_xml'); var xmlTextarea = document.getElementById('content_xml');
...@@ -106,45 +90,21 @@ Code.renderContent = function() { ...@@ -106,45 +90,21 @@ Code.renderContent = function() {
code = prettyPrintOne(code, 'js'); code = prettyPrintOne(code, 'js');
content.innerHTML = code; 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. * Initialize Blockly. Called on page load.
*/ */
Code.init = function() { Arduino.init = function() {
BlocklyApps.init(); BlocklyApps.init();
var rtl = BlocklyApps.isRtl(); var rtl = BlocklyApps.isRtl();
var container = document.getElementById('content_area'); var container = document.getElementById('content_area');
var onresize = function(e) { var onresize = function(e) {
var bBox = BlocklyApps.getBBox_(container); var bBox = BlocklyApps.getBBox_(container);
for (var i = 0; i < Code.TABS_.length; i++) { for (var i = 0; i < Arduino.TABS_.length; i++) {
var el = document.getElementById('content_' + Code.TABS_[i]); var el = document.getElementById('content_' + Arduino.TABS_[i]);
el.style.top = bBox.y + 'px'; el.style.top = bBox.y + 'px';
el.style.left = bBox.x + 'px'; el.style.left = bBox.x + 'px';
// Height and width need to be set, read back, then set again to // Height and width need to be set, read back, then set again to
...@@ -169,10 +129,6 @@ Code.init = function() { ...@@ -169,10 +129,6 @@ Code.init = function() {
rtl: rtl, rtl: rtl,
toolbox: toolbox}); 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(''); BlocklyApps.loadBlocks('');
if ('BlocklyStorage' in window) { if ('BlocklyStorage' in window) {
...@@ -180,17 +136,17 @@ Code.init = function() { ...@@ -180,17 +136,17 @@ Code.init = function() {
BlocklyStorage.backupOnUnload(); BlocklyStorage.backupOnUnload();
} }
Code.tabClick(Code.selected); Arduino.tabClick(Arduino.selected);
Blockly.fireUiEvent(window, 'resize'); Blockly.fireUiEvent(window, 'resize');
BlocklyApps.bindClick('trashButton', BlocklyApps.bindClick('trashButton',
function() {Code.discard(); Code.renderContent();}); function() {Arduino.discard(); Arduino.renderContent();});
BlocklyApps.bindClick('runButton', Code.runJS); BlocklyApps.bindClick('runButton', Arduino.loadToArduino);
for (var i = 0; i < Code.TABS_.length; i++) { for (var i = 0; i < Arduino.TABS_.length; i++) {
var name = Code.TABS_[i]; var name = Arduino.TABS_[i];
BlocklyApps.bindClick('tab_' + name, 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. // Lazy-load the syntax-highlighting.
...@@ -200,34 +156,21 @@ Code.init = function() { ...@@ -200,34 +156,21 @@ Code.init = function() {
if (window.location.pathname.match(/readonly.html$/)) { if (window.location.pathname.match(/readonly.html$/)) {
window.addEventListener('load', BlocklyApps.initReadonly); window.addEventListener('load', BlocklyApps.initReadonly);
} else { } else {
window.addEventListener('load', Code.init); window.addEventListener('load', Arduino.init);
} }
/** /**
* Execute the user's code. * Execute the user's code.
* Just a quick and dirty eval. Catch infinite loops. * Just a quick and dirty eval. Catch infinite loops.
*/ */
Code.runJS = function() { Arduino.loadToArduino = function() {
Blockly.JavaScript.INFINITE_LOOP_TRAP = ' checkTimeout();\n'; // TODO
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));
}
}; };
/** /**
* Discard all blocks from the workspace. * Discard all blocks from the workspace.
*/ */
Code.discard = function() { Arduino.discard = function() {
var count = Blockly.mainWorkspace.getAllBlocks().length; var count = Blockly.mainWorkspace.getAllBlocks().length;
if (count < 2 || if (count < 2 ||
window.confirm(BlocklyApps.getMsg('Code_discard').replace('%1', count))) { window.confirm(BlocklyApps.getMsg('Code_discard').replace('%1', count))) {
......
This diff is collapsed.
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="google" value="notranslate"> <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="../common.css">
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="../_soy/soyutils.js"></script> <script type="text/javascript" src="../_soy/soyutils.js"></script>
<script type="text/javascript" src="../common.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--> <!--script type="text/javascript" src="/storage.js"></script-->
</head> </head>
<body> <body>
......
...@@ -27,28 +27,26 @@ ...@@ -27,28 +27,26 @@
*/ */
{template .start} {template .start}
{call .messages /} {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="../../blocks_compressed.js"></script>
<script type="text/javascript" src="../../generators/arduino.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/logic.js"></script>
<script type="text/javascript" src="../../generators/arduino/loops.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/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/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/lists.js"></script> <script type="text/javascript" src="../../generators/arduino/time.js"></script>
<script type="text/javascript" src="../../generators/arduino/colour.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.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> <script type="text/javascript" src="../../{$ij.langSrc}"></script>
<table width="100%" height="100%"> <table width="100%" height="100%">
<tr> <tr>
<td> <td>
<h1> <h1>
<span id="title"> <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} {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}"}} {{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 Code
...@@ -68,12 +66,6 @@ ...@@ -68,12 +66,6 @@
<td class="tabmin">&nbsp;</td> <td class="tabmin">&nbsp;</td>
<td id="tab_arduino" class="taboff">Arduino</td> <td id="tab_arduino" class="taboff">Arduino</td>
<td class="tabmin">&nbsp;</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 id="tab_xml" class="taboff">XML</td>
<td class="tabmax"> <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}"> <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 @@ ...@@ -98,9 +90,6 @@
</table> </table>
<div id="content_blocks" class="content"></div> <div id="content_blocks" class="content"></div>
<pre id="content_arduino" class="content"></pre> <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> <textarea id="content_xml" class="content" wrap="off"></textarea>
{call apps.dialog /} {call apps.dialog /}
{call apps.storageDialog /} {call apps.storageDialog /}
...@@ -191,6 +180,7 @@ ...@@ -191,6 +180,7 @@
</value> </value>
</block> </block>
<block type="math_random_float"></block> <block type="math_random_float"></block>
<block type="base_map"></block>
</category> </category>
<category name="{msg meaning="Apps.catText" desc="IBID"}Text{/msg}"> <category name="{msg meaning="Apps.catText" desc="IBID"}Text{/msg}">
<block type="text"></block> <block type="text"></block>
...@@ -273,14 +263,22 @@ ...@@ -273,14 +263,22 @@
</value> </value>
</block> </block>
</category> </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.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.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> </xml>
{/template} {/template}
...@@ -292,6 +290,17 @@ ...@@ -292,6 +290,17 @@
<script type="text/javascript" src="../../blockly_compressed.js"></script> <script type="text/javascript" src="../../blockly_compressed.js"></script>
<script type="text/javascript" src="../../blocks_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> <script type="text/javascript" src="../../{$ij.langSrc}"></script>
<div id="blockly"></div> <div id="blockly"></div>
{/template} {/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