Skip to content

Commit 6b722a4

Browse files
committed
Merge remote-tracking branch 'home/master'
2 parents 3dad96d + 20d1a2a commit 6b722a4

File tree

9 files changed

+446
-148
lines changed

9 files changed

+446
-148
lines changed

src/main/webapp/cdn/blockly/generators/propc/base.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ Blockly.propc.string_type_block = function() {
134134
return [code, Blockly.propc.ORDER_NONE];
135135
};
136136

137+
Blockly.Blocks.string_length = {
138+
init: function () {
139+
this.setColour(colorPalette.getColor('programming'));
140+
this.appendValueInput('VALUE')
141+
.setCheck('String')
142+
.appendField("length of text");
143+
this.setInputsInline(true);
144+
this.setOutput(true, 'Number');
145+
this.setPreviousStatement(false, null);
146+
this.setNextStatement(false, null);
147+
}
148+
};
149+
150+
Blockly.propc.string_length = function() {
151+
var text = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_NONE);
152+
return ['strlen(' + text + ')', Blockly.propc.ORDER_NONE];
153+
};
154+
137155
Blockly.Blocks.high_low_value = {
138156
init: function () {
139157
this.setColour(colorPalette.getColor('programming'));

src/main/webapp/cdn/blockly/generators/propc/console.js

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Blockly.Blocks.console_print = {
3535
this.appendValueInput('MESSAGE')
3636
.setCheck('String')
3737
.appendField("Terminal print text");
38+
this.appendDummyInput()
39+
.appendField("then a new line")
40+
.appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl");
3841
this.setInputsInline(true);
3942
this.setPreviousStatement(true, null);
4043
this.setNextStatement(true, null);
@@ -53,35 +56,106 @@ Blockly.Blocks.console_print_variables = {
5356
['Hexadecimal','HEX'],
5457
['Binary', 'BIN']
5558
]), "FORMAT");
59+
this.appendDummyInput()
60+
.appendField("then a new line")
61+
.appendField(new Blockly.FieldCheckbox("FALSE"), "ck_nl");
62+
this.setInputsInline(true);
63+
this.setPreviousStatement(true, null);
64+
this.setNextStatement(true, null);
65+
}
66+
};
67+
68+
Blockly.Blocks.console_scan_text = {
69+
init: function () {
70+
this.setColour(colorPalette.getColor('protocols'));
71+
this.appendDummyInput()
72+
.appendField("Terminal receive text store in");
73+
this.appendValueInput('VALUE')
74+
.setCheck('String');
75+
this.setInputsInline(true);
76+
this.setPreviousStatement(true, null);
77+
this.setNextStatement(true, null);
78+
}
79+
};
80+
81+
Blockly.propc.console_scan_text = function () {
82+
var data = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC) || '';
83+
Blockly.propc.vartype_[data] = 'char *';
84+
Blockly.propc.serial_terminal_ = true;
85+
86+
if(data !== '') {
87+
var code = 'getStr(' + data + ', 64);\n';
88+
89+
return code;
90+
} else {
91+
return '';
92+
}
93+
};
94+
95+
Blockly.Blocks.console_scan_number = {
96+
init: function () {
97+
this.setColour(colorPalette.getColor('protocols'));
98+
this.appendDummyInput()
99+
.appendField("Terminal receive number store in");
100+
this.appendValueInput('VALUE')
101+
.setCheck('Number');
56102
this.setInputsInline(true);
57103
this.setPreviousStatement(true, null);
58104
this.setNextStatement(true, null);
59105
}
60106
};
61107

108+
Blockly.propc.console_scan_number = function () {
109+
var data = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC) || '';
110+
111+
Blockly.propc.serial_terminal_ = true;
112+
113+
if(data !== '') {
114+
var code = 'scan("%d\\n", &' + data + ');\n';
115+
116+
return code;
117+
} else {
118+
return '';
119+
}
120+
};
121+
62122
// Terminal print text
63123
Blockly.propc.console_print = function () {
64124
var text = Blockly.propc.valueToCode(this, 'MESSAGE', Blockly.propc.ORDER_ATOMIC);
125+
var checkbox = this.getFieldValue('ck_nl');
126+
65127
Blockly.propc.serial_terminal_ = true;
66-
return 'print(' + text + ');';
128+
129+
var code = 'print(' + text + ');\n';
130+
if (checkbox === 'TRUE') { code += 'print("\\r");\n'; }
131+
return code;
67132
};
68133

69134
Blockly.propc.console_print_variables = function () {
70-
// var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC) || '1000';
71135
var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC);
72136
var format = this.getFieldValue('FORMAT');
137+
var checkbox = this.getFieldValue('ck_nl');
73138
Blockly.propc.serial_terminal_ = true;
74139

75140
var code = 'print(';
76-
if (format === 'BIN') {
77-
code += '"%b"';
78-
}else if (format === 'HEX') {
79-
code += '"%x"';
80-
}else {
81-
code += '"%d"';
82-
}
83-
84-
code += ', ' + value + ');';
141+
if (checkbox !== 'TRUE') {
142+
if (format === 'BIN') {
143+
code += '"%b"';
144+
} else if (format === 'HEX') {
145+
code += '"%x"';
146+
} else {
147+
code += '"%d"';
148+
}
149+
} else {
150+
if (format === 'BIN') {
151+
code += '"%b\\r"';
152+
} else if (format === 'HEX') {
153+
code += '"%x\\r"';
154+
} else {
155+
code += '"%d\\r"';
156+
}
157+
}
158+
code += ', ' + value + ');\n';
85159
return code;
86160
};
87161

@@ -155,12 +229,12 @@ Blockly.Blocks.console_move_to_position = {
155229

156230
Blockly.propc.console_newline = function () {
157231
Blockly.propc.serial_terminal_ = true;
158-
return 'term_cmd(CR);';
232+
return 'term_cmd(CR);\n';
159233
};
160234

161235
Blockly.propc.console_clear = function () {
162236
Blockly.propc.serial_terminal_ = true;
163-
return 'term_cmd(CLS);';
237+
return 'term_cmd(CLS);\n';
164238
};
165239

166240
Blockly.propc.console_move_to_position = function () {
@@ -180,5 +254,5 @@ Blockly.propc.console_move_to_position = function () {
180254
column = 255;
181255
}
182256

183-
return 'term_cmd(CRSRXY, ' + column + ', ' + row + ');';
257+
return 'term_cmd(CRSRXY, ' + column + ', ' + row + ');\n';
184258
};

src/main/webapp/cdn/blockly/generators/propc/debug_LCD.js

Lines changed: 59 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,30 +38,35 @@ Blockly.Blocks.debug_lcd_init = {
3838
.appendField("baud")
3939
.appendField(new Blockly.FieldDropdown([["2400", "2400"], ["9600", "9600"], ["19200", "19200"]]), "BAUD");
4040

41+
this.setInputsInline(true);
4142
this.setPreviousStatement(true, null);
4243
this.setNextStatement(true, null);
4344
}
4445
};
4546

46-
//Blockly.Blocks.debug_lcd_clear = {
47-
// init: function () {
48-
// this.setColour(colorPalette.getColor('protocols'));
49-
// this.appendDummyInput()
50-
// .appendField("LCD clear");
51-
//
52-
// this.setPreviousStatement(true, null);
53-
// this.setNextStatement(true, null);
54-
// }
55-
//};
47+
Blockly.Blocks.debug_lcd_music_note = {
48+
init: function() {
49+
this.setColour(colorPalette.getColor('protocols'));
50+
this.appendDummyInput()
51+
.appendField("LCD play note")
52+
.appendField(new Blockly.FieldDropdown([["C", "223"], ["C#", "224"], ["D", "225"], ["D#", "226"], ["E", "227"], ["F", "228"], ["F#", "229"], ["G", "230"], ["G#", "231"], ["A", "220"], ["A#", "221"], ["B", "222"], ["no note (rest)", "232"]]), "NOTE")
53+
.appendField("octave")
54+
.appendField(new Blockly.FieldDropdown([["3rd", "215"], ["4th", "216"], ["5th", "217"], ["6th", "218"], ["7th", "219"]]), "OCTAVE")
55+
.appendField("length")
56+
.appendField(new Blockly.FieldDropdown([["whole (2 s)", "214"], ["half (1 s)", "213"], ["quarter (500 ms)", "212"], ["eigth (250 ms)", "211"], ["sixteenth (125 ms)", "210"], ["thirty-second (63 ms)", "209"], ["sixty-fourth (31 ms)", "208"]]), "LENGTH");
57+
58+
this.setPreviousStatement(true, null);
59+
this.setNextStatement(true, null);
60+
}
61+
};
5662

5763
Blockly.Blocks.debug_lcd_print = {
58-
init: function () {
64+
init: function () {
5965
this.setColour(colorPalette.getColor('protocols'));
60-
this.appendDummyInput("")
61-
.appendField("LCD print")
62-
.appendField(quotes.newQuote_(true))
63-
.appendField(new Blockly.FieldTextInput(''), 'TEXT')
64-
.appendField(quotes.newQuote_(false));
66+
this.appendValueInput('MESSAGE')
67+
.setCheck('String')
68+
.appendField("LCD print text ");
69+
this.setInputsInline(true);
6570
this.setPreviousStatement(true, null);
6671
this.setNextStatement(true, null);
6772
}
@@ -70,12 +75,16 @@ Blockly.Blocks.debug_lcd_print = {
7075
Blockly.Blocks.debug_lcd_number = {
7176
init: function () {
7277
this.setColour(colorPalette.getColor('protocols'));
78+
this.appendValueInput('VALUE')
79+
.appendField("LCD print number");
7380
this.appendDummyInput()
74-
.appendField("LCD print");
75-
this.appendValueInput('NUMBER', Number)
76-
.appendField("number")
77-
.setCheck('Number');
78-
81+
.appendField("as")
82+
.appendField(new Blockly.FieldDropdown([
83+
['Decimal','DEC'],
84+
['Hexadecimal','HEX'],
85+
['Binary', 'BIN']
86+
]), "FORMAT");
87+
this.setInputsInline(true);
7988
this.setPreviousStatement(true, null);
8089
this.setNextStatement(true, null);
8190
}
@@ -120,16 +129,40 @@ Blockly.propc.debug_lcd_init = function () {
120129
// return 'writeChar(debug_lcd, 12);\npause(5);\n';
121130
//};
122131

132+
Blockly.propc.debug_lcd_music_note = function () {
133+
var dropdown_note = this.getFieldValue('NOTE');
134+
var dropdown_octave = this.getFieldValue('OCTAVE');
135+
var dropdown_length = this.getFieldValue('LENGTH');
136+
137+
var code = 'writeChar(debug_lcd, ' + dropdown_octave + ');\n';
138+
code += 'writeChar(debug_lcd, ' + dropdown_length + ');\n';
139+
code += 'writeChar(debug_lcd, ' + dropdown_note + ');\n';
140+
141+
return code;
142+
};
143+
123144
Blockly.propc.debug_lcd_print = function () {
124-
var text = this.getFieldValue('TEXT');
145+
var msg = Blockly.propc.valueToCode(this, 'MESSAGE', Blockly.propc.ORDER_NONE);
146+
var code = 'dprint(debug_lcd, ' + msg + ');';
125147

126-
return 'dprint(debug_lcd, "' + text + '");\n';
148+
return code;
127149
};
128150

129151
Blockly.propc.debug_lcd_number = function () {
130-
var number = Blockly.propc.valueToCode(this, 'NUMBER', Blockly.propc.ORDER_UNARY_PREFIX) || '0';
131-
132-
return 'dprint(debug_lcd, "' + number + '");\n';
152+
var value = Blockly.propc.valueToCode(this, 'VALUE', Blockly.propc.ORDER_ATOMIC);
153+
var format = this.getFieldValue('FORMAT');
154+
155+
var code = 'dprint(debug_lcd, ';
156+
if (format === 'BIN') {
157+
code += '"%b"';
158+
}else if (format === 'HEX') {
159+
code += '"%x"';
160+
}else {
161+
code += '"%d"';
162+
}
163+
164+
code += ', ' + value + ');';
165+
return code;
133166
};
134167

135168
Blockly.propc.debug_lcd_action = function () {

0 commit comments

Comments
 (0)