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
Hide 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) {
...
@@ -128,8 +128,7 @@ Blockly.Arduino.init = function(workspace) {
Blockly
.
Arduino
.
getArduinoType_
(
variableTypes
[
varName
])
+
'
'
+
Blockly
.
Arduino
.
getArduinoType_
(
variableTypes
[
varName
])
+
'
'
+
varName
+
'
;
'
);
varName
+
'
;
'
);
}
}
Blockly
.
Arduino
.
definitions_
[
'
variables
'
]
=
Blockly
.
Arduino
.
definitions_
[
'
variables
'
]
=
variableDeclarations
.
join
(
'
\n
'
);
variableDeclarations
.
join
(
'
\n
'
)
+
'
\n
'
;
};
};
/**
/**
...
@@ -138,28 +137,32 @@ Blockly.Arduino.init = function(workspace) {
...
@@ -138,28 +137,32 @@ Blockly.Arduino.init = function(workspace) {
* @return {string} Completed code.
* @return {string} Completed code.
*/
*/
Blockly
.
Arduino
.
finish
=
function
(
code
)
{
Blockly
.
Arduino
.
finish
=
function
(
code
)
{
// Indent every line.
// Convert the includes, definitions, and functions dictionaries into lists
//TODO: revise regexs
var
includes
=
[],
definitions
=
[],
functions
=
[];
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
=
''
;
for
(
var
name
in
Blockly
.
Arduino
.
includes_
)
{
for
(
var
name
in
Blockly
.
Arduino
.
includes_
)
{
includes
.
push
(
Blockly
.
Arduino
.
includes_
[
name
]);
includes
.
push
(
Blockly
.
Arduino
.
includes_
[
name
]);
}
}
if
(
includes
.
length
)
{
includes
.
push
(
'
\n
'
);
}
for
(
var
name
in
Blockly
.
Arduino
.
definitions_
)
{
for
(
var
name
in
Blockly
.
Arduino
.
definitions_
)
{
definitions
.
push
(
Blockly
.
Arduino
.
definitions_
[
name
]);
definitions
.
push
(
Blockly
.
Arduino
.
definitions_
[
name
]);
}
}
if
(
definitions
.
length
)
{
definitions
.
push
(
'
\n
'
);
}
for
(
var
name
in
Blockly
.
Arduino
.
codeFunctions_
)
{
for
(
var
name
in
Blockly
.
Arduino
.
codeFunctions_
)
{
functions
.
push
(
Blockly
.
Arduino
.
codeFunctions_
[
name
]);
functions
.
push
(
Blockly
.
Arduino
.
codeFunctions_
[
name
]);
}
}
for
(
var
name
in
Blockly
.
Arduino
.
userFunctions_
)
{
for
(
var
name
in
Blockly
.
Arduino
.
userFunctions_
)
{
functions
.
push
(
Blockly
.
Arduino
.
userFunctions_
[
name
]);
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
)
{
if
(
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
]
!==
undefined
)
{
userSetupCode
=
'
\n
'
+
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
userSetupCode
=
'
\n
'
+
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
delete
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
delete
Blockly
.
Arduino
.
setups_
[
'
userSetupCode
'
];
...
@@ -167,11 +170,15 @@ Blockly.Arduino.finish = function(code) {
...
@@ -167,11 +170,15 @@ Blockly.Arduino.finish = function(code) {
for
(
var
name
in
Blockly
.
Arduino
.
setups_
)
{
for
(
var
name
in
Blockly
.
Arduino
.
setups_
)
{
setups
.
push
(
Blockly
.
Arduino
.
setups_
[
name
]);
setups
.
push
(
Blockly
.
Arduino
.
setups_
[
name
]);
}
}
if
(
userSetupCode
)
{
setups
.
push
(
userSetupCode
);
}
var
allDefs
=
includes
.
join
(
'
\n
'
)
+
'
\n\n
'
+
definitions
.
join
(
'
\n
'
)
+
'
\n\n
'
+
var
allDefs
=
includes
.
join
(
'
\n
'
)
+
definitions
.
join
(
'
\n
'
)
+
functions
.
join
(
'
\n\n
'
)
+
'
\n\n
void setup() {
\n
'
+
functions
.
join
(
'
\n\n
'
);
setups
.
join
(
'
\n
'
)
+
'
\n
'
+
userSetupCode
+
'
}
'
;
var
setup
=
'
void setup() {
'
+
setups
.
join
(
'
\n
'
)
+
'
\n
}
\n\n
'
;
return
allDefs
.
replace
(
/
\n\n
+/g
,
'
\n\n
'
).
replace
(
/
\n
*$/
,
'
\n\n\n
'
)
+
code
;
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) {
...
@@ -57,7 +57,7 @@ Blockly.Arduino['procedures_defreturn'] = function(block) {
// Construct code
// Construct code
var
code
=
returnType
+
'
'
+
funcName
+
'
(
'
+
args
.
join
(
'
,
'
)
+
'
) {
\n
'
+
var
code
=
returnType
+
'
'
+
funcName
+
'
(
'
+
args
.
join
(
'
,
'
)
+
'
) {
\n
'
+
branch
+
returnValue
+
'
}
\n
'
;
branch
+
returnValue
+
'
}
'
;
code
=
Blockly
.
Arduino
.
scrub_
(
block
,
code
);
code
=
Blockly
.
Arduino
.
scrub_
(
block
,
code
);
Blockly
.
Arduino
.
userFunctions_
[
funcName
]
=
code
;
Blockly
.
Arduino
.
userFunctions_
[
funcName
]
=
code
;
return
null
;
return
null
;
...
@@ -147,12 +147,12 @@ Blockly.Arduino['arduino_functions'] = function(block) {
...
@@ -147,12 +147,12 @@ Blockly.Arduino['arduino_functions'] = function(block) {
}
}
var
setupBranch
=
Blockly
.
Arduino
.
statementToCode
(
block
,
'
SETUP_FUNC
'
);
var
setupBranch
=
Blockly
.
Arduino
.
statementToCode
(
block
,
'
SETUP_FUNC
'
);
//
Remove first spacers as they will be added again in "addSetup()"
//
var setupCode = Blockly.Arduino.scrub_(block, setupBranch); No comment block
//setupBranch = setupBranch.substring(2);
if
(
setupBranch
)
{
var
setupCode
=
Blockly
.
Arduino
.
scrub_
(
block
,
setupBranch
);
Blockly
.
Arduino
.
addSetup
(
'
userSetupCode
'
,
setupBranch
,
true
);
Blockly
.
Arduino
.
addSetup
(
'
userSetupCode
'
,
setupCode
,
true
);
}
var
loopBranch
=
statementToCodeNoTab
(
block
,
'
LOOP_FUNC
'
);
var
loopBranch
=
statementToCodeNoTab
(
block
,
'
LOOP_FUNC
'
);
var
loopcode
=
Blockly
.
Arduino
.
scrub_
(
block
,
loopBranch
);
//var loopcode = Blockly.Arduino.scrub_(block, loopBranch); No comment block
return
loop
code
;
return
loop
Branch
;
};
};
blockly/generators/arduino/serial.js
View file @
25c52c79
...
@@ -46,7 +46,7 @@ Blockly.Arduino['serial_print'] = function(block) {
...
@@ -46,7 +46,7 @@ Blockly.Arduino['serial_print'] = function(block) {
Blockly
.
Arduino
[
'
serial_setup
'
]
=
function
(
block
)
{
Blockly
.
Arduino
[
'
serial_setup
'
]
=
function
(
block
)
{
var
serialId
=
block
.
getFieldValue
(
'
SERIAL_ID
'
);
var
serialId
=
block
.
getFieldValue
(
'
SERIAL_ID
'
);
var
serialSpeed
=
block
.
getFieldValue
(
'
SPEED
'
);
var
serialSpeed
=
block
.
getFieldValue
(
'
SPEED
'
);
var
serialSetupCode
=
serialId
+
'
.begin(
'
+
serialSpeed
+
'
);
\n
'
;
var
serialSetupCode
=
serialId
+
'
.begin(
'
+
serialSpeed
+
'
);
'
;
Blockly
.
Arduino
.
addSetup
(
'
serial_
'
+
serialId
,
serialSetupCode
,
true
);
Blockly
.
Arduino
.
addSetup
(
'
serial_
'
+
serialId
,
serialSetupCode
,
true
);
var
code
=
''
;
var
code
=
''
;
return
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