Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ardublockly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ardublockly
Commits
c19569e8
Commit
c19569e8
authored
Jul 12, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix stepper block (was using depreciated interpolateMsg).
parent
71573290
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
34 deletions
+50
-34
ardublockly/ardublockly_toolbox.xml
ardublockly/ardublockly_toolbox.xml
+0
-5
blockly/blocks/arduino/stepper.js
blockly/blocks/arduino/stepper.js
+48
-25
blockly/generators/arduino/stepper.js
blockly/generators/arduino/stepper.js
+2
-4
No files found.
ardublockly/ardublockly_toolbox.xml
View file @
c19569e8
...
...
@@ -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"
>
...
...
blockly/blocks/arduino/stepper.js
View file @
c19569e8
...
...
@@ -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
(
'
PIN
1#
'
)
.
appendField
(
'
pin
1#
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
digital
),
'
STEPPER_PIN1
'
)
.
appendField
(
'
PIN
2#
'
)
.
appendField
(
'
pin
2#
'
)
.
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 wa
r
ning to select a valid stepper config
this
.
setWarningText
(
'
Selected stepper does not exist any
more,
'
+
'
please select a new one.
'
);
}
}
...
...
blockly/generators/arduino/stepper.js
View file @
c19569e8
...
...
@@ -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
stepperInstance
Name
=
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
;
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment