@@ -3,7 +3,13 @@ ZJS API for Analog I/O (AIO)
33
44* [ Introduction] ( #introduction )
55* [ 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 )
713* [ Sample Apps] ( #sample-apps )
814
915Introduction
@@ -23,84 +29,77 @@ not have support for this.
2329
2430Web IDL
2531-------
26- This IDL provides an overview of the interface; see below for documentation of
27- specific API functions.
2832
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 ) .
3236
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]
3442interface AIO {
3543 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 {
4447 unsigned long read();
4548 void readAsync(ReadCallback callback); // TODO: change to return a promise
4649 void on(string eventType, ReadCallback callback);
4750 void close();
48- };
51+ };<p >callback ReadCallback = void (unsigned long value);
52+ </pre > </details >
4953
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.
5861
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
6063number for your device or use the board support module such as
6164[ Arduino 101] ( ./boards/arduino_101.md ) or [ K64F] ( ./boards/frdm_k64f.md ) to
6265specify a named pin.
6366
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.
6571
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.
6775
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
7777obtained.
7878
7979* 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
8182eventually 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
8384any given time.*
8485
8586* NOTE: This function will probably be replaced with a version that instead
8687returns a promise.*
8788
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.
9194
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,
9596it actually gets called periodically even when it hasn't changed.) When null is
9697passed for the change event, the previously registered callback will be
9798discarded and no longer called.
9899
99- ### AIOPin.close
100-
101- ` void close(); `
100+ ### pin.close()
102101
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
104103longer be called.
105104
106105Sample Apps
0 commit comments