Commit c19569e8 authored by carlosperate's avatar carlosperate

Fix stepper block (was using depreciated interpolateMsg).

parent 71573290
......@@ -174,11 +174,6 @@
<field name="NUM">10</field>
</block>
</value>
<value name="STEPPER_NAME">
<block type="text">
<field name="TEXT">MyStepper</field>
</block>
</value>
</block>
<block type="stepper_step">
<value name="STEPPER_STEPS">
......
......@@ -96,23 +96,23 @@ Blockly.Blocks['stepper_config'] = {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperConstructor');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.appendDummyInput()
.appendField('Configure STEPPER:');
.appendField("setup stepper")
.appendField(new Blockly.FieldTextInput("MyStepper"), 'STEPPER_NAME');
this.appendDummyInput()
.appendField('PIN1#')
.appendField('pin1#')
.appendField(new Blockly.FieldDropdown(profile.default.digital),
'STEPPER_PIN1')
.appendField('PIN2#')
.appendField('pin2#')
.appendField(new Blockly.FieldDropdown(profile.default.digital),
'STEPPER_PIN2');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
.appendField('Steps in one revolution');
.setAlign(Blockly.ALIGN_RIGHT)
.appendField('steps in one revolution');
this.appendValueInput('STEPPER_SPEED')
.setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
.appendField('Set speed to');
this.appendValueInput('STEPPER_NAME')
.setCheck(Blockly.StaticTyping.blocklyType.TEXT)
.appendField('Set name to');
.setAlign(Blockly.ALIGN_RIGHT)
.appendField('set speed to');
this.setTooltip('Configures a stepper motor pinout and other settings');
},
/**
......@@ -122,14 +122,12 @@ Blockly.Blocks['stepper_config'] = {
* @this Blockly.Block
*/
getStepperInstance: function() {
var InstanceName = null;
var instanceNameBlock = this.getInputTargetBlock('STEPPER_NAME');
if (!instanceNameBlock) {
var InstanceName = this.getFieldValue('STEPPER_NAME');
if (!InstanceName) {
InstanceName = Blockly.Blocks.Arduino.stepper.noName;
} else {
InstanceName = instanceNameBlock.getFieldValue('TEXT');
}
return InstanceName;
// Replace all spaces with underscores
return InstanceName.replace(/ /g, '_');;
}
};
......@@ -141,18 +139,43 @@ Blockly.Blocks['stepper_step'] = {
init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperStep');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.interpolateMsg(
// TODO: Combine these messages instead of using concatenation.
'STEPPER' + ' %1 ' +
'move' + ' %2' + 'steps',
['STEPPER_NAME',
new Blockly.Blocks.Arduino.stepper.FieldStepperInstance()],
['STEPPER_STEPS',
Blockly.StaticTyping.blocklyType.NUMBER, Blockly.ALIGN_RIGHT],
Blockly.ALIGN_RIGHT);
this.appendDummyInput()
.appendField('stepper')
.appendField(new Blockly.Blocks.Arduino.stepper.FieldStepperInstance(),
'STEPPER_NAME');
this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField('move');
this.appendDummyInput()
.appendField('steps');
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setTooltip('Turns the stepper motor a specific number of steps.');
/* For now the FieldStepperInstance is required, will need to replicate
functionality for JSON implementation.
this.jsonInit({
"message0": "stepper %1 move %2 steps",
"args0": [
{
"type": "field_dropdown",
"name": "STEPPER_NAME",
"options": Blockly.Blocks.Arduino.stepper.stepperDropdownList()
},
{
"type": "input_value",
"name": "STEPPER_STEPS",
"align": "RIGHT"
}
],
"inputsInline": true,
"previousStatement": null,
"nextStatement": null,
"colour": Blockly.Blocks.Arduino.stepper.HUE,
"tooltip": "Turns the stepper motor a specific number of steps.",
"helpUrl": "http://arduino.cc/en/Reference/StepperStep"
});*/
},
/**
* Called whenever anything on the workspace changes.
......@@ -206,8 +229,8 @@ Blockly.Blocks['stepper_step'] = {
this.setFieldValue(instances[0][0], 'STEPPER_NAME');
this.setWarningText(null);
} else {
// Al this point just set a waning to select a valid stepper config
this.setWarningText('Selected stepper does not exist anymore, ' +
// Al this point just set a warning to select a valid stepper config
this.setWarningText('Selected stepper does not exist any more, ' +
'please select a new one.');
}
}
......
......@@ -77,11 +77,9 @@ Blockly.Arduino['stepper_config'] = function(block) {
* @return {array} Completed code with order of operation.
*/
Blockly.Arduino['stepper_step'] = function(block) {
var stepperInstance = block.getFieldValue('STEPPER_NAME');
var stepperInstanceName = block.getFieldValue('STEPPER_NAME')
var stepperSteps = Blockly.Arduino.valueToCode(block, 'STEPPER_STEPS',
Blockly.Arduino.ORDER_ATOMIC) || '0';
var code = '';
code = stepperInstance + '.steps(' + stepperSteps + ');\n';
var code = stepperInstanceName + '.steps(' + stepperSteps + ');\n';
return code;
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment