Commit c19569e8 authored by carlosperate's avatar carlosperate

Fix stepper block (was using depreciated interpolateMsg).

parent 71573290
...@@ -174,11 +174,6 @@ ...@@ -174,11 +174,6 @@
<field name="NUM">10</field> <field name="NUM">10</field>
</block> </block>
</value> </value>
<value name="STEPPER_NAME">
<block type="text">
<field name="TEXT">MyStepper</field>
</block>
</value>
</block> </block>
<block type="stepper_step"> <block type="stepper_step">
<value name="STEPPER_STEPS"> <value name="STEPPER_STEPS">
......
...@@ -96,23 +96,23 @@ Blockly.Blocks['stepper_config'] = { ...@@ -96,23 +96,23 @@ Blockly.Blocks['stepper_config'] = {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperConstructor'); this.setHelpUrl('http://arduino.cc/en/Reference/StepperConstructor');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE); this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.appendDummyInput() this.appendDummyInput()
.appendField('Configure STEPPER:'); .appendField("setup stepper")
.appendField(new Blockly.FieldTextInput("MyStepper"), 'STEPPER_NAME');
this.appendDummyInput() this.appendDummyInput()
.appendField('PIN1#') .appendField('pin1#')
.appendField(new Blockly.FieldDropdown(profile.default.digital), .appendField(new Blockly.FieldDropdown(profile.default.digital),
'STEPPER_PIN1') 'STEPPER_PIN1')
.appendField('PIN2#') .appendField('pin2#')
.appendField(new Blockly.FieldDropdown(profile.default.digital), .appendField(new Blockly.FieldDropdown(profile.default.digital),
'STEPPER_PIN2'); 'STEPPER_PIN2');
this.appendValueInput('STEPPER_STEPS') this.appendValueInput('STEPPER_STEPS')
.setCheck(Blockly.StaticTyping.blocklyType.NUMBER) .setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
.appendField('Steps in one revolution'); .setAlign(Blockly.ALIGN_RIGHT)
.appendField('steps in one revolution');
this.appendValueInput('STEPPER_SPEED') this.appendValueInput('STEPPER_SPEED')
.setCheck(Blockly.StaticTyping.blocklyType.NUMBER) .setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
.appendField('Set speed to'); .setAlign(Blockly.ALIGN_RIGHT)
this.appendValueInput('STEPPER_NAME') .appendField('set speed to');
.setCheck(Blockly.StaticTyping.blocklyType.TEXT)
.appendField('Set name to');
this.setTooltip('Configures a stepper motor pinout and other settings'); this.setTooltip('Configures a stepper motor pinout and other settings');
}, },
/** /**
...@@ -122,14 +122,12 @@ Blockly.Blocks['stepper_config'] = { ...@@ -122,14 +122,12 @@ Blockly.Blocks['stepper_config'] = {
* @this Blockly.Block * @this Blockly.Block
*/ */
getStepperInstance: function() { getStepperInstance: function() {
var InstanceName = null; var InstanceName = this.getFieldValue('STEPPER_NAME');
var instanceNameBlock = this.getInputTargetBlock('STEPPER_NAME'); if (!InstanceName) {
if (!instanceNameBlock) {
InstanceName = Blockly.Blocks.Arduino.stepper.noName; 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'] = { ...@@ -141,18 +139,43 @@ Blockly.Blocks['stepper_step'] = {
init: function() { init: function() {
this.setHelpUrl('http://arduino.cc/en/Reference/StepperStep'); this.setHelpUrl('http://arduino.cc/en/Reference/StepperStep');
this.setColour(Blockly.Blocks.Arduino.stepper.HUE); this.setColour(Blockly.Blocks.Arduino.stepper.HUE);
this.interpolateMsg( this.appendDummyInput()
// TODO: Combine these messages instead of using concatenation. .appendField('stepper')
'STEPPER' + ' %1 ' + .appendField(new Blockly.Blocks.Arduino.stepper.FieldStepperInstance(),
'move' + ' %2' + 'steps', 'STEPPER_NAME');
['STEPPER_NAME', this.appendValueInput('STEPPER_STEPS')
new Blockly.Blocks.Arduino.stepper.FieldStepperInstance()], .setCheck(Blockly.StaticTyping.blocklyType.NUMBER)
['STEPPER_STEPS', .setAlign(Blockly.ALIGN_RIGHT)
Blockly.StaticTyping.blocklyType.NUMBER, Blockly.ALIGN_RIGHT], .appendField('move');
Blockly.ALIGN_RIGHT); this.appendDummyInput()
.appendField('steps');
this.setPreviousStatement(true); this.setPreviousStatement(true);
this.setNextStatement(true); this.setNextStatement(true);
this.setTooltip('Turns the stepper motor a specific number of steps.'); 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. * Called whenever anything on the workspace changes.
...@@ -206,8 +229,8 @@ Blockly.Blocks['stepper_step'] = { ...@@ -206,8 +229,8 @@ Blockly.Blocks['stepper_step'] = {
this.setFieldValue(instances[0][0], 'STEPPER_NAME'); this.setFieldValue(instances[0][0], 'STEPPER_NAME');
this.setWarningText(null); this.setWarningText(null);
} else { } else {
// Al this point just set a waning to select a valid stepper config // Al this point just set a warning to select a valid stepper config
this.setWarningText('Selected stepper does not exist anymore, ' + this.setWarningText('Selected stepper does not exist any more, ' +
'please select a new one.'); 'please select a new one.');
} }
} }
......
...@@ -77,11 +77,9 @@ Blockly.Arduino['stepper_config'] = function(block) { ...@@ -77,11 +77,9 @@ Blockly.Arduino['stepper_config'] = function(block) {
* @return {array} Completed code with order of operation. * @return {array} Completed code with order of operation.
*/ */
Blockly.Arduino['stepper_step'] = function(block) { 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', var stepperSteps = Blockly.Arduino.valueToCode(block, 'STEPPER_STEPS',
Blockly.Arduino.ORDER_ATOMIC) || '0'; Blockly.Arduino.ORDER_ATOMIC) || '0';
var code = ''; var code = stepperInstanceName + '.steps(' + stepperSteps + ');\n';
code = stepperInstance + '.steps(' + stepperSteps + ');\n';
return code; 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