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
eb625d19
Commit
eb625d19
authored
Jul 20, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update stepper block to follow block definition wording consistency.
parent
f06ce8b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
37 deletions
+35
-37
blockly/blocks/arduino/stepper.js
blockly/blocks/arduino/stepper.js
+30
-32
blockly/generators/arduino/stepper.js
blockly/generators/arduino/stepper.js
+5
-5
No files found.
blockly/blocks/arduino/stepper.js
View file @
eb625d19
...
...
@@ -3,10 +3,10 @@
* http://www.apache.org/licenses/LICENSE-2.0
*
* @fileoverview Blocks for Arduino Stepper library.
* The Arduino Servo functions syntax can be found in the
* The Arduino Servo functions syntax can be found in the
* following URL: http://arduino.cc/en/Reference/Stepper
* Additional functions apart from the normal generators have
* been added to be able to generate the 'set' drop down menu
* Additional functions apart from the normal generators have
* been added to be able to generate the 'set' drop down menu
* with all current instances of the Stepper class:
* Blockly.Blocks.Arduino.stepper.stepperInstances
* Blockly.Blocks.Arduino.stepper.FieldStepperInstance
...
...
@@ -19,16 +19,14 @@
goog
.
provide
(
'
Blockly.Blocks.Arduino.stepper
'
);
goog
.
require
(
'
Blockly.FieldDropdown
'
);
goog
.
require
(
'
Blockly.Arduino
'
);
goog
.
require
(
'
Blockly.FieldDropdown
'
);
Blockly
.
Blocks
.
Arduino
.
stepper
.
HUE
=
75
;
/** Common HSV hue for all blocks in this category. */
Blockly
.
Blocks
.
Arduino
.
stepper
.
HUE
=
80
;
/**
* Strings for easy reference
*/
/** Strings for easy reference. */
Blockly
.
Blocks
.
Arduino
.
stepper
.
noInstance
=
'
No_Instances
'
;
Blockly
.
Blocks
.
Arduino
.
stepper
.
noName
=
'
Empty_input_name
'
;
...
...
@@ -40,9 +38,9 @@ Blockly.Blocks.Arduino.stepper.stepperInstances = function() {
var
stepperList
=
[];
var
blocks
=
Blockly
.
mainWorkspace
.
getAllBlocks
();
for
(
var
x
=
0
;
x
<
blocks
.
length
;
x
++
)
{
var
getStepper
Instance
=
blocks
[
x
].
getStepper
Instance
;
if
(
getStepperInstance
)
{
var
stepperInstance
=
getStepperInstance
.
call
(
blocks
[
x
]);
var
getStepper
SetupInstance
=
blocks
[
x
].
getStepperSetup
Instance
;
if
(
getStepper
Setup
Instance
)
{
var
stepperInstance
=
getStepper
Setup
Instance
.
call
(
blocks
[
x
]);
if
(
stepperInstance
)
{
stepperList
.
push
(
stepperInstance
);
}
...
...
@@ -67,7 +65,7 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
}
}
else
{
// There are no config blocks in the work area
options
[
0
]
=
[
Blockly
.
Blocks
.
Arduino
.
stepper
.
noInstance
,
options
[
0
]
=
[
Blockly
.
Blocks
.
Arduino
.
stepper
.
noInstance
,
Blockly
.
Blocks
.
Arduino
.
stepper
.
noInstance
];
}
return
options
;
...
...
@@ -79,8 +77,8 @@ Blockly.Blocks.Arduino.stepper.stepperDropdownList = function() {
* @constructor
*/
Blockly
.
Blocks
.
Arduino
.
stepper
.
FieldStepperInstance
=
function
()
{
Blockly
.
Blocks
.
Arduino
.
stepper
.
FieldStepperInstance
.
superClass_
.
constructor
.
call
(
this
,
Blockly
.
Blocks
.
Arduino
.
stepper
.
stepperDropdownList
);
Blockly
.
Blocks
.
Arduino
.
stepper
.
FieldStepperInstance
.
superClass_
.
constructor
.
call
(
this
,
Blockly
.
Blocks
.
Arduino
.
stepper
.
stepperDropdownList
);
};
goog
.
inherits
(
Blockly
.
Blocks
.
Arduino
.
stepper
.
FieldStepperInstance
,
Blockly
.
FieldDropdown
);
...
...
@@ -96,9 +94,11 @@ Blockly.Blocks['stepper_config'] = {
this
.
setHelpUrl
(
'
http://arduino.cc/en/Reference/StepperConstructor
'
);
this
.
setColour
(
Blockly
.
Blocks
.
Arduino
.
stepper
.
HUE
);
this
.
appendDummyInput
()
.
appendField
(
"
setup stepper
"
)
.
appendField
(
new
Blockly
.
FieldTextInput
(
"
MyStepper
"
),
'
STEPPER_NAME
'
);
.
appendField
(
'
Setup
'
)
.
appendField
(
new
Blockly
.
FieldTextInput
(
'
MyStepper
'
),
'
STEPPER_NAME
'
)
.
appendField
(
'
stepper motor:
'
);
this
.
appendDummyInput
()
.
setAlign
(
Blockly
.
ALIGN_RIGHT
)
.
appendField
(
'
pin1#
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
Blockly
.
Arduino
.
Boards
.
selected
.
digitalPins
),
'
STEPPER_PIN1
'
)
...
...
@@ -108,28 +108,31 @@ Blockly.Blocks['stepper_config'] = {
this
.
appendValueInput
(
'
STEPPER_STEPS
'
)
.
setCheck
(
Blockly
.
StaticTyping
.
blocklyType
.
NUMBER
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
)
.
appendField
(
'
steps in one
revolution
'
);
.
appendField
(
'
how many steps per
revolution
'
);
this
.
appendValueInput
(
'
STEPPER_SPEED
'
)
.
setCheck
(
Blockly
.
StaticTyping
.
blocklyType
.
NUMBER
)
.
setAlign
(
Blockly
.
ALIGN_RIGHT
)
.
appendField
(
'
set speed to
'
);
this
.
setTooltip
(
'
Configures a stepper motor pinout and other settings
'
);
.
appendField
(
'
set speed
(rpm)
to
'
);
this
.
setTooltip
(
'
Configures a stepper motor pinout and other settings
.
'
);
},
/**
* Returns the stepper instance name, defined in the 'STEPPER_NAME' input
* String block attached to this block.
* @return {!
Array.<string>
} List with the instance name.
* @return {!
string
} List with the instance name.
* @this Blockly.Block
*/
getStepperInstance
:
function
()
{
getStepper
Setup
Instance
:
function
()
{
var
InstanceName
=
this
.
getFieldValue
(
'
STEPPER_NAME
'
);
if
(
!
InstanceName
)
{
InstanceName
=
Blockly
.
Blocks
.
Arduino
.
stepper
.
noName
;
}
// Replace all spaces with underscores
return
InstanceName
.
replace
(
/ /g
,
'
_
'
);
;
return
InstanceName
.
replace
(
/ /g
,
'
_
'
);
},
/** Updates the content of the the pin related fields. */
/**
* Updates the content of the the pin related fields.
* @this Blockly.Block
*/
updateFields
:
function
()
{
Blockly
.
Arduino
.
Boards
.
refreshBlockFieldDropdown
(
this
,
'
STEPPER_PIN1
'
,
'
digitalPins
'
);
...
...
@@ -147,13 +150,11 @@ Blockly.Blocks['stepper_step'] = {
this
.
setHelpUrl
(
'
http://arduino.cc/en/Reference/StepperStep
'
);
this
.
setColour
(
Blockly
.
Blocks
.
Arduino
.
stepper
.
HUE
);
this
.
appendDummyInput
()
.
appendField
(
'
stepper
'
)
.
appendField
(
'
move
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
'
);
.
setCheck
(
Blockly
.
StaticTyping
.
blocklyType
.
NUMBER
);
this
.
appendDummyInput
()
.
appendField
(
'
steps
'
);
this
.
setPreviousStatement
(
true
);
...
...
@@ -191,10 +192,7 @@ Blockly.Blocks['stepper_step'] = {
* @this Blockly.Block
*/
onchange
:
function
()
{
if
(
!
this
.
workspace
)
{
// Block has been deleted.
return
;
}
if
(
!
this
.
workspace
)
{
return
;
}
// Block has been deleted.
var
currentDropdown
=
this
.
getFieldValue
(
'
STEPPER_NAME
'
);
var
instances
=
Blockly
.
Blocks
.
Arduino
.
stepper
.
stepperDropdownList
();
...
...
blockly/generators/arduino/stepper.js
View file @
eb625d19
...
...
@@ -3,7 +3,7 @@
* http://www.apache.org/licenses/LICENSE-2.0
*
* @fileoverview Arduino code generator for the Stepper library blocks.
* The Arduino Servo functions syntax can be found in the
* The Arduino Servo functions syntax can be found in the
* following URL: http://arduino.cc/en/Reference/Stepper
*/
'
use strict
'
;
...
...
@@ -14,20 +14,20 @@ goog.require('Blockly.Arduino');
/**
* Code generator for the stepper generator configuration. Nothing is added
* Code generator for the stepper generator configuration. Nothing is added
* to the 'loop()' function. Sets the pins (X and Y), steps per revolution (Z),
* speed(A) and instance name (B).
* Arduino code: #include <Stepper.h>
* Stepper B(Z, X, Y);
* setup() { B.setSpeed(A); }
* @param {!Blockly.Block} block Block to generate the code from.
* @return {string} Empty string as no code goes into 'loop()'
* @return {string} Empty string as no code goes into 'loop()'
.
*/
Blockly
.
Arduino
[
'
stepper_config
'
]
=
function
(
block
)
{
var
pin1
=
block
.
getFieldValue
(
'
STEPPER_PIN1
'
);
var
pin2
=
block
.
getFieldValue
(
'
STEPPER_PIN2
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
STEPPER
;
var
stepperName
=
block
.
getStepperInstance
();
var
stepperName
=
block
.
getStepper
Setup
Instance
();
var
stepperSteps
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
STEPPER_STEPS
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
360
'
;
var
stepperSpeed
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
STEPPER_SPEED
'
,
...
...
@@ -77,7 +77,7 @@ Blockly.Arduino['stepper_config'] = function(block) {
* @return {array} Completed code with order of operation.
*/
Blockly
.
Arduino
[
'
stepper_step
'
]
=
function
(
block
)
{
var
stepperInstanceName
=
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
=
stepperInstanceName
+
'
.step(
'
+
stepperSteps
+
'
);
\n
'
;
...
...
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