Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
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
appinventor-sources
Commits
a6a4b578
Unverified
Commit
a6a4b578
authored
Mar 20, 2020
by
Diego Barreiro
Committed by
GitHub
Mar 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Serial Component (#1732)
parent
2ade5c0e
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
211 additions
and
0 deletions
+211
-0
appinventor/appengine/src/com/google/appinventor/client/Images.java
...r/appengine/src/com/google/appinventor/client/Images.java
+6
-0
appinventor/appengine/src/com/google/appinventor/client/editor/simple/palette/SimpleComponentDescriptor.java
...ient/editor/simple/palette/SimpleComponentDescriptor.java
+1
-0
appinventor/appengine/src/com/google/appinventor/images/arduino.png
...r/appengine/src/com/google/appinventor/images/arduino.png
+0
-0
appinventor/components/build.xml
appinventor/components/build.xml
+1
-0
appinventor/components/src/com/google/appinventor/components/common/YaVersion.java
...c/com/google/appinventor/components/common/YaVersion.java
+4
-0
appinventor/components/src/com/google/appinventor/components/runtime/Serial.java
...src/com/google/appinventor/components/runtime/Serial.java
+157
-0
appinventor/components/src/com/google/appinventor/components/runtime/util/ErrorMessages.java
...le/appinventor/components/runtime/util/ErrorMessages.java
+9
-0
appinventor/docs/html/reference/components/connectivity.html
appinventor/docs/html/reference/components/connectivity.html
+33
-0
appinventor/lib/physicaloid/physicaloid-library.jar
appinventor/lib/physicaloid/physicaloid-library.jar
+0
-0
No files found.
appinventor/appengine/src/com/google/appinventor/client/Images.java
View file @
a6a4b578
...
...
@@ -630,6 +630,12 @@ public interface Images extends Resources {
@Source
(
"com/google/appinventor/images/logo.png"
)
ImageResource
logo
();
/**
* Designer palette item: Arduino component
*/
@Source
(
"com/google/appinventor/images/arduino.png"
)
ImageResource
arduino
();
/**
* Media icon: image
*/
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/palette/SimpleComponentDescriptor.java
View file @
a6a4b578
...
...
@@ -169,6 +169,7 @@ public final class SimpleComponentDescriptor {
bundledImages
.
put
(
"images/polygon.png"
,
images
.
polygon
());
bundledImages
.
put
(
"images/featurecollection.png"
,
images
.
featurecollection
());
bundledImages
.
put
(
"images/navigation.png"
,
images
.
navigationComponent
());
bundledImages
.
put
(
"images/arduino.png"
,
images
.
arduino
());
imagesInitialized
=
true
;
}
...
...
appinventor/appengine/src/com/google/appinventor/images/arduino.png
0 → 100644
View file @
a6a4b578
777 Bytes
appinventor/components/build.xml
View file @
a6a4b578
...
...
@@ -151,6 +151,7 @@
<copy
toFile=
"${public.deps.dir}/commons-pool.jar"
file=
"${lib.dir}/commons-pool/commons-pool2-2.0.jar"
/>
<copy
toFile=
"${public.deps.dir}/guava-14.0.1.jar"
file=
"${lib.dir}/guava/guava-14.0.1.jar"
/>
<copy
toFile=
"${public.deps.dir}/core.jar"
file=
"${lib.dir}/QRGenerator/core.jar"
/>
<copy
toFile=
"${public.deps.dir}/physicaloid.jar"
file=
"${lib.dir}/physicaloid/physicaloid-library.jar"
/>
<!-- BEGIN Android Support Libraries -->
<copy
todir=
"${public.deps.dir}/"
>
<fileset
dir=
"${support.dir}/"
includes=
"*.aar,*.jar"
excludes=
"testing-support-R-classes.jar"
/>
...
...
appinventor/components/src/com/google/appinventor/components/common/YaVersion.java
View file @
a6a4b578
...
...
@@ -505,6 +505,7 @@ public class YaVersion {
// - WEBVIEWER_COMPONENT_VERSION was incremented to 9
// For YOUNG_ANDROID_VERSION 204:
// - NAVIGATION_COMPONENT_VERSION was initialized to 1
// - SERIAL_COMPONENT_VERSION was initialized to 1
public
static
final
int
YOUNG_ANDROID_VERSION
=
204
;
...
...
@@ -1331,6 +1332,9 @@ public class YaVersion {
//For PROXIMITYSENSOR_COMPONENT_VERSION: Initial Version
public
static
final
int
PROXIMITYSENSOR_COMPONENT_VERSION
=
1
;
//For SERIAL_COMPONENT_VERSION: Initial Version
public
static
final
int
SERIAL_COMPONENT_VERSION
=
1
;
// Rendezvous Server Location
public
static
final
String
RENDEZVOUS_SERVER
=
"rendezvous.appinventor.mit.edu"
;
...
...
appinventor/components/src/com/google/appinventor/components/runtime/Serial.java
0 → 100644
View file @
a6a4b578
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2016-2019 MIT, All rights reserved
// Copyright 2017-2019 Kodular, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package
com.google.appinventor.components.runtime
;
import
android.content.Context
;
import
android.util.Log
;
import
com.physicaloid.lib.Physicaloid
;
import
com.google.appinventor.components.common.ComponentCategory
;
import
com.google.appinventor.components.annotations.DesignerComponent
;
import
com.google.appinventor.components.annotations.DesignerProperty
;
import
com.google.appinventor.components.annotations.PropertyCategory
;
import
com.google.appinventor.components.annotations.SimpleFunction
;
import
com.google.appinventor.components.annotations.SimpleObject
;
import
com.google.appinventor.components.annotations.SimpleProperty
;
import
com.google.appinventor.components.annotations.UsesLibraries
;
import
com.google.appinventor.components.common.YaVersion
;
import
com.google.appinventor.components.common.PropertyTypeConstants
;
import
com.google.appinventor.components.runtime.util.ErrorMessages
;
import
java.io.UnsupportedEncodingException
;
@DesignerComponent
(
version
=
YaVersion
.
SERIAL_COMPONENT_VERSION
,
description
=
"Serial component which can be used to connect to devices like Arduino"
,
category
=
ComponentCategory
.
CONNECTIVITY
,
nonVisible
=
true
,
iconName
=
"images/arduino.png"
,
androidMinSdk
=
12
)
@SimpleObject
@UsesLibraries
(
libraries
=
"physicaloid.jar"
)
public
class
Serial
extends
AndroidNonvisibleComponent
implements
Component
{
private
static
final
String
LOG_TAG
=
"Serial Component"
;
private
Context
context
;
private
Physicaloid
mPhysicaloid
;
private
int
baudRate
=
9600
;
private
int
bytes
=
256
;
public
Serial
(
ComponentContainer
container
)
{
super
(
container
.
$form
());
context
=
container
.
$context
();
Log
.
d
(
LOG_TAG
,
"Created"
);
}
@SimpleFunction
(
description
=
"Initializes serial connection."
)
public
void
InitializeSerial
()
{
mPhysicaloid
=
new
Physicaloid
(
context
);
BaudRate
(
this
.
baudRate
);
Log
.
d
(
LOG_TAG
,
"Initialized"
);
}
@SimpleFunction
(
description
=
"Opens serial connection. Returns true when opened."
)
public
boolean
OpenSerial
()
{
Log
.
d
(
LOG_TAG
,
"Opening connection"
);
if
(
mPhysicaloid
==
null
)
{
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"OpenSerial"
,
ErrorMessages
.
ERROR_SERIAL_NOT_INITIALIZED
);
return
false
;
}
return
mPhysicaloid
.
open
();
}
@SimpleFunction
(
description
=
"Closes serial connection. Returns true when closed."
)
public
boolean
CloseSerial
()
{
Log
.
d
(
LOG_TAG
,
"Closing connection"
);
if
(
mPhysicaloid
==
null
)
{
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"CloseSerial"
,
ErrorMessages
.
ERROR_SERIAL_NOT_INITIALIZED
);
return
false
;
}
return
mPhysicaloid
.
close
();
}
@SimpleFunction
(
description
=
"Reads data from serial."
)
public
String
ReadSerial
()
{
String
data
=
""
;
if
(
mPhysicaloid
==
null
)
{
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"ReadSerial"
,
ErrorMessages
.
ERROR_SERIAL_NOT_INITIALIZED
);
}
else
{
byte
[]
buf
=
new
byte
[
this
.
bytes
];
if
(
mPhysicaloid
.
read
(
buf
)
>
0
)
{
try
{
data
=
new
String
(
buf
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
mEr
)
{
Log
.
e
(
LOG_TAG
,
mEr
.
getMessage
());
}
}
}
return
data
;
}
@SimpleFunction
(
description
=
"Writes given data to serial."
)
public
void
WriteSerial
(
String
data
)
{
if
(!
data
.
isEmpty
()
&&
mPhysicaloid
!=
null
)
{
byte
[]
buf
=
data
.
getBytes
();
int
result
=
mPhysicaloid
.
write
(
buf
);
if
(
result
==
-
1
)
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"WriteSerial"
,
ErrorMessages
.
ERROR_SERIAL_WRITING
);
}
else
if
(
mPhysicaloid
==
null
)
{
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"WriteSerial"
,
ErrorMessages
.
ERROR_SERIAL_NOT_INITIALIZED
);
}
}
@SimpleFunction
(
description
=
"Writes given data to serial, and appends a new line at the end."
)
public
void
PrintSerial
(
String
data
)
{
if
(!
data
.
isEmpty
())
WriteSerial
(
data
+
"\n"
);
}
@SimpleProperty
(
category
=
PropertyCategory
.
BEHAVIOR
,
description
=
"Returns true when the Serial connection is open."
)
public
boolean
IsOpen
()
{
if
(
mPhysicaloid
==
null
)
{
form
.
dispatchErrorOccurredEvent
(
Serial
.
this
,
"IsOpen"
,
ErrorMessages
.
ERROR_SERIAL_NOT_INITIALIZED
);
return
false
;
}
return
mPhysicaloid
.
isOpened
();
}
@SimpleProperty
(
category
=
PropertyCategory
.
BEHAVIOR
,
description
=
"Returns true when the Serial has been initialized."
)
public
boolean
IsInitialized
()
{
return
mPhysicaloid
!=
null
;
}
@SimpleProperty
(
category
=
PropertyCategory
.
BEHAVIOR
,
description
=
"Returns the current baud rate"
)
public
int
BaudRate
()
{
return
this
.
baudRate
;
}
@DesignerProperty
(
editorType
=
PropertyTypeConstants
.
PROPERTY_TYPE_INTEGER
,
defaultValue
=
"9600"
)
@SimpleProperty
public
void
BaudRate
(
int
baudRate
)
{
this
.
baudRate
=
baudRate
;
Log
.
d
(
LOG_TAG
,
"Baud Rate: "
+
baudRate
);
if
(
mPhysicaloid
!=
null
)
mPhysicaloid
.
setBaudrate
(
baudRate
);
else
Log
.
w
(
LOG_TAG
,
"Could not set Serial Baud Rate to "
+
baudRate
+
". Just saved, not applied to serial! Maybe you forgot to initialize it?"
);
}
@SimpleProperty
(
category
=
PropertyCategory
.
BEHAVIOR
,
description
=
"Returns the buffer size in bytes"
)
public
int
BufferSize
()
{
return
this
.
bytes
;
}
@DesignerProperty
(
editorType
=
PropertyTypeConstants
.
PROPERTY_TYPE_INTEGER
,
defaultValue
=
"256"
)
@SimpleProperty
public
void
BufferSize
(
int
bytes
)
{
this
.
bytes
=
bytes
;
Log
.
d
(
LOG_TAG
,
"Buffer Size: "
+
bytes
);
}
}
appinventor/components/src/com/google/appinventor/components/runtime/util/ErrorMessages.java
View file @
a6a4b578
...
...
@@ -269,12 +269,17 @@ public final class ErrorMessages {
public
static
final
int
ERROR_SERVER
=
3808
;
public
static
final
int
ERROR_SPEECH_TIMEOUT
=
3809
;
// Serial errors
public
static
final
int
ERROR_SERIAL_NOT_INITIALIZED
=
3901
;
public
static
final
int
ERROR_SERIAL_WRITING
=
3902
;
// Navigation Errors
public
static
final
int
ERROR_INVALID_API_KEY
=
4001
;
public
static
final
int
ERROR_UNABLE_TO_REQUEST_DIRECTIONS
=
4002
;
public
static
final
int
ERROR_ROUTING_SERVICE_ERROR
=
4003
;
public
static
final
int
ERROR_NO_ROUTE_FOUND
=
4004
;
// Start the next group of errors at 4100
// Mapping of error numbers to error message format strings.
...
...
@@ -676,6 +681,10 @@ public final class ErrorMessages {
errorMessages
.
put
(
ERROR_SERVER
,
"Error From Server"
);
errorMessages
.
put
(
ERROR_SPEECH_TIMEOUT
,
"No Speech Input"
);
// Serial
errorMessages
.
put
(
ERROR_SERIAL_NOT_INITIALIZED
,
"Serial was not initialized"
);
errorMessages
.
put
(
ERROR_SERIAL_WRITING
,
"Error writing data to serial"
);
// Navigation Errors
errorMessages
.
put
(
ERROR_INVALID_API_KEY
,
"No api key provided"
);
errorMessages
.
put
(
ERROR_UNABLE_TO_REQUEST_DIRECTIONS
,
...
...
appinventor/docs/html/reference/components/connectivity.html
View file @
a6a4b578
...
...
@@ -134,6 +134,7 @@
<li><a
href=
"#ActivityStarter"
>
ActivityStarter
</a></li>
<li><a
href=
"#BluetoothClient"
>
BluetoothClient
</a></li>
<li><a
href=
"#BluetoothServer"
>
BluetoothServer
</a></li>
<li><a
href=
"#Serial"
>
Serial
</a></li>
<li><a
href=
"#Web"
>
Web
</a></li>
</ul>
...
...
@@ -471,6 +472,38 @@ set the following properties:
<dd>
Stop accepting an incoming connection.
</dd>
</dl>
<h2
id=
"Serial"
>
Serial
</h2>
<h3
id=
"Serial-Properties"
>
Properties
</h3>
<dl
class=
"properties"
>
<dt
id=
"Serial.BaudRate"
class=
"number do"
><em>
BaudRate
</em></dt>
<dd>
Specifies the baud rate for the connection.
</dd>
<dt
id=
"Serial.BufferSize"
class=
"number do"
><em>
BufferSize
</em></dt>
<dd>
Specifies the buffer size in bytes for the connection.
</dd>
<dt
id=
"Serial.IsInitialized"
class=
"boolean bo"
><em>
IsInitialized
</em></dt>
<dd>
Returns true when the component has been initialized.
</dd>
<dt
id=
"Serial.IsOpen"
class=
"boolean bo"
><em>
IsOpen
</em></dt>
<dd>
Returns true when the connection has been opened.
</dd>
</dl>
<h3
id=
"Serial-Methods"
>
Methods
</h3>
<dl
class=
"methods"
>
<dt
id=
"Serial.CloseSerial"
class=
"method returns boolean"
><i></i>
CloseSerial()
</dt>
<dd>
Attempts to close the serial connection, returning true when success.
</dd>
<dt
id=
"Serial.InitializeSerial"
class=
"method"
><i></i>
InitializeSerial()
</dt>
<dd>
Initializes the serial component to be ready to use.
</dd>
<dt
id=
"Serial.OpenSerial"
class=
"method returns boolean"
><i></i>
OpenSerial()
</dt>
<dd>
Attempts to close the serial connection, returning true when success.
</dd>
<dt
id=
"Serial.PrintSerial"
class=
"method"
><i></i>
PrintSerial(
<em
class=
"text"
>
data
</em>
)
</dt>
<dd>
Sends the given data to the serial connection, and appends a new line.
</dd>
<dt
id=
"Serial.ReadSerial"
class=
"method"
><i></i>
ReadSerial()
</dt>
<dd>
Starts reading the serial port. Will raise AfterReadSerial event.
</dd>
<dt
id=
"Serial.WriteSerial"
class=
"method"
><i></i>
WriteSerial(
<em
class=
"text"
>
data
</em>
)
</dt>
<dd>
Sends the given data to the serial connection.
</dd>
</dl>
<h2
id=
"Web"
>
Web
</h2>
<p>
Non-visible component that provides functions for HTTP GET, POST, PUT, and DELETE requests.
</p>
...
...
appinventor/lib/physicaloid/physicaloid-library.jar
0 → 100644
View file @
a6a4b578
File added
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