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
9616c87f
Commit
9616c87f
authored
Feb 23, 2015
by
carlosperate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added examples functionality to Arduino webapp.
parent
a59c9a7f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
341 additions
and
41 deletions
+341
-41
TODO.md
TODO.md
+4
-3
apps/arduino/arduino_material.js
apps/arduino/arduino_material.js
+34
-10
apps/arduino/arduino_material_ardublockly.js
apps/arduino/arduino_material_ardublockly.js
+58
-17
apps/arduino/examples/blink.xml
apps/arduino/examples/blink.xml
+38
-0
apps/arduino/examples/serial_print_ascii_.xml
apps/arduino/examples/serial_print_ascii_.xml
+90
-0
apps/arduino/examples/servo_knob.xml
apps/arduino/examples/servo_knob.xml
+48
-0
apps/arduino/examples/stepper_knob.xml
apps/arduino/examples/stepper_knob.xml
+59
-0
apps/arduino/index.html
apps/arduino/index.html
+8
-9
apps/arduino_classic/arduino_classic.js
apps/arduino_classic/arduino_classic.js
+2
-2
No files found.
TODO.md
View file @
9616c87f
...
...
@@ -15,7 +15,7 @@
Can't convert 'bytes' object to str implicitly
There was an error manipulating the sketch data!!
```
-
[ ]
## Server
-
[ ] Serial port test code
...
...
@@ -46,7 +46,8 @@ There was an error manipulating the sketch data!!
## Arduino web-app
-
[ ] Edit toolbox fade out + visibility button fade in with a CSS animated change in height with overflow hidden.
-
[ ] Add examples
-
[x] Add examples
-
[ ] Change js variables naming convention from current 'snake_case' to 'lower camel case' to comply with Google's js coding style.
#
#
Future features
# Future features
-
[ ] Serial console in web app for comms with Arduino
apps/arduino/arduino_material.js
View file @
9616c87f
...
...
@@ -54,16 +54,14 @@ ArduinoMaterial.bindActionFunctions_ = function() {
ArduinoMaterial
.
bindClick_
(
'
menu_settings
'
,
function
()
{
ArduinoMaterial
.
openSettings
();
$
(
'
.button-collapse
'
).
sideNav
(
'
hide
'
);
});
ArduinoMaterial
.
bindClick_
(
'
menu_example_1
'
,
ArduinoMaterial
.
functionNotImplemented
);
ArduinoMaterial
.
bindClick_
(
'
menu_example_2
'
,
ArduinoMaterial
.
functionNotImplemented
);
ArduinoMaterial
.
bindClick_
(
'
menu_example_3
'
,
ArduinoMaterial
.
functionNotImplemented
);
ArduinoMaterial
.
bindClick_
(
'
menu_example_4
'
,
ArduinoMaterial
.
functionNotImplemented
);
ArduinoMaterial
.
bindClick_
(
'
menu_example_5
'
,
ArduinoMaterial
.
functionNotImplemented
);
ArduinoMaterial
.
bindClick_
(
'
menu_example_1
'
,
function
()
{
ArduinoMaterial
.
loadServerXmlFile
(
'
examples/blink.xml
'
)});
ArduinoMaterial
.
bindClick_
(
'
menu_example_2
'
,
function
()
{
ArduinoMaterial
.
loadServerXmlFile
(
'
examples/serial_print_ascii_.xml
'
)});
ArduinoMaterial
.
bindClick_
(
'
menu_example_3
'
,
function
()
{
ArduinoMaterial
.
loadServerXmlFile
(
'
examples/servo_knob.xml
'
)});
ArduinoMaterial
.
bindClick_
(
'
menu_example_4
'
,
function
()
{
ArduinoMaterial
.
loadServerXmlFile
(
'
examples/stepper_knob.xml
'
)});
// Floating buttons
ArduinoMaterial
.
bindClick_
(
'
button_run
'
,
ArduinoMaterial
.
sendCode
);
...
...
@@ -108,6 +106,32 @@ ArduinoMaterial.bindBlocklyEventListeners_ = function() {
}
};
/**
* Loads an XML file from the server and adds the blocks into the Blockly
* workspace.
*/
ArduinoMaterial
.
loadServerXmlFile
=
function
(
xmlFile
)
{
// The loadXmlBlockFile loads the file asynchronously and needs a callback
var
loadXmlCallback
=
function
(
sucess
)
{
if
(
sucess
)
{
ArduinoMaterial
.
renderContent
();
}
else
{
ArduinoMaterial
.
materialAlert
(
'
Invalid XML
'
,
'
The XML file was not successfully parsed into blocks.
\
Please review the XML code and try again.
'
,
false
);
}
};
var
callbackConnectionError
=
function
()
{
$
(
'
#not_running_dialog
'
).
openModal
();
};
ArduinoMaterial
.
loadXmlBlockFile
(
xmlFile
,
loadXmlCallback
,
callbackConnectionError
);
};
/**
* Loads an XML file from the users file system and adds the blocks into the
* Blockly workspace.
...
...
apps/arduino/arduino_material_ardublockly.js
View file @
9616c87f
...
...
@@ -25,23 +25,7 @@ ArduinoMaterial.BLOCKLY_INJECTED = false;
*/
ArduinoMaterial
.
injectBlockly
=
function
(
blockly_el
,
toolbox_path
)
{
// Create a an XML HTTP request
var
request
;
try
{
// Firefox, Chrome, IE7+, Opera, Safari
request
=
new
XMLHttpRequest
();
}
catch
(
e
)
{
try
{
// IE6 and earlier
request
=
new
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);
}
catch
(
e
)
{
try
{
request
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);
}
catch
(
e
)
{
throw
'
Your browser does not support AJAX. Cannot load toolbox
'
;
}
}
}
var
request
=
ArduinoMaterial
.
ajaxRequest
();
// If file run locally Internet explorer fails here
try
{
...
...
@@ -74,6 +58,38 @@ ArduinoMaterial.injectBlockly = function(blockly_el, toolbox_path) {
}
};
/**
* Loads an XML file from the server and adds the blocks into the Blockly
* workspace.
*/
ArduinoMaterial
.
loadXmlBlockFile
=
function
(
xmlFile
,
callbackFileLoaded
,
callbackConectonError
)
{
// Create a an XML HTTP request
var
request
=
ArduinoMaterial
.
ajaxRequest
();
// If file run locally Internet explorer fails here
try
{
request
.
open
(
"
GET
"
,
xmlFile
,
true
);
}
catch
(
e
)
{
callbackConectonError
();
}
// Once file is open, parse the XML into the workspace
request
.
onreadystatechange
=
function
()
{
if
(
(
request
.
readyState
==
4
)
&&
(
request
.
status
==
200
)
)
{
var
success
=
ArduinoMaterial
.
replaceBlocksfromXml
(
request
.
responseText
);
callbackFileLoaded
(
success
);
}
}
// If file run locally Chrome will fail here
try
{
request
.
send
(
null
);
}
catch
(
e
)
{
callbackConectonError
();
}
};
/**
* Renders the Arduino color highlighted code code into an element.
* @return {!string} Arduino code string.
...
...
@@ -165,3 +181,28 @@ ArduinoMaterial.discard = function() {
});
}
};
/**
* Creates an AJAX request
* @return An XML HTTP Request
*/
ArduinoMaterial
.
ajaxRequest
=
function
()
{
var
request
;
try
{
// Firefox, Chrome, IE7+, Opera, Safari
request
=
new
XMLHttpRequest
();
}
catch
(
e
)
{
try
{
// IE6 and earlier
request
=
new
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);
}
catch
(
e
)
{
try
{
request
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);
}
catch
(
e
)
{
throw
'
Your browser does not support AJAX. Cannot load toolbox
'
;
request
=
null
;
}
}
}
return
request
;
};
\ No newline at end of file
apps/arduino/examples/blink.xml
0 → 100644
View file @
9616c87f
<xml>
<block
type=
"io_builtin_led"
id=
"131"
inline=
"true"
x=
"6"
y=
"88"
>
<field
name=
"BUILT_IN_LED"
>
13
</field>
<value
name=
"STATE"
>
<block
type=
"io_highlow"
id=
"132"
>
<field
name=
"STATE"
>
HIGH
</field>
</block>
</value>
<next>
<block
type=
"time_delay"
id=
"139"
inline=
"true"
>
<value
name=
"DELAY_TIME_MILI"
>
<block
type=
"math_number"
id=
"140"
>
<field
name=
"NUM"
>
1000
</field>
</block>
</value>
<next>
<block
type=
"io_builtin_led"
id=
"162"
inline=
"true"
>
<field
name=
"BUILT_IN_LED"
>
13
</field>
<value
name=
"STATE"
>
<block
type=
"io_highlow"
id=
"163"
>
<field
name=
"STATE"
>
HIGH
</field>
</block>
</value>
<next>
<block
type=
"time_delay"
id=
"160"
inline=
"true"
>
<value
name=
"DELAY_TIME_MILI"
>
<block
type=
"math_number"
id=
"161"
>
<field
name=
"NUM"
>
1000
</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</xml>
\ No newline at end of file
apps/arduino/examples/serial_print_ascii_.xml
0 → 100644
View file @
9616c87f
<xml>
<block
type=
"serial_speed"
id=
"9"
x=
"314"
y=
"68"
>
<field
name=
"SERIAL_ID"
>
Serial
</field>
<field
name=
"SPEED"
>
9600
</field>
</block>
<block
type=
"variables_set"
id=
"10"
inline=
"true"
x=
"40"
y=
"125"
>
<field
name=
"VAR"
>
thisByte
</field>
<value
name=
"VALUE"
>
<block
type=
"math_number"
id=
"11"
>
<field
name=
"NUM"
>
33
</field>
</block>
</value>
<next>
<block
type=
"controls_whileUntil"
id=
"12"
inline=
"false"
>
<field
name=
"MODE"
>
WHILE
</field>
<value
name=
"BOOL"
>
<block
type=
"logic_compare"
id=
"13"
inline=
"true"
>
<field
name=
"OP"
>
LT
</field>
<value
name=
"A"
>
<block
type=
"variables_get"
id=
"14"
>
<field
name=
"VAR"
>
thisByte
</field>
</block>
</value>
<value
name=
"B"
>
<block
type=
"math_number"
id=
"15"
>
<field
name=
"NUM"
>
126
</field>
</block>
</value>
</block>
</value>
<statement
name=
"DO"
>
<block
type=
"serial_print"
id=
"16"
inline=
"true"
>
<field
name=
"SERIAL_ID"
>
Serial
</field>
<field
name=
"NEW_LINE"
>
FALSE
</field>
<value
name=
"CONTENT"
>
<block
type=
"variables_set_type"
id=
"17"
inline=
"true"
>
<field
name=
"VARIABLE_SETTYPE_TYPE"
>
char
</field>
<value
name=
"VARIABLE_SETTYPE_INPUT"
>
<block
type=
"variables_get"
id=
"18"
>
<field
name=
"VAR"
>
thisByte
</field>
</block>
</value>
</block>
</value>
<next>
<block
type=
"serial_print"
id=
"19"
inline=
"true"
>
<field
name=
"SERIAL_ID"
>
Serial
</field>
<field
name=
"NEW_LINE"
>
FALSE
</field>
<value
name=
"CONTENT"
>
<block
type=
"text"
id=
"20"
>
<field
name=
"TEXT"
>
, dec:
</field>
</block>
</value>
<next>
<block
type=
"serial_print"
id=
"21"
inline=
"true"
>
<field
name=
"SERIAL_ID"
>
Serial
</field>
<field
name=
"NEW_LINE"
>
TRUE
</field>
<value
name=
"CONTENT"
>
<block
type=
"variables_set_type"
id=
"22"
inline=
"true"
>
<field
name=
"VARIABLE_SETTYPE_TYPE"
>
byte
</field>
<value
name=
"VARIABLE_SETTYPE_INPUT"
>
<block
type=
"variables_get"
id=
"23"
>
<field
name=
"VAR"
>
thisByte
</field>
</block>
</value>
</block>
</value>
<next>
<block
type=
"math_change"
id=
"24"
inline=
"true"
>
<field
name=
"VAR"
>
thisByte
</field>
<value
name=
"DELTA"
>
<block
type=
"math_number"
id=
"25"
>
<field
name=
"NUM"
>
1
</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</statement>
<next>
<block
type=
"infinite_loop"
id=
"35"
></block>
</next>
</block>
</next>
</block>
</xml>
\ No newline at end of file
apps/arduino/examples/servo_knob.xml
0 → 100644
View file @
9616c87f
<xml
xmlns=
"http://www.w3.org/1999/xhtml"
>
<block
type=
"variables_set"
id=
"384"
inline=
"true"
x=
"31"
y=
"136"
>
<field
name=
"VAR"
>
val
</field>
<value
name=
"VALUE"
>
<block
type=
"io_analogread"
id=
"393"
>
<field
name=
"PIN"
>
A0
</field>
</block>
</value>
<next>
<block
type=
"variables_set"
id=
"397"
inline=
"true"
>
<field
name=
"VAR"
>
val
</field>
<value
name=
"VALUE"
>
<block
type=
"base_map"
id=
"416"
inline=
"true"
>
<value
name=
"NUM"
>
<block
type=
"variables_get"
id=
"420"
>
<field
name=
"VAR"
>
val
</field>
</block>
</value>
<value
name=
"DMAX"
>
<block
type=
"math_number"
id=
"439"
>
<field
name=
"NUM"
>
180
</field>
</block>
</value>
</block>
</value>
<next>
<block
type=
"servo_write"
id=
"370"
inline=
"true"
>
<field
name=
"SERVO_PIN"
>
9
</field>
<value
name=
"SERVO_ANGLE"
>
<block
type=
"variables_get"
id=
"443"
>
<field
name=
"VAR"
>
val
</field>
</block>
</value>
<next>
<block
type=
"time_delay"
id=
"450"
inline=
"true"
>
<value
name=
"DELAY_TIME_MILI"
>
<block
type=
"math_number"
id=
"451"
>
<field
name=
"NUM"
>
15
</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</next>
</block>
</xml>
\ No newline at end of file
apps/arduino/examples/stepper_knob.xml
0 → 100644
View file @
9616c87f
<xml>
<block
type=
"stepper_config"
id=
"1"
inline=
"false"
x=
"312"
y=
"38"
>
<field
name=
"STEPPER_PIN1"
>
8
</field>
<field
name=
"STEPPER_PIN2"
>
9
</field>
<value
name=
"STEPPER_STEPS"
>
<block
type=
"math_number"
id=
"2"
>
<field
name=
"NUM"
>
100
</field>
</block>
</value>
<value
name=
"STEPPER_SPEED"
>
<block
type=
"math_number"
id=
"3"
>
<field
name=
"NUM"
>
30
</field>
</block>
</value>
<value
name=
"STEPPER_NAME"
>
<block
type=
"text"
id=
"4"
>
<field
name=
"TEXT"
>
MyStepper
</field>
</block>
</value>
</block>
<block
type=
"variables_set"
id=
"5"
inline=
"true"
x=
"40"
y=
"201"
>
<field
name=
"VAR"
>
val
</field>
<value
name=
"VALUE"
>
<block
type=
"io_analogread"
id=
"6"
>
<field
name=
"PIN"
>
A0
</field>
</block>
</value>
<next>
<block
type=
"stepper_step"
id=
"7"
inline=
"true"
>
<field
name=
"STEPPER_NAME"
>
MyStepper
</field>
<value
name=
"STEPPER_STEPS"
>
<block
type=
"math_arithmetic"
id=
"8"
inline=
"true"
>
<field
name=
"OP"
>
MINUS
</field>
<value
name=
"A"
>
<block
type=
"variables_get"
id=
"9"
>
<field
name=
"VAR"
>
val
</field>
</block>
</value>
<value
name=
"B"
>
<block
type=
"variables_get"
id=
"10"
>
<field
name=
"VAR"
>
previous
</field>
</block>
</value>
</block>
</value>
<next>
<block
type=
"variables_set"
id=
"11"
inline=
"true"
>
<field
name=
"VAR"
>
previous
</field>
<value
name=
"VALUE"
>
<block
type=
"variables_get"
id=
"12"
>
<field
name=
"VAR"
>
val
</field>
</block>
</value>
</block>
</next>
</block>
</next>
</block>
</xml>
\ No newline at end of file
apps/arduino/index.html
View file @
9616c87f
...
...
@@ -93,11 +93,10 @@
<div
class=
"collapsible-header"
>
Examples
<i
class=
"mdi-navigation-arrow-drop-down"
></i></div>
<div
class=
"collapsible-body"
>
<ul>
<li
id=
"menu_example_1"
><a
href=
"#!"
>
Example 1
</a></li>
<li
id=
"menu_example_2"
><a
href=
"#!"
>
Example 2
</a></li>
<li
id=
"menu_example_3"
><a
href=
"#!"
>
Example 3
</a></li>
<li
id=
"menu_example_4"
><a
href=
"#!"
>
Example 4
</a></li>
<li
id=
"menu_example_5"
><a
href=
"#!"
>
Example 5
</a></li>
<li
id=
"menu_example_1"
><a
href=
"#!"
>
Blink
</a></li>
<li
id=
"menu_example_2"
><a
href=
"#!"
>
Serial print
</a></li>
<li
id=
"menu_example_3"
><a
href=
"#!"
>
Servo knob
</a></li>
<li
id=
"menu_example_4"
><a
href=
"#!"
>
Stepper knob
</a></li>
</ul>
</div>
</li>
...
...
@@ -237,8 +236,8 @@
</div>
</div>
<!--
General
Alert: Content is loaded using Javascript to display alerts -->
<div
id=
"not_running_dialog"
class=
"modal
modal-fixed-footer"
style=
"height:50%!important
"
>
<!--
Local Server
Alert: Content is loaded using Javascript to display alerts -->
<div
id=
"not_running_dialog"
class=
"modal"
>
<div
class=
"modal-content"
>
<h4
id=
"gen_alert_title"
>
Ardublockly not running locally
</h4>
<p>
For Ardublockly to work correctly, the Ardublockly server must be
...
...
@@ -251,8 +250,8 @@
<p>
If you have Ardublockly already installed, make sure the "
<i>
setup.py
</i>
or
the "
<i>
ardublockly_win.bat
</i>
" program is running.
</p>
</div>
<div
class=
"modal-footer"
>
<a
id=
"gen_alert_ok_link"
href=
"#"
class=
"waves-effect btn-flat modal-close"
>
Okay
</a>
<div>
<a
id=
"gen_alert_ok_link"
href=
"#"
class=
"waves-effect btn-flat modal-close"
style=
"float:right;margin-right:48px"
>
Okay
</a>
</div>
</div>
...
...
apps/arduino_classic/arduino_classic.js
View file @
9616c87f
...
...
@@ -121,7 +121,7 @@ ArduinoClassic.init = function() {
// Binding buttons
ArduinoClassic
.
bindClick
(
'
peekCode
'
,
ArduinoClassic
.
peekCode
);
ArduinoClassic
.
bindClick
(
'
openButton
'
,
ArduinoClassic
.
loadXmlFile
);
ArduinoClassic
.
bindClick
(
'
openButton
'
,
ArduinoClassic
.
load
User
XmlFile
);
ArduinoClassic
.
bindClick
(
'
saveButton
'
,
ArduinoClassic
.
saveXmlFile
);
ArduinoClassic
.
bindClick
(
'
trashButton
'
,
ArduinoClassic
.
discard
);
ArduinoClassic
.
bindClick
(
'
settingsButton
'
,
ArduinoClassic
.
openSettings
);
...
...
@@ -350,7 +350,7 @@ ArduinoClassic.injectBlockly = function(blockly_el, toolbox_path) {
* Loads an XML file from the users file system and adds the blocks into the
* Blockly workspace.
*/
ArduinoClassic
.
loadXmlFile
=
function
()
{
ArduinoClassic
.
load
User
XmlFile
=
function
()
{
// Create event listener function
var
parseInputXMLfile
=
function
(
e
)
{
var
files
=
e
.
target
.
files
;
...
...
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