Hi everyone,
This is my first attempt at blockly. I would like to generate a gcode with Blockly and send that via serail port to Arduino.
So far, I understand how to create custom blocks and created a very simple block with steps and speed variables.
But I don't know how to generate a corresponding Gcode (for example X100 S10, X100 means to move 100 steps and S10 means speed is 10rpm) within the code generator. I know that I have to write just a single line below this line, but I have no idea how to do that.
// TODO: Assemble JavaScript into code variable.
I have looked in the below link for reference, but in that link he was sending an http request, not generating any Gcode type stuff.
Please help me to complete this project. Many thanks in advance.
My block's langauge code is:
Blockly.Blocks['move_stepper'] = {
init: function() {
this.appendValueInput("steps")
.setCheck("Number")
.appendField(new Blockly.FieldTextInput("steps"), "steps");
this.appendValueInput("speed")
.setCheck("Number")
.appendField(new Blockly.FieldTextInput("speed"), "speed");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(100);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
};
and the corresponding Javascript is:
Blockly.JavaScript['move_stepper'] = function(block) {
var text_steps = block.getFieldValue('steps');
var value_steps = Blockly.JavaScript.valueToCode(block, 'steps', Blockly.JavaScript.ORDER_ATOMIC);
var text_speed = block.getFieldValue('speed');
var value_speed = Blockly.JavaScript.valueToCode(block, 'speed', Blockly.JavaScript.ORDER_ATOMIC);
// TODO: Assemble JavaScript into code variable.
var code = '...;\n';
return code;
};