Skip to content

Commit a76373d

Browse files
committed
Add new Interrupts blocks
Adding Interrupts section of toolbox, and message apply English[en] only.
1 parent 01c872c commit a76373d

File tree

6 files changed

+180
-4
lines changed

6 files changed

+180
-4
lines changed

ardublockly/ardublockly_toolbox.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,10 @@ Ardublockly.TOOLBOX_XML =
231231
' <block type="spi_transfer"></block>' +
232232
' <block type="spi_transfer_return"></block>' +
233233
' </category>' +
234+
' <category id="catInts" name="Ints">' +
235+
' <block type="interrupts_attach"></block>' +
236+
' <block type="interrupts_detach"></block>' +
237+
' <block type="interrupts"></block>' +
238+
' <block type="interrupts_no"></block>' +
239+
' </category>' +
234240
'</xml>';

ardublockly/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<link rel="stylesheet" href="ardublockly.css" media="screen,projection">
1414

1515
<!-- Ardublockly - These three files contain the compress version -->
16-
<script src="../blockly/blockly_compressed.js"></script>
16+
<!--script src="../blockly/blockly_compressed.js"></script>
1717
<script src="../blockly/blocks_compressed.js"></script>
18-
<script src="../blockly/arduino_compressed.js"></script>
18+
<script src="../blockly/arduino_compressed.js"></script-->
1919
<!-- To use the uncompressed version comment out the above and comment in the ones below -->
20-
<!--script src="../blockly/blockly_uncompressed.js"></script>
20+
<script src="../blockly/blockly_uncompressed.js"></script>
2121
<script src="../blockly/blocks/logic.js"></script>
2222
<script src="../blockly/blocks/loops.js"></script>
2323
<script src="../blockly/blocks/math.js"></script>
@@ -26,6 +26,7 @@
2626
<script src="../blockly/blocks/colour.js"></script>
2727
<script src="../blockly/blocks/variables.js"></script>
2828
<script src="../blockly/blocks/procedures.js"></script>
29+
<script src="../blockly/blocks/arduino/interrupts.js"></script>
2930
<script src="../blockly/blocks/arduino/io.js"></script>
3031
<script src="../blockly/blocks/arduino/map.js"></script>
3132
<script src="../blockly/blocks/arduino/procedures.js"></script>
@@ -38,6 +39,7 @@
3839
<script src="../blockly/blocks/arduino/variables.js"></script>
3940
<script src="../blockly/generators/arduino.js"></script>
4041
<script src="../blockly/generators/arduino/boards.js"></script>
42+
<script src="../blockly/generators/arduino/interrupts.js"></script>
4143
<script src="../blockly/generators/arduino/io.js"></script>
4244
<script src="../blockly/generators/arduino/lists.js"></script>
4345
<script src="../blockly/generators/arduino/logic.js"></script>
@@ -52,7 +54,7 @@
5254
<script src="../blockly/generators/arduino/text.js"></script>
5355
<script src="../blockly/generators/arduino/time.js"></script>
5456
<script src="../blockly/generators/arduino/tone.js"></script>
55-
<script src="../blockly/generators/arduino/variables.js"></script-->
57+
<script src="../blockly/generators/arduino/variables.js"></script>
5658

5759
<!-- Default language js files, user selection appended to head on load -->
5860
<script src="../blockly/msg/js/en.js"></script>

ardublockly/msg/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ Ardublockly.LOCALISED_TEXT = {
102102
catAudio: "Audio",
103103
catMotors: "Motors",
104104
catComms: "Comms",
105+
catInts: "Interrupts",
105106
};
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//http://www.seeedstudio.com/wiki/GROVE_System
2+
//http://www.seeedstudio.com/depot/index.php?main_page=advanced_search_result&search_in_description=1&keyword=grovefamily
3+
//support starter bundle example http://www.seeedstudio.com/wiki/GROVE_-_Starter_Kit_V1.1b
4+
5+
/**
6+
* @license
7+
* Visual Blocks Editor
8+
*
9+
* Copyright 2012 Fred Lin.
10+
* https://github.com/gasolin/BlocklyDuino
11+
*
12+
* Licensed under the Apache License, Version 2.0 (the "License");
13+
* you may not use this file except in compliance with the License.
14+
* You may obtain a copy of the License at
15+
*
16+
* http://www.apache.org/licenses/LICENSE-2.0
17+
*
18+
* Unless required by applicable law or agreed to in writing, software
19+
* distributed under the License is distributed on an "AS IS" BASIS,
20+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21+
* See the License for the specific language governing permissions and
22+
* limitations under the License.
23+
*/
24+
25+
/**
26+
* @fileoverview Helper functions for generating seeeduino grove blocks.
27+
* @author [email protected] (Fred Lin)
28+
*/
29+
30+
goog.provide('Blockly.Blocks.interrupts');
31+
32+
goog.require('Blockly.Blocks');
33+
goog.require('Blockly.Types');
34+
35+
Blockly.Blocks.interrupts.HUE = 190;
36+
37+
Blockly.Blocks['interrupts_attach'] = {
38+
init: function() {
39+
this.setHelpUrl(Blockly.Msg.INTERRUPTS_ATTACH_HELPURL);
40+
this.setColour(190);
41+
this.appendDummyInput()
42+
.appendField(Blockly.Msg.INTERRUPTS_ATTACH_TITLE);
43+
this.appendDummyInput()
44+
.appendField(Blockly.Msg.PIN)
45+
.appendField(new Blockly.FieldDropdown(Blockly.Arduino.Boards.selected.interrupt), "PIN");
46+
this.appendDummyInput()
47+
.appendField(Blockly.Msg.MODE)
48+
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.ARD_LOW, "LOW"],[Blockly.Msg.ARD_CHANGE, "CHANGE"],[Blockly.Msg.ARD_RISING, "RISING"],[Blockly.Msg.ARD_FALLING, "FALLING"]]), "MODE");
49+
this.appendStatementInput("CONTENT");
50+
this.setInputsInline(true);
51+
this.setTooltip(Blockly.Msg.INTERRUPTS_ATTACH_TOOLTIP);
52+
}
53+
};
54+
55+
Blockly.Blocks['interrupts_detach'] = {
56+
init: function() {
57+
this.setHelpUrl(Blockly.Msg.INTERRUPTS_DETACH_HELPURL);
58+
this.setColour(190);
59+
this.appendDummyInput()
60+
.appendField(Blockly.Msg.INTERRUPTS_DETACH_TITLE);
61+
this.appendDummyInput()
62+
.appendField(new Blockly.FieldDropdown(Blockly.Arduino.Boards.selected.interrupt), "PIN");
63+
this.setPreviousStatement(true, null);
64+
this.setNextStatement(true, null);
65+
this.setTooltip(Blockly.Msg.INTERRUPTS_DETACH_TOOLTIP);
66+
}
67+
};
68+
69+
Blockly.Blocks['interrupts'] = {
70+
init: function() {
71+
this.setHelpUrl(Blockly.Msg.INTERRUPTS_HELPURL);
72+
this.setColour(190);
73+
this.appendDummyInput()
74+
.appendField(Blockly.Msg.INTERRUPTS_TITLE);
75+
this.setPreviousStatement(true, null);
76+
this.setNextStatement(true, null);
77+
this.setTooltip(Blockly.Msg.INTERRUPTS_TOOLTIP);
78+
}
79+
};
80+
81+
Blockly.Blocks['interrupts_no'] = {
82+
init: function() {
83+
this.setHelpUrl(Blockly.Msg.INTERRUPTS_NO_HELPURL);
84+
this.setColour(190);
85+
this.appendDummyInput()
86+
.appendField(Blockly.Msg.INTERRUPTS_NO_TITLE);
87+
this.setPreviousStatement(true, null);
88+
this.setNextStatement(true, null);
89+
this.setTooltip(Blockly.Msg.INTERRUPTS_NO_TOOLTIP);
90+
}
91+
};
92+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @license
3+
* Visual Blocks Language
4+
*
5+
* Copyright 2012 Google Inc.
6+
* https://developers.google.com/blockly/
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
/**
22+
* @fileoverview Generating Arduino for list blocks.
23+
* @author [email protected] (Neil Fraser)
24+
*/
25+
'use strict';
26+
27+
goog.provide('Blockly.Arduino.interrupts');
28+
29+
goog.require('Blockly.Arduino');
30+
31+
Blockly.Arduino['interrupts_attach'] = function(block) {
32+
var pin = block.getFieldValue('PIN');
33+
var mode = block.getFieldValue('MODE');
34+
var content = Blockly.Arduino.statementToCode(block, 'CONTENT');
35+
36+
Blockly.Arduino.setups_['setup_interrupt_' + pin] = 'attachInterrupt(' + pin + ',' + 'interrupt_' + pin + ',' + mode + ');';
37+
38+
Blockly.Arduino.definitions_['define_interrupt_' + pin] = 'void interrupt_' + pin +'(){\n'
39+
+ content
40+
+ '}\n';
41+
return '';
42+
}
43+
44+
Blockly.Arduino['interrupts_detach'] = function(block) {
45+
var pin = block.getFieldValue('PIN');
46+
47+
var code = 'detachInterrupt(' + pin + ');\n';
48+
return code;
49+
}
50+
51+
Blockly.Arduino['interrupts'] = function(block) {
52+
return 'interrupts();\n';
53+
}
54+
55+
Blockly.Arduino['interrupts_no'] = function(block) {
56+
return 'noInterrupts();\n';
57+
}
58+

blockly/msg/js/en.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,20 @@ Blockly.Msg.NEW_INSTANCE = "New instance...";
510510
Blockly.Msg.NEW_INSTANCE_TITLE = "New instance name:";
511511
Blockly.Msg.RENAME_INSTANCE = "Rename instance...";
512512
Blockly.Msg.RENAME_INSTANCE_TITLE = "Rename all '%1' instances to:";
513+
514+
// Interpput
515+
Blockly.Msg.INTERRUPTS_ATTACH_HELPURL = "https://www.arduino.cc/en/Reference/AttachInterrupt";
516+
Blockly.Msg.INTERRUPTS_ATTACH_TITLE = "Attach Interrupt";
517+
Blockly.Msg.INTERRUPTS_ATTACH_TOOLTIP = "The first parameter to attachInterrupt is an interrupt number.";
518+
Blockly.Msg.INTERRUPTS_DETACH_HELPURL = "https://www.arduino.cc/en/Reference/DetachInterrupt";
519+
Blockly.Msg.INTERRUPTS_DETACH_TITLE = "Detach Interrupt";
520+
Blockly.Msg.INTERRUPTS_DETACH_TOOLTIP = "Turns off the given interrupt.";
521+
Blockly.Msg.INTERRUPTS_HELPURL = "https://www.arduino.cc/en/Reference/Interrupts";
522+
Blockly.Msg.INTERRUPTS_NO_HELPURL = "https://www.arduino.cc/en/Reference/NoInterrupts";
523+
Blockly.Msg.INTERRUPTS_NO_TITLE = "Disable Interrupt";
524+
Blockly.Msg.INTERRUPTS_NO_TOOLTIP = "Disables interrupts (you can re-enable them with interrupts()).";
525+
Blockly.Msg.INTERRUPTS_TITLE = "Enable Interrupt";
526+
Blockly.Msg.INTERRUPTS_TOOLTIP = "Re-enables interrupts (after they've been disabled by noInterrupts()). ";
527+
Blockly.Msg.ARD_FALLING = "Falling";
528+
Blockly.Msg.ARD_RISING = "Rising";
529+
Blockly.Msg.ARD_CHANGE = "Change";

0 commit comments

Comments
 (0)