Skip to content

Commit

Permalink
Added missing LCD blocks (setCursor and clear)
Browse files Browse the repository at this point in the history
  • Loading branch information
RichoM committed Sep 2, 2023
1 parent bc9d5b4 commit d94bcad
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
8 changes: 8 additions & 0 deletions gui/ide/ast2blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,14 @@ let ASTToBlocks = (function () {
node.setAttribute("type", "print_string");
appendField(node, "lcdName", alias);
appendValue(node, "string", findArg(args, "value", 0) || defaultArg, ctx);
} else if (selector == "setCursor") {
node.setAttribute("type", "lcd_set_cursor");
appendField(node, "lcdName", alias);
appendValue(node, "column", findArg(args, "column", 0) || defaultArg, ctx);
appendValue(node, "row", findArg(args, "row", 1) || defaultArg, ctx);
} else if (selector == "clear") {
node.setAttribute("type", "lcd_clear");
appendField(node, "lcdName", alias);
} else {
// NOTE(Richo): Fallback code...
initPrimitiveCall(node, json, ctx);
Expand Down
39 changes: 39 additions & 0 deletions gui/ide/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,45 @@ let UziBlock = (function () {
color: colors.LCD,
supportsBreakpoints: true,
},
lcd_set_cursor: {
text: "%name . setCursor ( %column, %row ) ;",
type: null,
inputs: {
"name": {
name: "lcdName",
types: null,
builder: (block, input, name) => input.appendField(new Blockly.FieldDropdown(currentLcdsForDropdown), name),
},
"column": {
name: "column",
types: [types.NUMBER],
builder: (block, input, name) => block.appendValueInput(name).setAlign(Blockly.ALIGN_RIGHT),
},
"row": {
name: "row",
types: [types.NUMBER],
builder: (block, input, name) => block.appendValueInput(name).setAlign(Blockly.ALIGN_RIGHT),
}
},
connections: { up: true, down: true, left: false },
color: colors.LCD,
supportsBreakpoints: true,
},
lcd_clear: {
text: "%name . clear () ;",
type: null,
inputs: {
"name": {
name: "lcdName",
types: null,
builder: (block, input, name) => input.appendField(new Blockly.FieldDropdown(currentLcdsForDropdown), name),
}
},
connections: { up: true, down: true, left: false },
color: colors.LCD,
supportsBreakpoints: true,
},


// Sensors - Sonar
get_sonar_distance: {
Expand Down
22 changes: 22 additions & 0 deletions gui/ide/blocks2ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,28 @@ let BlocksToAST = (function () {
let arg = {name: null, value: string};
stream.push(builder.scriptCall(id, selector, [arg]));
},
lcd_set_cursor: function (block, ctx, stream) {
let id = XML.getId(block);
let lcdName = asIdentifier(XML.getChildNode(block, "lcdName").innerText);
let column = generateCodeForValue(block, ctx, "column");
let row = generateCodeForValue(block, ctx, "row");

ctx.addLcdImport(lcdName);

let selector = lcdName + "." + "setCursor";
let args = [{name: "column", value: column},
{name: "row", value: row}];
stream.push(builder.scriptCall(id, selector, args));
},
lcd_clear: function (block, ctx, stream) {
let id = XML.getId(block);
let lcdName = asIdentifier(XML.getChildNode(block, "lcdName").innerText);

ctx.addLcdImport(lcdName);

let selector = lcdName + "." + "clear";
stream.push(builder.scriptCall(id, selector, []));
},
get_sonar_distance: function (block, ctx, stream) {
let id = XML.getId(block);
let sonarName = asIdentifier(XML.getChildNode(block, "sonarName").innerText);
Expand Down
11 changes: 7 additions & 4 deletions gui/ide/toolbox-advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,22 @@
</shadow>
</value>
</block>
<!-- <block type="set_cursor">
<block type="lcd_set_cursor">
<field name="lcdName"></field>
<value name="valueLeft">
<value name="column">
<shadow type="number">
<field name="value">0</field>
</shadow>
</value>
<value name="valueRight">
<value name="row">
<shadow type="number">
<field name="value">0</field>
</shadow>
</value>
</block> -->
</block>
<block type="lcd_clear">
<field name="lcdName"></field>
</block>
</category>
<category name="Sonar" custom="SONAR">
<button text="Configure sonars..." callbackKey="configureSonars"></button>
Expand Down
2 changes: 2 additions & 0 deletions gui/ide/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ var TRANSLATIONS = [
["%name .getSpeed( )", "get %name speed", "obtener la velocidad de %name", "mootori %name kiirus", "läs %name hastighet"],
["%name . printNumber ( %number ) ;", "show number %number in %name", "mostrar número %number en %name", null, null],
["%name . printString ( %string ) ;", "show text %string in %name", "mostrar texto %string en %name", null, null],
["%name . setCursor ( %column, %row ) ;", "move cursor for %name to column %column row %row", "mover cursor de %name a columna %column fila %row", null, null],
["%name . clear () ;", "clear %name", "limpiar pantalla de %name", null, null],
["%name . %unit ()", "read distance from %name in %unit", "leer distancia de %name en %unit", "mõõda kaugus kajaloost %name ühikutes %unit", "läs avståndet från ekolodet %name i %unit"],
["buttons. %state ( %pin )", "is button %state on pin %pin ?", "¿ está %state el botón en el pin %pin ?", "kas lüliti on %state viigus %pin", "är knapp %state på ben %pin"],
["buttons. %action ( %pin ) ;", "wait for button %action on pin %pin", "esperar hasta que %action el botón en el pin %pin", "oota lüliti %action viigus %pin", "vänta på knapp %action på ben %pin"],
Expand Down

0 comments on commit d94bcad

Please sign in to comment.