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
662aa5a5
Commit
662aa5a5
authored
Aug 28, 2014
by
Carlos
Committed by
carlospamg
Aug 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Arduino Servo library blocks and code generator
parent
a867bf01
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
5 deletions
+119
-5
apps/arduino/generated/en.js
apps/arduino/generated/en.js
+3
-3
apps/arduino/template.soy
apps/arduino/template.soy
+6
-0
generators/arduino.js
generators/arduino.js
+2
-2
generators/arduino/servo.js
generators/arduino/servo.js
+108
-0
No files found.
apps/arduino/generated/en.js
View file @
662aa5a5
This diff is collapsed.
Click to expand it.
apps/arduino/template.soy
View file @
662aa5a5
...
...
@@ -37,6 +37,7 @@
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../generators/arduino/servo.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/time.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
...
...
@@ -283,6 +284,10 @@
<block type="time_millis"></block>
<block type="time_micros"></block>
</category>
<category name="{msg meaning="Apps.catServo" desc="IBID"}Servo{/msg}">
<block type="servo_write"></block>
<block type="servo_read"></block>
</category>
</xml>
{/template}
...
...
@@ -302,6 +307,7 @@
<script type="text/javascript" src="../../generators/arduino/loops.js"></script>
<script type="text/javascript" src="../../generators/arduino/math.js"></script>
<script type="text/javascript" src="../../generators/arduino/procedures.js"></script>
<script type="text/javascript" src="../../generators/arduino/servo.js"></script>
<script type="text/javascript" src="../../generators/arduino/text.js"></script>
<script type="text/javascript" src="../../generators/arduino/time.js"></script>
<script type="text/javascript" src="../../generators/arduino/variables.js"></script>
...
...
generators/arduino.js
View file @
662aa5a5
...
...
@@ -76,7 +76,7 @@ var profile = {
interrupt
:
[[
"
Int_1
"
,
"
1
"
],
[
"
Int_2
"
,
"
2
"
],
[
"
Int_3
"
,
"
3
"
],
[
"
Int_4
"
,
"
4
"
],
[
"
Int_5
"
,
"
5
"
]],
serial
:
[[
"
300
"
,
"
300
"
],
[
"
600
"
,
"
600
"
],
[
"
1200
"
,
"
1200
"
],
[
"
2400
"
,
"
2400
"
],
[
"
4800
"
,
"
4800
"
],
[
"
9600
"
,
"
9600
"
],
[
"
14400
"
,
"
14400
"
],
[
"
19200
"
,
"
19200
"
],
[
"
28800
"
,
"
28800
"
],
[
"
31250
"
,
"
31250
"
],
[
"
38400
"
,
"
38400
"
],[
"
57600
"
,
"
57600
"
],
[
"
115200
"
,
"
115200
"
]],
builtin_led
:
[[
"
BUILTIN_1
"
,
"
13
"
]],
pin_types
:
{
INPUT
:
"
INPUT
"
,
OUTPUT
:
"
OUTPUT
"
,
PWM
:
"
PWM
"
},
pin_types
:
{
INPUT
:
"
INPUT
"
,
OUTPUT
:
"
OUTPUT
"
,
PWM
:
"
PWM
"
,
SERVO
:
"
SERVO
"
},
types
:
[[
"
void
"
,
"
void
"
],
[
"
Boolean
"
,
"
boolean
"
],
[
"
Character
"
,
"
char
"
],
[
"
Unsigned Character
"
,
"
unsigned char
"
],
[
"
Byte
"
,
"
byte
"
],
[
"
Integer
"
,
"
int
"
],
[
"
Unsigned Integer
"
,
"
unsigned int
"
],
[
"
Word
"
,
"
word
"
],
[
"
Long
"
,
"
long
"
],
[
"
Unsigned Long
"
,
"
unsigned long
"
],
[
"
Short
"
,
"
short
"
],
[
"
Float
"
,
"
float
"
],
[
"
Double
"
,
"
double
"
],
[
"
String
"
,
"
String
"
],
[
"
Char Array
"
,
"
string
"
],
[
"
Array
"
,
"
array
"
]]
},
arduino_mega
:{
...
...
@@ -215,7 +215,7 @@ Blockly.Arduino.finish = function(code) {
}
var
allDefs
=
imports
.
join
(
'
\n
'
)
+
definitions
.
join
(
'
\n
'
)
+
'
\n
void setup() {
\n
'
+
setups
.
join
(
'
\n
'
)
+
'
\n
}
'
;
'
\n
\n
void setup() {
\n
'
+
setups
.
join
(
'
\n
'
)
+
'
\n
}
'
;
return
allDefs
.
replace
(
/
\n\n
+/g
,
'
\n\n
'
).
replace
(
/
\n
*$/
,
'
\n\n\n
'
)
+
code
;
};
...
...
generators/arduino/servo.js
0 → 100644
View file @
662aa5a5
/**
* @fileoverview Blocks extension for Arduino Servo library.
* The Arduino Servo functions syntax can be found in http://arduino.cc/en/reference/servo
*/
'
use strict
'
;
goog
.
provide
(
'
Blockly.Arduino.servo
'
);
goog
.
require
(
'
Blockly.Arduino
'
);
/**
* Description
*/
Blockly
.
Blocks
[
'
servo_write
'
]
=
{
init
:
function
()
{
this
.
setHelpUrl
(
'
http://arduino.cc/en/Reference/ServoWrite
'
);
this
.
setColour
(
50
);
this
.
appendDummyInput
(
''
)
.
appendField
(
'
Set SERVO from Pin
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
pwm
),
'
SERVO_PIN
'
);
this
.
setInputsInline
(
false
);
this
.
appendValueInput
(
'
SERVO_ANGLE
'
,
'
Number
'
)
.
setCheck
(
'
Number
'
)
.
appendField
(
"
to
"
);
this
.
appendDummyInput
(
''
)
.
appendField
(
'
Degrees (0-180)
'
);
this
.
setInputsInline
(
true
);
this
.
setPreviousStatement
(
true
,
null
);
this
.
setNextStatement
(
true
,
null
);
this
.
setTooltip
(
'
Set a Servo to an specified angle
'
);
}
};
/**
* Description
*/
Blockly
.
Arduino
[
'
servo_write
'
]
=
function
(
block
)
{
var
pin_key
=
block
.
getFieldValue
(
'
SERVO_PIN
'
);
var
pin_type
=
profile
.
default
.
pin_types
.
SERVO
;
var
servo_name
=
'
myServo_
'
+
pin_key
;
var
servo_angle
=
Blockly
.
Arduino
.
valueToCode
(
block
,
'
SERVO_ANGLE
'
,
Blockly
.
Arduino
.
ORDER_ATOMIC
)
||
'
90
'
;
var
code
=
servo_name
+
'
.write(
'
+
servo_angle
+
'
);
\n
'
;
// Maintain the setup regardless of pin conflict, warning should be enough
Blockly
.
Arduino
.
definitions_
[
'
define_servo
'
]
=
'
#include <Servo.h>
\n
'
;
Blockly
.
Arduino
.
definitions_
[
'
global_servo_
'
+
pin_key
]
=
'
Servo
'
+
servo_name
+
'
;
'
;
Blockly
.
Arduino
.
setups_
[
'
setup_servo_
'
+
pin_key
]
=
servo_name
+
'
.attach(
'
+
pin_key
+
'
);
'
;
// If the IO has been configured already set a block warning for the user
if
(
pin_key
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pin_key
]
!=
pin_type
)
{
block
.
setWarningText
(
'
Pin alredy used as
'
+
Blockly
.
Arduino
.
pins_
[
pin_key
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pin_key
]
=
pin_type
;
block
.
setWarningText
(
null
);
}
return
code
;
};
/**
* Description
*/
Blockly
.
Blocks
[
'
servo_read
'
]
=
{
init
:
function
()
{
this
.
setHelpUrl
(
'
http://arduino.cc/en/Reference/ServoRead
'
);
this
.
setColour
(
50
);
this
.
appendDummyInput
(
''
)
.
appendField
(
'
Read SERVO from PIN#
'
)
.
appendField
(
new
Blockly
.
FieldDropdown
(
profile
.
default
.
pwm
),
'
SERVO_PIN
'
);
this
.
setOutput
(
true
,
'
Number
'
);
this
.
setTooltip
(
'
Read a Servo angle
'
);
}
};
/**
* Description
*/
Blockly
.
Arduino
[
'
servo_read
'
]
=
function
(
block
)
{
var
pin_key
=
block
.
getFieldValue
(
'
SERVO_PIN
'
);
var
pin_type
=
profile
.
default
.
pin_types
.
SERVO
;
var
servo_name
=
'
myServo_
'
+
pin_key
;
var
code
=
servo_name
+
'
.read()
'
;
// Maintain the setup regardless of pin conflict, warning should be enough
Blockly
.
Arduino
.
definitions_
[
'
define_servo
'
]
=
'
#include <Servo.h>
\n
'
;
Blockly
.
Arduino
.
definitions_
[
'
global_servo_
'
+
pin_key
]
=
'
Servo
'
+
servo_name
+
'
;
'
;
Blockly
.
Arduino
.
setups_
[
'
setup_servo_
'
+
pin_key
]
=
servo_name
+
'
.attach(
'
+
pin_key
+
'
);
'
;
// If the IO has been configured already set a block warning for the user
if
(
pin_key
in
Blockly
.
Arduino
.
pins_
)
{
if
(
Blockly
.
Arduino
.
pins_
[
pin_key
]
!=
pin_type
)
{
block
.
setWarningText
(
'
Pin alredy used as
'
+
Blockly
.
Arduino
.
pins_
[
pin_key
]);
}
else
{
block
.
setWarningText
(
null
);
}
}
else
{
// First time this IO pin is used, so configure it
Blockly
.
Arduino
.
pins_
[
pin_key
]
=
pin_type
;
block
.
setWarningText
(
null
);
}
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