Skip to content

Commit 63f06d6

Browse files
committed
Add block to support cursor moving
1 parent 4e8d882 commit 63f06d6

File tree

7 files changed

+65
-21
lines changed

7 files changed

+65
-21
lines changed

blockly.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"types": ["lcd1602_new", "lcd1602_print","lcd1602_clear"],
2+
"types": ["lcd1602_new", "lcd1602_print","lcd1602_clear", "lcd1602_row_column"],
33
"category": "catMenu1",
44
"scripts": [
55
"blockly/blocks.js",

blockly/blocks.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var utmUrl = '?utm_source=cloud-blockly&utm_medium=contextMenu&utm_campaign=tuto
44
Blockly.Blocks['lcd1602_clear'] = {
55
init: function() {
66
this.appendDummyInput()
7-
.appendField(new Blockly.FieldVariable("lcd1602"), "lcd1602")
7+
.appendField(new Blockly.FieldVariable("lcd1602"), "name_")
88
.appendField(Blockly.Msg.WEBDUINO_LCD1602_CLEAR);
99
this.setPreviousStatement(true, null);
1010
this.setNextStatement(true, null);
@@ -14,7 +14,6 @@ Blockly.Blocks['lcd1602_clear'] = {
1414
}
1515
};
1616

17-
1817
Blockly.Blocks['lcd1602_new'] = {
1918
init: function () {
2019
this.appendDummyInput()
@@ -64,6 +63,40 @@ Blockly.Blocks['lcd1602_print'] = {
6463
this.setNextStatement(true);
6564
this.setTooltip('');
6665
this.setColour(65);
67-
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
66+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
6867
}
69-
};
68+
};
69+
70+
Blockly.Blocks['lcd1602_row_column'] = {
71+
init: function() {
72+
this.appendDummyInput()
73+
.appendField(new Blockly.FieldVariable("lcd1602"), "name_")
74+
.appendField(Blockly.Msg.WEBDUINO_LCD1602_START, "文字起始位置")
75+
.appendField(Blockly.Msg.WEBDUINO_LCD1602_COLUMN, "欄")
76+
.appendField(new Blockly.FieldDropdown([["1","1"], ["2","2"]]), "row_")
77+
.appendField(Blockly.Msg.WEBDUINO_LCD1602_ROW, "列")
78+
.appendField(new Blockly.FieldDropdown([
79+
["1","1"],
80+
["2","2"],
81+
["3","3"],
82+
["4","4"],
83+
["5","5"],
84+
["6","6"],
85+
["7","7"],
86+
["8","8"],
87+
["9","9"],
88+
["10","10"],
89+
["11","11"],
90+
["12","12"],
91+
["13","13"],
92+
["14","14"],
93+
["15","15"],
94+
["16","16"]
95+
]), "column_");
96+
this.setPreviousStatement(true, null);
97+
this.setNextStatement(true, null);
98+
this.setColour(65);
99+
this.setTooltip("");
100+
this.setHelpUrl(mainUrl + 'basic/index.html' + utmUrl);
101+
}
102+
};

blockly/javascript.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
Blockly.JavaScript['lcd1602_clear'] = function(block) {
2-
var variable_lcd1602 = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('lcd1602'), Blockly.Variables.NAME_TYPE);
3-
// TODO: Assemble JavaScript into code variable.
4-
var code = variable_lcd1602+'.clear();\n';
5-
return code;
6-
};
7-
8-
91
Blockly.JavaScript['lcd1602_new'] = function (block) {
102
var dropdown_sda_ = block.getFieldValue('sda_');
113
var dropdown_scl_ = block.getFieldValue('scl_');
12-
var code = 'getLCD1602(board,'+ dropdown_sda_ + ',' + dropdown_scl_ + ')';
4+
var code = 'getLCD1602(board,' + dropdown_sda_ + ',' + dropdown_scl_ + ')';
135
return [code, Blockly.JavaScript.ORDER_FUNCTION_CALL];
146
};
157

@@ -18,4 +10,19 @@ Blockly.JavaScript['lcd1602_print'] = function (block) {
1810
var value_value_ = Blockly.JavaScript.valueToCode(block, 'value_', Blockly.JavaScript.ORDER_ATOMIC);
1911
var code = variable_name_ + '.print(' + value_value_ + ');\n';
2012
return code;
21-
};
13+
};
14+
15+
Blockly.JavaScript['lcd1602_clear'] = function (block) {
16+
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
17+
var code = variable_name_ + '.clear();\n';
18+
return code;
19+
};
20+
21+
Blockly.JavaScript['lcd1602_row_column'] = function (block) {
22+
var variable_name_ = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('name_'), Blockly.Variables.NAME_TYPE);
23+
var number_column_ = parseInt(block.getFieldValue('column_'));
24+
var number_row_ = parseInt(block.getFieldValue('row_'));
25+
26+
var code = variable_name_ + '.cursor(' + (--number_column_) + ', ' + (--number_row_) + ');\n';
27+
return code;
28+
};

blockly/msg/blocks/en.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
33
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
44
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "Print:";
55
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "Clear Screen";
6-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD Col:";
7-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD Row:";
6+
Blockly.Msg.WEBDUINO_LCD1602_START = "Text start position:";
7+
Blockly.Msg.WEBDUINO_LCD1602_ROW = "Row";
8+
Blockly.Msg.WEBDUINO_LCD1602_COLUMN = "Column";

blockly/msg/blocks/zh-hans.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
33
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
44
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "显示文字";
55
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "清除屏幕内容";
6-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD 设定列:";
7-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD 设定栏:";
6+
Blockly.Msg.WEBDUINO_LCD1602_START = "文字起始位置";
7+
Blockly.Msg.WEBDUINO_LCD1602_ROW = "栏";
8+
Blockly.Msg.WEBDUINO_LCD1602_COLUMN = "列";

blockly/msg/blocks/zh-hant.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ Blockly.Msg.WEBDUINO_LCD1602 = "LCD (1602),SDA ";
33
Blockly.Msg.WEBDUINO_LCD1602_SCL = " SCL";
44
Blockly.Msg.WEBDUINO_LCD1602_PRINT = "顯示文字";
55
Blockly.Msg.WEBDUINO_LCD1602_CLEAR = "清除螢幕內容";
6-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_X = "LCD 設定列:";
7-
Blockly.Msg.WEBDUINO_LCD1602_LOCATE_Y = "LCD 設定欄:";
6+
Blockly.Msg.WEBDUINO_LCD1602_START = "文字起始位置";
7+
Blockly.Msg.WEBDUINO_LCD1602_ROW = "欄";
8+
Blockly.Msg.WEBDUINO_LCD1602_COLUMN = "列";

blockly/toolbox.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
</block>
1616
</value>
1717
</block>
18+
<block type="lcd1602_row_column"></block>
1819
<block type="lcd1602_clear"></block>
1920
</category>

0 commit comments

Comments
 (0)