Skip to content

Commit 88b8f47

Browse files
committed
Improve API docs
1 parent dc20020 commit 88b8f47

File tree

5 files changed

+115
-3
lines changed

5 files changed

+115
-3
lines changed

docs/api_camera.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
JS API: Camera Integration
2+
==========================
3+
4+
.. code-block:: html
5+
6+
<script src="/networktables/camera.js"></script>
7+
8+
.. note:: These functions require `jQuery <http://jquery.com/>`_ to be
9+
loaded first!
10+
11+
.. js:function:: loadCameraOnConnect(args)
12+
13+
This useful helper function will create an img or svg element inside of the
14+
div element that you specify. The image will only be connected when a
15+
successful NetworkTables connection is detected, to prevent timeout issues.
16+
Additionally, this function will attempt to verify that the webcam server is
17+
actually up and running before creating the image.
18+
19+
You should provide an object with an object that can have the following
20+
attributes:
21+
22+
:param container: Where to draw things
23+
:param proto: optional, defaults to http://
24+
:param host: optional, if null will use robot's autodetected IP
25+
:param port: optional, webserver port
26+
:param image_url: path to mjpg stream
27+
:param data_url: a file or page that must exist on the webcam server
28+
:param wait_img: optional image to show when not connected
29+
:param error_img: optional image to show when not connected
30+
:param attrs: optional attributes to set on svg or img element
31+
:param nosim: if true, connect to the webcam in simulation mode
32+
33+
For example, to connect to mjpg-streamer on the RoboRIO:
34+
35+
.. code-block:: javascript
36+
37+
loadCameraOnConnect({
38+
container: '#my_div_element',
39+
port: 5800,
40+
image_url: '/?action=stream',
41+
data_url: '/program.json',
42+
attrs: {
43+
width: 640,
44+
height: 480
45+
}
46+
});
47+
48+
49+
.. note:: This has only been tested with mjpg-streamer, but should work for
50+
other HTTP webcams as well.

docs/api_js.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
JavaScript API
2-
==============
1+
JS API: NetworkTables
2+
=====================
3+
4+
To use these functions, add this to your HTML page:
5+
6+
.. code-block:: html
7+
8+
<script src="/networktables/networktables.js"></script>
9+
10+
**Note**:
311

412
It's very important to note that the Javascript NetworkTables API currently
513
has no concept of a table or subtable. When referring to keys when accessing

docs/api_util.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
JS API: Utilities
2+
=================
3+
4+
To use these functions, add this to your HTML page:
5+
6+
.. code-block:: html
7+
8+
<script src="/networktables/utils.js"></script>
9+
10+
.. note:: These functions require `jQuery <http://jquery.com/>`_ and
11+
`D3 <https://d3js.org/>`_ to be loaded first!
12+
13+
The functions in this file are still experimental in nature, and as we
14+
expand the number of functions in this file it is expected that the API
15+
will change.
16+
17+
SendableChooser
18+
---------------
19+
20+
.. js:function:: attachSelectToSendableChooser(html_id, nt_key)
21+
22+
Given the id of an HTML ``<select>`` element and the key name of a SendableChooser
23+
object setup in networktables, this will sync the select combo box with the
24+
contents of the SendableChooser, and you will be able to select an object
25+
using the select element.
26+
27+
:param html_id: An ID of an HTML select element
28+
:param nt_key: The name of the NetworkTables key that the SendableChooser
29+
is associated with
30+
31+
See the WPILib documentation for information on how to use SendableChooser
32+
in your robot's program.
33+
34+
.. js:function:: updateSelectWithChooser(html_id, nt_key)
35+
36+
This function is designed to be used from the onValueChanged callback
37+
whenever values from a SendableChooser change, but you probably should
38+
prefer to use attachSelectToSendableChooser instead.
39+
40+
See attachSelectToSendableChooser documentation.
41+
42+
Indicators
43+
----------
44+
45+
.. js:function:: attachRobotConnectionIndicator(html_id[, size, stroke_width])
46+
47+
Creates a circle SVG that turns red when robot is not connected, green when
48+
it is connected.
49+
50+
:param html_id: ID to insert svg into
51+
:param size: Size of circle
52+
:param stroke_width: Border of circle

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
:maxdepth: 4
66

77
api_js
8+
api_util
9+
api_camera
810
troubleshooting
911

1012
Indices and tables

pynetworktables2js/js/camera.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function $s(elem) {
5252
5353
5454
.. note:: This has only been tested with mjpg-streamer, but should work for
55-
other webcams as well.
55+
other HTTP webcams as well.
5656
*/
5757
function loadCameraOnConnect(args) {
5858
/*

0 commit comments

Comments
 (0)