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
ab0cbe56
Commit
ab0cbe56
authored
Jul 20, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update IO block with new generator functions & slightly different colour.
parent
eb625d19
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
129 deletions
+68
-129
blockly/blocks/arduino/io.js
blockly/blocks/arduino/io.js
+29
-20
blockly/generators/arduino/io.js
blockly/generators/arduino/io.js
+39
-109
No files found.
blockly/blocks/arduino/io.js
View file @
ab0cbe56
...
...
@@ -12,8 +12,8 @@ goog.provide('Blockly.Blocks.Arduino.io');
goog
.
require
(
'
Blockly.Arduino
'
);
Blockly
.
Blocks
.
Arduino
.
io
.
HUE
=
2
3
0
;
/** Common HSV hue for all blocks in this category. */
Blockly
.
Blocks
.
Arduino
.
io
.
HUE
=
2
5
0
;
Blockly
.
Blocks
[
'
io_digitalwrite
'
]
=
{
/**
...
...
@@ -26,7 +26,7 @@ Blockly.Blocks['io_digitalwrite'] = {
this
.
appendDummyInput
(
''
)
.
appendField
(
'
set digital pin#
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
Blockly
.
Arduino
.
Boards
.
selected
.
digitalPins
),
'
PIN
'
)
Blockly
.
Arduino
.
Boards
.
selected
.
digitalPins
),
'
PIN
'
)
;
this
.
appendValueInput
(
'
STATE
'
,
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
)
.
appendField
(
'
to
'
)
.
setCheck
(
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
);
...
...
@@ -39,7 +39,10 @@ Blockly.Blocks['io_digitalwrite'] = {
getType
:
function
()
{
return
Blockly
.
StaticTyping
.
blocklyType
.
INTEGER
;
},
/** 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
,
'
PIN
'
,
'
digitalPins
'
);
...
...
@@ -61,11 +64,14 @@ Blockly.Blocks['io_digitalread'] = {
this
.
setOutput
(
true
,
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
);
this
.
setTooltip
(
'
Reads the digital value of a pin.
'
);
},
/**
Retrieves t
he type of return value for the block, an integer. */
/**
@return {!string} T
he type of return value for the block, an integer. */
getType
:
function
()
{
return
Blockly
.
StaticTyping
.
blocklyType
.
INTEGER
;
},
/** 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
,
'
PIN
'
,
'
digitalPins
'
);
...
...
@@ -83,7 +89,7 @@ Blockly.Blocks['io_builtin_led'] = {
this
.
appendDummyInput
(
''
)
.
appendField
(
'
set LED
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
Blockly
.
Arduino
.
Boards
.
selected
.
builtinLed
),
'
BUILT_IN_LED
'
)
Blockly
.
Arduino
.
Boards
.
selected
.
builtinLed
),
'
BUILT_IN_LED
'
)
;
this
.
appendValueInput
(
'
STATE
'
,
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
)
.
appendField
(
'
to
'
)
.
setCheck
(
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
);
...
...
@@ -92,13 +98,14 @@ Blockly.Blocks['io_builtin_led'] = {
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Turn on or off the built in LED.
'
);
},
/**
* Retrieves the type of return value for the block, in this case an integer.
*/
/** @return {!string} The type of return value for the block, an integer. */
getType
:
function
()
{
return
Blockly
.
StaticTyping
.
blocklyType
.
INTEGER
;
},
/** 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
,
'
BUILT_IN_LED
'
,
'
builtinLed
'
);
...
...
@@ -125,7 +132,10 @@ Blockly.Blocks['io_analogwrite'] = {
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Write analog value between 0 and 255 to a specific Port.
'
);
},
/** 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
,
'
PIN
'
,
'
analogPins
'
);
}
...
...
@@ -146,13 +156,14 @@ Blockly.Blocks['io_analogread'] = {
this
.
setOutput
(
true
,
Blockly
.
StaticTyping
.
blocklyType
.
NUMBER
);
this
.
setTooltip
(
'
Return value between 0 and 1024.
'
);
},
/**
* Retrieves the type of return value for the block, in this case an integer.
*/
/** @return {!string} The type of return value for the block, an integer. */
getType
:
function
()
{
return
Blockly
.
StaticTyping
.
blocklyType
.
INTEGER
;
},
/** 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
,
'
PIN
'
,
'
analogPins
'
);
}
...
...
@@ -169,13 +180,11 @@ Blockly.Blocks['io_highlow'] = {
this
.
appendDummyInput
(
''
)
.
appendField
(
new
Blockly
.
FieldDropdown
([[
'
HIGH
'
,
'
HIGH
'
],
[
'
LOW
'
,
'
LOW
'
]]),
'
STATE
'
)
'
STATE
'
)
;
this
.
setOutput
(
true
,
Blockly
.
StaticTyping
.
blocklyType
.
BOOLEAN
);
this
.
setTooltip
(
'
Set a pin state logic High or Low.
'
);
},
/**
* Retrieves the type of return value for the block, in this case a boolean.
*/
/** @return {!string} The type of return value for the block, an integer. */
getType
:
function
()
{
return
Blockly
.
StaticTyping
.
blocklyType
.
INTEGER
;
}
...
...
blockly/generators/arduino/io.js
View file @
ab0cbe56
...
...
@@ -21,30 +21,17 @@ goog.require('Blockly.Arduino');
* @return {string} Completed code.
*/
Blockly
.
Arduino
[
'
io_digitalwrite
'
]
=
function
(
block
)
{
var
pinKey
=
block
.
getFieldValue
(
'
PIN
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
;
var
stateInput
=
Blockly
.
Arduino
.
valueToCode
(
var
pin
=
block
.
getFieldValue
(
'
PIN
'
);
var
stateOutput
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
STATE
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
0
'
;
var
setUpKey
=
'
setup_io_
'
+
pinKey
;
var
pinMode
=
'
pinMode(
'
+
pinKey
+
'
, OUTPUT);
'
;
var
code
=
'
digitalWrite(
'
+
pinKey
+
'
,
'
+
stateInput
+
'
);
\n
'
// If the IO has been configured already temporarily change it and restore it
if
(
pinKey
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pinKey
]
!=
pinType
)
{
block
.
setWarningText
(
'
Pin already used as
'
+
Blockly
.
Arduino
.
pins_
[
pinKey
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pinKey
]
=
pinType
;
Blockly
.
Arduino
.
setups_
[
setUpKey
]
=
pinMode
;
block
.
setWarningText
(
null
);
}
Blockly
.
Arduino
.
reservePin
(
block
,
pin
,
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
,
'
Digital Write
'
);
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, OUTPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
var
code
=
'
digitalWrite(
'
+
pin
+
'
,
'
+
stateOutput
+
'
);
\n
'
;
return
code
;
};
...
...
@@ -56,28 +43,14 @@ Blockly.Arduino['io_digitalwrite'] = function(block) {
* @return {array} Completed code with order of operation.
*/
Blockly
.
Arduino
[
'
io_digitalread
'
]
=
function
(
block
)
{
var
pinKey
=
block
.
getFieldValue
(
'
PIN
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
INPUT
;
var
setUpKey
=
'
setup_io_
'
+
pinKey
;
var
pinMode
=
'
pinMode(
'
+
pinKey
+
'
, INPUT);
'
;
var
code
=
'
digitalRead(
'
+
pinKey
+
'
)
'
;
// If the IO has been configured already temporarily change it and restore it
if
(
pinKey
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pinKey
]
!=
pinType
)
{
block
.
setWarningText
(
'
Pin already used as
'
+
Blockly
.
Arduino
.
pins_
[
pinKey
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pinKey
]
=
pinType
;
Blockly
.
Arduino
.
setups_
[
setUpKey
]
=
pinMode
;
block
.
setWarningText
(
null
);
}
var
pin
=
block
.
getFieldValue
(
'
PIN
'
);
Blockly
.
Arduino
.
reservePin
(
block
,
pin
,
Blockly
.
Arduino
.
Boards
.
pinTypes
.
INPUT
,
'
Digital Read
'
);
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, INPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
var
code
=
'
digitalRead(
'
+
pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
...
...
@@ -89,31 +62,17 @@ Blockly.Arduino['io_digitalread'] = function(block) {
* @return {string} Completed code.
*/
Blockly
.
Arduino
[
'
io_builtin_led
'
]
=
function
(
block
)
{
var
pinKey
=
block
.
getFieldValue
(
'
BUILT_IN_LED
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
;
var
stateInput
=
Blockly
.
Arduino
.
valueToCode
(
var
pin
=
block
.
getFieldValue
(
'
BUILT_IN_LED
'
);
var
stateOutput
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
STATE
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
0
'
;
var
setUpKey
=
'
setup_io_
'
+
pinKey
;
var
pinMode
=
'
pinMode(
'
+
pinKey
+
'
,
'
+
pinType
+
'
);
'
;
var
code
=
'
digitalWrite(
'
+
pinKey
+
'
,
'
+
stateInput
+
'
);
\n
'
// If the IO has been configured already temporarily change it and restore it
if
(
pinKey
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pinKey
]
!=
pinType
)
{
block
.
setWarningText
(
'
Pin
'
+
pinKey
+
'
already used as
'
+
Blockly
.
Arduino
.
pins_
[
pinKey
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pinKey
]
=
pinType
;
Blockly
.
Arduino
.
setups_
[
setUpKey
]
=
pinMode
;
block
.
setWarningText
(
null
);
}
Blockly
.
Arduino
.
reservePin
(
block
,
pin
,
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
,
'
Set LED
'
);
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, OUTPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
var
code
=
'
digitalWrite(
'
+
pin
+
'
,
'
+
stateOutput
+
'
);
\n
'
;
return
code
;
};
...
...
@@ -125,30 +84,17 @@ Blockly.Arduino['io_builtin_led'] = function(block) {
* @return {string} Completed code.
*/
Blockly
.
Arduino
[
'
io_analogwrite
'
]
=
function
(
block
)
{
var
pinKey
=
block
.
getFieldValue
(
'
PIN
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
;
var
value_num
=
Blockly
.
Arduino
.
valueToCode
(
var
pin
=
block
.
getFieldValue
(
'
PIN
'
);
var
stateOutput
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
NUM
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
0
'
;
var
setUpKey
=
'
setup_io_
'
+
pinKey
;
var
pinMode
=
'
pinMode(
'
+
pinKey
+
'
, OUTPUT);
'
;
var
code
=
'
analogWrite(
'
+
pinKey
+
'
,
'
+
value_num
+
'
);
\n
'
// If the IO has been configured already temporarily change it and restore it
if
(
pinKey
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pinKey
]
!=
pinType
)
{
block
.
setWarningText
(
'
Pin already used as
'
+
Blockly
.
Arduino
.
pins_
[
pinKey
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pinKey
]
=
pinType
;
Blockly
.
Arduino
.
setups_
[
setUpKey
]
=
pinMode
;
block
.
setWarningText
(
null
);
}
Blockly
.
Arduino
.
reservePin
(
block
,
pin
,
Blockly
.
Arduino
.
Boards
.
pinTypes
.
OUTPUT
,
'
Analogue Write
'
);
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, OUTPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
var
code
=
'
analogWrite(
'
+
pin
+
'
,
'
+
stateOutput
+
'
);
\n
'
;
return
code
;
};
...
...
@@ -160,32 +106,17 @@ Blockly.Arduino['io_analogwrite'] = function(block) {
* @return {array} Completed code with order of operation.
*/
Blockly
.
Arduino
[
'
io_analogread
'
]
=
function
(
block
)
{
var
pinKey
=
block
.
getFieldValue
(
'
PIN
'
);
var
pinType
=
Blockly
.
Arduino
.
Boards
.
pinTypes
.
INPUT
;
var
setUpKey
=
'
setup_io_
'
+
pinKey
;
var
pinMode
=
'
pinMode(
'
+
pinKey
+
'
,
'
+
pinType
+
'
);
'
;
var
code
=
'
analogRead(
'
+
pinKey
+
'
)
'
;
// If the IO has been configured already temporarily change it and restore it
if
(
pinKey
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pinKey
]
!=
pinType
)
{
block
.
setWarningText
(
'
Pin already used as
'
+
Blockly
.
Arduino
.
pins_
[
pinKey
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pinKey
]
=
pinType
;
Blockly
.
Arduino
.
setups_
[
setUpKey
]
=
pinMode
;
block
.
setWarningText
(
null
);
}
var
pin
=
block
.
getFieldValue
(
'
PIN
'
);
Blockly
.
Arduino
.
reservePin
(
block
,
pin
,
Blockly
.
Arduino
.
Boards
.
pinTypes
.
INPUT
,
'
Analogue Read
'
);
var
pinSetupCode
=
'
pinMode(
'
+
pin
+
'
, INPUT);
'
;
Blockly
.
Arduino
.
addSetup
(
'
io_
'
+
pin
,
pinSetupCode
,
false
);
var
code
=
'
analogRead(
'
+
pin
+
'
)
'
;
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
/**
* Value for defining a digital pin state.
* Arduino code: loop { HIGH / LOW }
...
...
@@ -193,7 +124,6 @@ Blockly.Arduino['io_analogread'] = function(block) {
* @return {array} Completed code with order of operation.
*/
Blockly
.
Arduino
[
'
io_highlow
'
]
=
function
(
block
)
{
// Boolean values HIGH and LOW.
var
code
=
(
block
.
getFieldValue
(
'
STATE
'
)
==
'
HIGH
'
)
?
'
HIGH
'
:
'
LOW
'
;
var
code
=
block
.
getFieldValue
(
'
STATE
'
);
return
[
code
,
Blockly
.
Arduino
.
ORDER_ATOMIC
];
};
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