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
25c52c79
Commit
25c52c79
authored
Jul 20, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add better control over Arduino code new lines.
parent
681fdf1b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
24 deletions
+31
-24
blockly/generators/arduino.js
blockly/generators/arduino.js
+23
-16
blockly/generators/arduino/procedures.js
blockly/generators/arduino/procedures.js
+7
-7
blockly/generators/arduino/serial.js
blockly/generators/arduino/serial.js
+1
-1
No files found.
blockly/generators/arduino.js
View file @
25c52c79
...
...
@@ -128,8 +128,7 @@ Blockly.Arduino.init = function(workspace) {
Blockly
.
Arduino
.
getArduinoType_
(
variableTypes
[
varName
])
+
'
'
+
varName
+
'
;
'
);
}
Blockly
.
Arduino
.
definitions_
[
'
variables
'
]
=
variableDeclarations
.
join
(
'
\n
'
)
+
'
\n
'
;
Blockly
.
Arduino
.
definitions_
[
'
variables
'
]
=
variableDeclarations
.
join
(
'
\n
'
);
};
/**
...
...
@@ -138,28 +137,32 @@ Blockly.Arduino.init = function(workspace) {
* @return {string} Completed code.
*/
Blockly
.
Arduino
.
finish
=
function
(
code
)
{
// Indent every line.
//TODO: revise regexs
code
=
'
'
+
code
.
replace
(
/
\n
/g
,
'
\n
'
);
code
=
code
.
replace
(
/
\n\s
+$/
,
'
\n
'
);
code
=
'
void loop() {
\n
'
+
code
+
'
\n
}
'
;
// Convert the includes, definitions, functions, and setup dicts into lists
var
includes
=
[],
definitions
=
[],
functions
=
[],
setups
=
[];
var
userSetupCode
=
''
;
// Convert the includes, definitions, and functions dictionaries into lists
var
includes
=
[],
definitions
=
[],
functions
=
[];
for
(
var
name
in
Blockly
.
Arduino
.
includes_
)
{
includes
.
push
(
Blockly
.
Arduino
.
includes_
[
name
]);
}
if
(
includes
.
length
)
{
includes
.
push
(
'
\n
'
);
}
for
(
var
name
in
Blockly
.
Arduino
.
definitions_
)
{
definitions
.
push
(
Blockly
.
Arduino
.
definitions_
[
name
]);
}
if
(
definitions
.
length
)
{
definitions
.
push
(
'
\n
'
);
}
for
(
var
name
in
Blockly
.
Arduino
.
codeFunctions_
)
{
functions
.
push
(
Blockly
.
Arduino
.
codeFunctions_
[
name
]);
}
for
(
var
name
in
Blockly
.
Arduino
.
userFunctions_
)
{
functions
.
push
(
Blockly
.
Arduino
.
userFunctions_
[
name
]);
}
// userSetupCode is added at the end of the setup function
if
(
functions
.
length
)
{
functions
.
push
(
'
\n
'
);
}
// userSetupCode added at the end of the setup function without leading spaces
var
setups
=
[
''
],
userSetupCode
=
''
;
if
(
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
]
!==
undefined
)
{
userSetupCode
=
'
\n
'
+
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
delete
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
...
...
@@ -167,11 +170,15 @@ Blockly.Arduino.finish = function(code) {
for
(
var
name
in
Blockly
.
Arduino
.
setups_
)
{
setups
.
push
(
Blockly
.
Arduino
.
setups_
[
name
]);
}
if
(
userSetupCode
)
{
setups
.
push
(
userSetupCode
);
}
var
allDefs
=
includes
.
join
(
'
\n
'
)
+
'
\n\n
'
+
definitions
.
join
(
'
\n
'
)
+
'
\n\n
'
+
functions
.
join
(
'
\n\n
'
)
+
'
\n\n
void setup() {
\n
'
+
setups
.
join
(
'
\n
'
)
+
'
\n
'
+
userSetupCode
+
'
}
'
;
return
allDefs
.
replace
(
/
\n\n
+/g
,
'
\n\n
'
).
replace
(
/
\n
*$/
,
'
\n\n\n
'
)
+
code
;
var
allDefs
=
includes
.
join
(
'
\n
'
)
+
definitions
.
join
(
'
\n
'
)
+
functions
.
join
(
'
\n\n
'
);
var
setup
=
'
void setup() {
'
+
setups
.
join
(
'
\n
'
)
+
'
\n
}
\n\n
'
;
var
loop
=
'
void loop() {
\n
'
+
code
.
replace
(
/
\n
/g
,
'
\n
'
)
+
'
\n
}
'
;
return
allDefs
+
setup
+
loop
;
};
/**
...
...
blockly/generators/arduino/procedures.js
View file @
25c52c79
...
...
@@ -57,7 +57,7 @@ Blockly.Arduino['procedures_defreturn'] = function(block) {
// Construct code
var
code
=
returnType
+
'
'
+
funcName
+
'
(
'
+
args
.
join
(
'
,
'
)
+
'
) {
\n
'
+
branch
+
returnValue
+
'
}
\n
'
;
branch
+
returnValue
+
'
}
'
;
code
=
Blockly
.
Arduino
.
scrub_
(
block
,
code
);
Blockly
.
Arduino
.
userFunctions_
[
funcName
]
=
code
;
return
null
;
...
...
@@ -147,12 +147,12 @@ Blockly.Arduino['arduino_functions'] = function(block) {
}
var
setupBranch
=
Blockly
.
Arduino
.
statementToCode
(
block
,
'
SETUP_FUNC
'
);
//
Remove first spacers as they will be added again in "addSetup()"
//setupBranch = setupBranch.substring(2);
var
setupCode
=
Blockly
.
Arduino
.
scrub_
(
block
,
setupBranch
);
Blockly
.
Arduino
.
addSetup
(
'
userSetupCode
'
,
setupCode
,
true
);
//
var setupCode = Blockly.Arduino.scrub_(block, setupBranch); No comment block
if
(
setupBranch
)
{
Blockly
.
Arduino
.
addSetup
(
'
userSetupCode
'
,
setupBranch
,
true
);
}
var
loopBranch
=
statementToCodeNoTab
(
block
,
'
LOOP_FUNC
'
);
var
loopcode
=
Blockly
.
Arduino
.
scrub_
(
block
,
loopBranch
);
return
loop
code
;
//var loopcode = Blockly.Arduino.scrub_(block, loopBranch); No comment block
return
loop
Branch
;
};
blockly/generators/arduino/serial.js
View file @
25c52c79
...
...
@@ -46,7 +46,7 @@ Blockly.Arduino['serial_print'] = function(block) {
Blockly
.
Arduino
[
'
serial_setup
'
]
=
function
(
block
)
{
var
serialId
=
block
.
getFieldValue
(
'
SERIAL_ID
'
);
var
serialSpeed
=
block
.
getFieldValue
(
'
SPEED
'
);
var
serialSetupCode
=
serialId
+
'
.begin(
'
+
serialSpeed
+
'
);
\n
'
;
var
serialSetupCode
=
serialId
+
'
.begin(
'
+
serialSpeed
+
'
);
'
;
Blockly
.
Arduino
.
addSetup
(
'
serial_
'
+
serialId
,
serialSetupCode
,
true
);
var
code
=
''
;
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