Skip to content

Commit

Permalink
Merge branch 'master' of github.com:wearscript/wearscript-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandyn A. White committed Mar 22, 2014
2 parents 6609155 + e625f59 commit 647f2de
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_build
html
10 changes: 5 additions & 5 deletions arduino.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ Using an Arduino with WearScript you can integrate all varieties of sensors, inp

To start the manager in client mode (i.e., it connects to the Go server, see PubSub for details) use the following.

.. code-block:: guess
.. code-block:: bash
python manager.py --serialport /dev/ttyACM0 client <client endpoint here>
To start the manager in server mode (e.g., Glass connect directly to this script, bypassing the Go server) use the following. See PubSub for details on how to get Glass to connect locally and caveats of doing so.

.. code-block:: guess
.. code-block:: bash
python manager.py --serialport /dev/ttyACM0 server <server port here>
Basic
-----

Connected to an Arduino (tested with Uno and Due), the following uses the scroll gesture to control a servo on Pin 9 and an LED on pin 13 (both specified in the .ino file). We access them by sending data of the form ["arduinobasic", device, value] where devices index contiguously into servo pins then LEDs (i.e., binary pin, need not control an LED) specified in the .ino file. For Servos the value is written directly to the servo and for LEDs any non-zero value is "on" and zero is "off".
Connected to an Arduino (tested with Uno and Duo), the following uses the scroll gesture to control a servo on Pin 9 and an LED on pin 13 (both specified in the .ino file). We access them by sending data of the form ["arduinobasic", device, value] where devices index contiguously into servo pins then LEDs (i.e., binary pin, need not control an LED) specified in the .ino file. For Servos the value is written directly to the servo and for LEDs any non-zero value is "on" and zero is "off".

.. code-block:: guess
.. code-block:: html

<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0" bgcolor="#000000"><script>
Expand All @@ -46,4 +46,4 @@ Connected to an Arduino (tested with Uno and Due), the following uses the scroll
Neopixel
---------

Neopixels are independently addressable LED strips that can display multiple colors, change brightness, and display patterns over time. Using the included neopixel .ino file and sample script https://api.picar.us/wearscriptdev/#/gist/9390329/glass.html complex patterns can be programmed and executed on the Arduino including loops.
Neopixels are independently addressable LED strips that can display multiple colors, change brightness, and display patterns over time. Using the included neopixel .ino file and sample script https://api.wearscript.com/#/gist/9390329/glass.html complex patterns can be programmed and executed on the Arduino including loops.
32 changes: 16 additions & 16 deletions bluetooth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Keyboard -> Glass

By connecting a BT keyboard to Glass you can control the timeline and use the keypresses inside WearScript like you would in a normal webpage. Keyboards like this http://www.amazon.com/dp/B005C6CVAE/ work well with Glass. First we have to install the Settings.apk so that we can access the pairing options. Install the Settings.apk from here http://www.glassxe.com/2013/05/23/settings-apk-and-launcher2-apk-from-the-hacking-glass-session-at-google-io/ and start the settings using

.. code-block:: guess
.. code-block:: bash
adb am start -a android.intent.action.MAIN -n com.android.settings/.Settings
Expand All @@ -26,7 +26,7 @@ Bluetooth module: http://www.amazon.com/dp/B0093XAV4U

Arduino code. Make sure to plug the RX from BT into TX of arduino which is pin 2 below.

.. code-block:: guess
.. code-block:: c
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2); // RX, TX
Expand All @@ -39,29 +39,29 @@ Arduino code. Make sure to plug the RX from BT into TX of arduino which is pin
void loop() {
if (mySerial.available())
Serial.write(mySerial.read());
Serial.write(mySerial.read());
if (Serial.available()) {
delay(10); // HACK
mySerial.write(Serial.read());
delay(10); // HACK
mySerial.write(Serial.read());
}
}
.. code-block:: guess
.. code-block:: html

<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', function () {
WS.bluetoothWrite('20:13:12:05:04:11', 'bluetooth message from glass to arduino');
WS.bluetoothRead('20:13:12:05:04:11', function (c) {
WS.log('BT:' + c)
});
WS.bluetoothList(function (devices) {
WS.log(JSON.stringify(devices));
});
});
if (WS.scriptVersion(1)) return;
WS.serverConnect('{{WSUrl}}', function () {
WS.bluetoothWrite('20:13:12:05:04:11', 'bluetooth message from glass to arduino');
WS.bluetoothRead('20:13:12:05:04:11', function (c) {
WS.log('BT:' + c)
});
WS.bluetoothList(function (devices) {
WS.log(JSON.stringify(devices));
});
});
}
window.onload = main;
</script>
Expand Down
73 changes: 11 additions & 62 deletions camera.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,43 @@ Camera
cameraOn(double imagePeriod, [int maxHeight, int maxWidth, Function callback]) : void
Continuously capture camera frames. If a callback is specified it is given the data base64 encoded.

.. code-block:: guess
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<img width="640" height="360" id="image" \>
<script>
function main() {
if (WS.scriptVersion(1)) return;
.. code-block:: javascript
WS.cameraOn(.5, 180, 320, function (x) {
document.getElementById('image').setAttribute('src', 'data:image/jpg;base64,' + x);
});
}
window.onload = main;
</script></body></html>
cameraOff() : void
Turns off camera

.. code-block:: guess
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<img width="640" height="360" id="image" \>
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.cameraOn(.5, 180, 320, function (x) {
document.getElementById('image').setAttribute('src', 'data:image/jpg;base64,' + x);
});
setTimeout(function () {
WS.cameraOff();
}, 5000);
}
window.onload = main;
</script></body></html>
.. code-block:: javascript
setTimeout(function () {WS.cameraOff();}, 5000);
cameraPhoto([Function callback]) : void
Take a picture and save it to the SD card and callback to `callback(String path)`. Can be used as src attribute for an image.


.. code-block:: guess
.. code-block:: javascript
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<img width="640" height="360" id="image" \>
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.cameraPhoto(function (x) {
document.getElementById('image').setAttribute('src', 'file://' + x);
});
}
window.onload = main;
</script></body></html>
cameraPhotoData([Function callback]) : void
Take a picture and callback to `callback(String imageb64)` with a base64 encoded jpeg.

.. code-block:: guess
.. code-block:: javascript
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<img width="640" height="360" id="image" \>
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.cameraPhotoData(function (x) {
document.getElementById('image').setAttribute('src', 'data:image/jpg;base64,' + x);
});
}
window.onload = main;
</script></body></html>
cameraVideo([Function callback]) : void
Record a video and save to the SD card.

.. code-block:: guess
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.cameraVideo(function (x) {
WS.log(x);
});
}
window.onload = main;
</script></body></html>
.. code-block:: javascript
WS.cameraVideo(function (x) {
WS.log(x);
});
24 changes: 22 additions & 2 deletions cards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ GDK Cards
=========
WearScript uses an abstraction called a CardTree that allows for a hierarchy of cards where a node in the tree can optionally have either a menu or another set of cards beneath it and every card can have a tap/select callback. The syntax is overloaded to make common functionality concise.

Examples
--------
The following displays a GDK card (consists of a body and footer)

.. code-block:: javascript
Expand Down Expand Up @@ -57,11 +59,11 @@ A subtree of cards is added by creating another set of cards and placing it as t
WS.cardTree(tree);
WS.displayCardTree();
The GDK cards are limited in the layouts provided and the Mirror API provides more formatting options with HTML. We've ported much of this functionality without using Mirror so that more complex layouts (e.g., lists) can be used. Currently unsupported features include auto-paginate and auto-size. The syntax is that you create a <script> tag with the content (same format as Mirror accepts), then pass the ID of that tag to tree.addHTML(id) which can take all of the same options previously described (e.g., callbacks, menus, subtrees). Both card types can co-exist in the CardTree as illustrated below. For several examples of HTML cards checkout https://api.picar.us/wearscriptdev/#/gist/9477514/glass.html
The GDK cards are limited in the layouts provided and the Mirror API provides more formatting options with HTML. We've ported much of this functionality without using Mirror so that more complex layouts (e.g., lists) can be used. Currently unsupported features include auto-paginate and auto-size. The syntax is that you create a <script> tag with the content (same format as Mirror accepts), then pass the ID of that tag to tree.addHTML(id) which can take all of the same options previously described (e.g., callbacks, menus, subtrees). Both card types can co-exist in the CardTree as illustrated below. For several examples of HTML cards checkout https://api.wearscript.com/#/gist/9477514/glass.html

First put the html in a script tag

.. code-block:: guess
.. code-block:: html

<script type="text/html" id="tpl_card0">
<article>
Expand Down Expand Up @@ -89,3 +91,21 @@ Then refer to it in javascript using WS.addHTML
tree.add('Body 1', 'Footer 1');
WS.cardTree(tree);
WS.displayCardTree();
API
----

WS.Cards() : Tree
Creates an empty card tree configuration

Tree.add(String body, String footer, [Function selected, Function tapped], [String menuTitle, Function menuAction]..) : Tree
Add a card to a tree. Can be chained for fluency

Tree.addHtml(String htmlID, [Function selected, Function tapped], [String menuTitle, Function menuAction]..) : Tree
Add a full HTML card to the tree. Can be chained for fluency.

WS.cardTree(tree) : void
Generates the full card tree in native memory.

WS.displayCardTree() : void
Shows the CardScrollView
7 changes: 7 additions & 0 deletions conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

import sys, os

on_rtd = os.environ.get('READTHEDOCS', None) == 'True'

if not on_rtd: # only import and set the theme if we're building docs locally
import sphinx_rtd_theme
html_theme = 'sphinx_rtd_theme'
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

# -- General configuration -----------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be extensions
Expand Down
13 changes: 6 additions & 7 deletions input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ gestureCallback(String event, Function callback) : void
Register to get gesture events using the string of one of the events below (following GDK names, see below).

Event Types
Each of these follows the `parameters provided by the GDK <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector>`_
:onGesture(String gesture): The gestures that can be returned are `listed here <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/Gesture>`_: LONG_PRESS, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT, TAP, THREE_LONG_PRESS, THREE_TAP, TWO_LONG_PRESS, TWO_SWIPE_RIGHT, TWO_SWIPE_UP, TWO_TAP
:onGesture<GESTURE>(): Shorthand for a specific gesture (e.g., onGestureTAP).
:onFingerCountChanged(int previousCount, int currentCount):
:onScroll(float displacement, float delta, float velocity):
:onTwoFingerScroll(float displacement, float delta, float velocity):
:onFingerCountChanged(int previousCount, int currentCount): see `FingerListener <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector.FingerListener#onFingerCountChanged(int, int)>`_ in GDK
:onScroll(float displacement, float delta, float velocity): see `ScrollListener <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector.ScrollListener#onScroll(float, float, float)>`_ in GDK
:onTwoFingerScroll(float displacement, float delta, float velocity): see `TwoFingerScrollListener <https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector.TwoFingerScrollListener#onTwoFingerScroll(float, float, float)>`_ in GDK
:onEyeGesture(String gesture): One of WINK, DOUBLE_WINK, DOUBLE_BLINK, DON, DOFF
:onEyeGesture<GESTURE>: Shorthand for a specific gesture (e.g., onEyeGestureWINK)

Expand Down Expand Up @@ -58,7 +57,7 @@ gestureCallback(String event, Function callback) : void
speechRecognize(String prompt, Function callback) : void
Displays the prompt and calls your callback with the recognized speech as a string

* Callback has parameters of the form function `callback(String recognizedText)`
Callback of the form `function mycallback(String recognizedText)`

.. code-block:: javascript
Expand All @@ -70,8 +69,8 @@ qr(Function callback) : void
Open a QR scanner, return scan results via a callback from zxing

Callback of the form `function mycallback(data, format)`
:data(string): The scanned data (e.g., http://wearscript.com) is returned
:format(string): The format of the data (e.g., QR_CODE)
:String data: The scanned data (e.g., http://wearscript.com) is returned
:String format: The format of the data (e.g., QR_CODE)

.. code-block:: javascript
Expand Down
4 changes: 2 additions & 2 deletions myo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ Myo
===
The Myo uses bluetooth-le and can only be connected to Android Kit Kat devices (e.g., Nexus 5). As the SDK is not publicly available you'll need to get the Myo binary of WearScript (currently a private branch) from us. If you are part of the Myo Alpha program we can add you to the repository.

This demonstrates training the Myo, saying out load which gesture is performed. NONE is produced after a gesture is stopped (e.g., a clenched fist will stay FIST until it is released and then will be NONE). It also streams the accelerometer, orientation, and gyro to the sensors tab (see WS.dataLog).
This demonstrates training the Myo, saying out loud which gesture is performed. NONE is produced after a gesture is stopped (e.g., a clenched fist will stay FIST until it is released and then will be NONE). It also streams the accelerometer, orientation, and gyro to the sensors tab (see WS.dataLog).

.. code-block:: guess
.. code-block:: html

<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
Expand Down
8 changes: 4 additions & 4 deletions pubsub.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ Example: Ping/Pong

To start the manager in client mode (i.e., it connects to the Go server) use the following. All messages are sent example_ping <-internet-> go server <-internet-> glass which means you will have higher latency than connecting directly but you can stil use the Playground fully. This is normally recommended for development.

.. code-block:: guess
.. code-block:: bash
python example_ping.py client <client endpoint here>
To start the manager in server mode (e.g., Glass connect directly to this script, bypassing the Go server) use the following. Note that in your script you have to change WS.serverConnect to use your server's ip and port (e.g., ws://localip:localport) which mean you won't get playground connectivity (e.g., no logs, can't resend code) until you stop the script ("Ok Glass" -> "Wear a Script" -> Scroll to Stop). The benefit is that you can get substantially lower latency connecting directly to your computer.

.. code-block:: guess
.. code-block:: bash
python example_ping.py server <server port here>
Expand All @@ -62,7 +62,7 @@ To start the manager in server mode (e.g., Glass connect directly to this script
wearscript.parse(callback, argparse.ArgumentParser())
.. code-block:: guess
.. code-block:: python
// Go: Server
package main
Expand Down Expand Up @@ -126,7 +126,7 @@ Example: Image/Sensor Stream
WS.serverConnect('{{WSUrl}}', function () {
WS.sensorOn('accelerometer', .25);
WS.cameraOn(1);
WS.dataLog(false, true, .15);
WS.dataLog(false, true, .15);
});
}
window.onload = main;
Expand Down
26 changes: 14 additions & 12 deletions sensors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ Sensor Types
------------
Sensors have unique names and integer types that are used internally and can be used as WS.sensor('light') which returns 5. The standard Android sensor types are positive and custom types are given negative numbers.

* pupil: -2
* gps: -1
* accelerometer: 1
* magneticField: 2
* orientation: 3
* gyroscope: 4
* light: 5
* gravity: 9
* linearAcceleration: 10
* rotationVector: 11


=================== =======
Type Value
=================== =======
pupil -2
gps -1
accelerometer 1
magneticField 2
orientation 3
gyroscope 4
light 5
gravity 9
linearAcceleration 10
rotationVector 11
=================== =======
Loading

0 comments on commit 647f2de

Please sign in to comment.