@@ -3,7 +3,13 @@ ZJS API for Analog I/O (AIO)
3
3
4
4
* [ Introduction] ( #introduction )
5
5
* [ Web IDL] ( #web-idl )
6
- * [ API Documentation] ( #api-documentation )
6
+ * [ Class: AIO] ( #aio-api )
7
+ * [ aio.open(AIOInit)] ( #aioopenaioinit )
8
+ * [ Class: AIOPin] ( #aiopin-api )
9
+ * [ pin.read()] ( #pinread )
10
+ * [ pin.readAsync(ReadCallback)] ( #pinreadasyncreadcallback )
11
+ * [ pin.on(eventType, ReadCallback)] ( #pinoneventtype-readcallback )
12
+ * [ pin.close()] ( #pinclose )
7
13
* [ Sample Apps] ( #sample-apps )
8
14
9
15
Introduction
@@ -23,84 +29,77 @@ not have support for this.
23
29
24
30
Web IDL
25
31
-------
26
- This IDL provides an overview of the interface; see below for documentation of
27
- specific API functions.
28
32
29
- ``` javascript
30
- // require returns an AIO object
31
- // var aio = require('aio');
33
+ This IDL provides an overview of the interface; see below for
34
+ documentation of specific API functions. We have a short document
35
+ explaining [ ZJS WebIDL conventions ] ( Notes_on_WebIDL.md ) .
32
36
33
- [NoInterfaceObject]
37
+ <details >
38
+ <summary >Click to show WebIDL</summary >
39
+ <pre >
40
+ // require returns an AIO object
41
+ // var aio = require('aio');<p >[ReturnFromRequire]
34
42
interface AIO {
35
43
AIOPin open(AIOInit init);
36
- };
37
-
38
- dictionary AIOInit {
39
- unsigned long pin;
40
- };
41
-
42
- [NoInterfaceObject]
43
- interface AIOPin {
44
+ };<p >dictionary AIOInit {
45
+ (unsigned long or string) pin;
46
+ };<p >interface AIOPin {
44
47
unsigned long read();
45
48
void readAsync(ReadCallback callback); // TODO: change to return a promise
46
49
void on(string eventType, ReadCallback callback);
47
50
void close();
48
- };
51
+ };<p >callback ReadCallback = void (unsigned long value);
52
+ </pre > </details >
49
53
50
- callback ReadCallback = void (unsigned long value);
51
- ```
52
-
53
- API Documentation
54
- -----------------
55
- ### AIO.open
56
-
57
- ` AIOPin open(AIOInit init); `
54
+ AIO API
55
+ -------
56
+ ### aio.open(init)
57
+ * 'init' * AIOInit object* The AIOInit object has a single field called "pin"
58
+ that represents the name of the pin (either an integer or a string,
59
+ depending on the board).
60
+ * Returns: an AIOPin object that may be used to read values from the pin.
58
61
59
- The ` init ` object lets you set the pin number. You can either use a raw
62
+ When setting the pin number, you can either use a raw
60
63
number for your device or use the board support module such as
61
64
[ Arduino 101] ( ./boards/arduino_101.md ) or [ K64F] ( ./boards/frdm_k64f.md ) to
62
65
specify a named pin.
63
66
64
- Use the AIOPin object returned to read values from the pin.
67
+ AIOPin API
68
+ ----------
69
+ ### pin.read()
70
+ * Returns: the latest reading from the pin (an unsigned integer). Blocks until it gets the result.
65
71
66
- ### AIOPin.read
72
+ ### pin.readAsync(callback)
73
+ * 'callback' * ReadCallback* User-provided callback function that takes
74
+ a single unsigned integer and has no return value.
67
75
68
- ` unsigned long read(); `
69
-
70
- Returns the latest reading from the pin. Blocks until it gets the result.
71
-
72
- ### AIOPin.readAsync
73
-
74
- ` void readAsync(ReadCallback callback); `
75
-
76
- Pass a function for ` callback ` that will be called later when the result is
76
+ Pass a function for ` ReadCallback ` that will be called later when the result is
77
77
obtained.
78
78
79
79
* WARNING: Making an async call like this allocates some memory while the call
80
- is pending, so if you issue them faster than they are fulfilled, you will
80
+ is pending; if async calls are issued faster than they are fulfilled,
81
+ the system will
81
82
eventually run out of memory - pretty soon on these small devices. So the best
82
- practice would be to make sure you only have a small, fixed number pending at
83
+ practice would be to have only a small, fixed number pending at
83
84
any given time.*
84
85
85
86
* NOTE: This function will probably be replaced with a version that instead
86
87
returns a promise.*
87
88
88
- ### AIOPin.on
89
-
90
- ` void on(string eventType, ReadCallback callback); `
89
+ ### pin.on(eventType, callback)
90
+ * 'eventType' * string* Type of event; currently, the only supported
91
+ type is "change".
92
+ * 'callback' * ReadCallback* User-provided callback function that takes
93
+ a single, unsigned integer and has no return value; can be null.
91
94
92
- Currently, the only supported ` eventType ` is 'change', and ` callback ` should
93
- be either a function or null. When a function is passed for the change event,
94
- the function will be called any time the analog voltage changes. (At the moment,
95
+ The callback function is called any time the analog voltage changes. (At the moment,
95
96
it actually gets called periodically even when it hasn't changed.) When null is
96
97
passed for the change event, the previously registered callback will be
97
98
discarded and no longer called.
98
99
99
- ### AIOPin.close
100
-
101
- ` void close(); `
100
+ ### pin.close()
102
101
103
- Closes the AIOPin. Once it is closed, all event handlers registered will no
102
+ Closes the AIOPin. Once it is closed, all registered event handlers will no
104
103
longer be called.
105
104
106
105
Sample Apps
0 commit comments