From 8157c05cddab5b824e4d265559f9e6da95e12c29 Mon Sep 17 00:00:00 2001 From: Timothy Harvey Date: Tue, 24 Jul 2018 14:23:32 -0500 Subject: [PATCH 1/2] Fixed small things on grove and web-socket and redid webusb, which I somehow missed on the first go around. Signed-off-by: Timothy Harvey --- docs/grove_lcd.md | 1 - docs/web-socket.md | 11 ++++++++-- docs/webusb.md | 51 ++++++++++++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/docs/grove_lcd.md b/docs/grove_lcd.md index ed7c611f6..4c865ab73 100644 --- a/docs/grove_lcd.md +++ b/docs/grove_lcd.md @@ -15,7 +15,6 @@ ZJS API for Grove LCD * [groveLCDDevice.getFunction()](#grovelcddevicegetfunction) * [groveLCDDevice.setDisplayState(config)](#grovelcddevicesetdisplaystateconfig) * [GroveLCDDevice.getDisplayState()](#grovelcddevicegetdisplaystate) - * [Sample Apps](#sample-apps) Introduction diff --git a/docs/web-socket.md b/docs/web-socket.md index 806a7d908..479f29be5 100644 --- a/docs/web-socket.md +++ b/docs/web-socket.md @@ -36,7 +36,7 @@ explaining [ZJS WebIDL conventions](Notes_on_WebIDL.md). // var ws = require('ws'); [ReturnFromRequire] interface WebSocket { - WebSocketServer Server(object options); + WebSocketServer Server(OptionsObject options); };

[ExternalInterface=(EventEmitter)] interface WebSocketServer: EventEmitter{};

[ExternalInterface=(Buffer),] @@ -44,7 +44,14 @@ interface WebSocketConnection: EventEmitter { void send(Buffer data, boolean mask); void ping(Buffer data, boolean mask); void pong(Buffer data, boolean mask); -}; +};

dictionary OptionsObject { + double port; // Port to bind to + boolean backlog; // Max number of concurrent connections + boolean clientTracking; // enable client tracking + double maxPayload; // set the max payload bytes per message + string acceptHandler; // handler to call to accept/deny connections +}; + WebSocket API diff --git a/docs/webusb.md b/docs/webusb.md index e285e26f7..6a74fc947 100644 --- a/docs/webusb.md +++ b/docs/webusb.md @@ -2,8 +2,10 @@ Zephyr.js API for WebUSB ======================== * [Introduction](#introduction) -* [Class: WebUSB](#class-webusb) -* [API Documentation](#api-documentation) +* [Class: WebUSB](#webusb-api) + * [webusb.setURL(url)](#webusbseturlurl) + * [webusb.write(buffer)](#webusbwritebuffer) + * [Event: 'read'](#event-read) * [Sample Apps](#sample-apps) Introduction @@ -19,8 +21,33 @@ When you connect your device to a Linux PC or Mac with Chrome >= 60 running, it will give a notification that the device would like you to visit the URL you've set. (Windows currently prevents this from working, I believe.) -API Documentation ------------------ +Web IDL +------- +This IDL provides an overview of the interface; see below for documentation of +specific API functions. We also have a short document explaining [ZJS WebIDL conventions](Notes_on_WebIDL.md). +

+ Click to show/hide WebIDL +
+// require returns a webusb object
+// var webusb = require('webusb');

[ReturnFromRequire, ExternalInterface=(Buffer)] +interface webusb { + void setURL(string url); + void write(Buffer buf); +}; +

+
+ +webusb API +---------- + +### webusb.setURL(url) +* `url` *string* Should begin with "https://" for Chrome to accept it +and display a notification. Other URLs are valid in terms of the protocol but +will have no user-visible effect in Chrome. + +### webusb.write(buffer) +* `write` *Buffer* Writes the data in `buffer` to the WebUSB TX line. By default, at most 511 bytes can be pending at one time, so that is the maximum write size, assuming all previous data has already been flushed out. An error will be thrown on overflow. + ### Event: 'read' * `Buffer` `data` @@ -28,22 +55,6 @@ API Documentation Emitted when data is received on the WebUSB RX line. The `data` parameter is a `Buffer` with the received data. -### WebUSB.setURL - -`void setURL(string url);` - -The `url` string should begin with "https://" in order for Chrome to accept it -and display a notification. Other URLs are valid in terms of the protocol but -will have no user-visible effect in Chrome. - -### WebUSB.write - -`void write(Buffer buffer);` - -Writes the data in `buffer` to the WebUSB TX line. By default at most 511 bytes -can be pending at one time, so that is the maximum write size, assuming all -previous data had already been flushed out. An error will be thrown on overflow. - Sample Apps ----------- * [WebUSB sample](../samples/WebUSB.js) From e37996e34f0097652a0659e1c3e3a9f5f555c771 Mon Sep 17 00:00:00 2001 From: Timothy Harvey Date: Tue, 12 Feb 2019 10:47:54 -0600 Subject: [PATCH 2/2] Fixed WebIDL inconsistencies as follows: aio.md and ble.md: each had their own version of ReadCallback, so they couldn't be compiled together; we changed the types to include the package name to uniquely identify each one buffer.md: Javascript objects have a method called toString, so changed the operation name to to_string; changed "Uint8" to the WebIDL type "octet"; set a default value for the to_string operation and specified it as "optional" to match the corresponding zephry code gpio.md and sensors.md: like aio/ble, these each declared their own version of "ChangeCallback", so we prepended each instance with its package name pme.md: set JSON to all caps, because that's the way that WebIDL defines it Signed-off-by: Timothy Harvey --- docs/aio.md | 12 ++++++------ docs/ble.md | 8 ++++---- docs/buffer.md | 8 ++++---- docs/gpio.md | 6 +++--- docs/pme.md | 4 ++-- docs/sensors.md | 20 ++++++++++---------- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/aio.md b/docs/aio.md index bdd1d153d..65f9658cd 100644 --- a/docs/aio.md +++ b/docs/aio.md @@ -45,10 +45,10 @@ interface AIO { (unsigned long or string) pin; };

interface AIOPin { unsigned long read(); - void readAsync(ReadCallback callback); // TODO: change to return a promise - void on(string eventType, ReadCallback callback); + void readAsync(aio_ReadCallback callback); // TODO: change to return a promise + void on(string eventType, aio_ReadCallback callback); void close(); -};

callback ReadCallback = void (unsigned long value); +};

callback aio_ReadCallback = void (unsigned long value); AIO API @@ -70,10 +70,10 @@ AIOPin API * Returns: the latest reading from the pin (an unsigned integer). Blocks until it gets the result. ### pin.readAsync(callback) -* 'callback' *ReadCallback* User-provided callback function that takes +* 'callback' *aio_ReadCallback* User-provided callback function that takes a single unsigned integer and has no return value. -Pass a function for `ReadCallback` that will be called later when the result is +Pass a function for `aio_ReadCallback` that will be called later when the result is obtained. *WARNING: Making an async call like this allocates some memory while the call @@ -89,7 +89,7 @@ returns a promise.* ### pin.on(eventType, callback) * 'eventType' *string* Type of event; currently, the only supported type is "change". -* 'callback' *ReadCallback* User-provided callback function that takes +* 'callback' *aio_ReadCallback* User-provided callback function that takes a single, unsigned integer and has no return value; can be null. The callback function is called any time the analog voltage changes. (At the moment, diff --git a/docs/ble.md b/docs/ble.md index 5908562d4..a27d10faf 100644 --- a/docs/ble.md +++ b/docs/ble.md @@ -65,19 +65,19 @@ dictionary PrimaryServiceInit { string uuid; sequence < string > properties; // 'read', 'write', 'notify' sequence < DescriptorInit > descriptors; - ReadCallback onReadRequest; // optional + ble_ReadCallback onReadRequest; // optional WriteCallback onWriteRequest; // optional SubscribeCallback onSubscribe; // optional UnsubscribeCallback onUnsubscribe; // optional NotifyCallback onNotify; // optional };

interface Characteristic { - attribute ReadCallback onReadRequest; + attribute ble_ReadCallback onReadRequest; attribute WriteCallback onWriteRequest; attribute SubscribeCallback onSubscribe; attribute UnsubscribeCallback onUnsubscribe; attribute NotifyCallback onNotify; attribute CharacteristicResult response; -};

callback ReadCallback = void (unsigned long offset, +};

callback ble_ReadCallback = void (unsigned long offset, FulfillReadCallback fulfillReadCallback); [ExternalInterface=(Buffer)] callback WriteCallback = void (Buffer data, unsigned long offset, @@ -210,7 +210,7 @@ This object has 3 required fields: 3. `descriptors` *array of [Descriptors](#descriptor)* It may also contain these optional callback fields: -1. `onReadRequest` *ReadCallback* +1. `onReadRequest` *ble_ReadCallback* * Called when the client is requesting to read data from the characteristic. * See below for common argument definitions 2. `onWriteRequest` *WriteCallback* diff --git a/docs/buffer.md b/docs/buffer.md index 56b8b25e3..5b324b588 100644 --- a/docs/buffer.md +++ b/docs/buffer.md @@ -10,7 +10,7 @@ ZJS API for Buffer * [buf.copy(target[, targetStart, [sourceStart[, sourceEnd]]])](#bufcopytarget-targetstart-sourcestart-sourceend) * [buf.fill(value[, offset[, end[, encoding]]])](#buffillvalue-offset-end-encoding) * [buf.readUInt*(offset)](#bufreaduint-family) - * [buf.toString([encoding])](#buftostringencoding) + * [buf.to_string([encoding])](#bufto_stringencoding) * [buf.write(string[, offset[, length[, encoding]]])](#bufwritestring-offset-length-encoding) * [buf.writeUInt*(value, offset)](#bufwriteuint-family) * [Sample Apps](#sample-apps) @@ -29,7 +29,7 @@ specific API functions. We have a short document explaining [ZJS WebIDL convent

Click to show/hide WebIDL
-[ Constructor(sequence < Uint8 > initialValues),
+[ Constructor(sequence < octet > initialValues),
   Constructor(unsigned long size),
   Constructor(ByteString initialString), ]
 interface Buffer {
@@ -46,7 +46,7 @@ interface Buffer {
     short readUInt16LE(optional unsigned long offset = 0);
     long readUInt32BE(optional unsigned long offset = 0);
     long readUInt32LE(optional unsigned long offset = 0);
-    string toString(string encoding);
+    string to_string(optional string encoding = "utf8");
     long write(string value, optional long offset = 0,
                              optional long length = 0,
                              optional string encoding = "utf8");
@@ -121,7 +121,7 @@ little-endian (lowest byte first) integer depending on the function version.
 The `offset` should be provided but will be treated as 0 if not given. Returns
 an error if the buffer is not big enough.
 
-### buf.toString([encoding])
+### buf.to_string([encoding])
 * `encoding` *string* Encoding to use.
 * Returns: *string*
 
diff --git a/docs/gpio.md b/docs/gpio.md
index 5e9d9769a..c4feff37b 100644
--- a/docs/gpio.md
+++ b/docs/gpio.md
@@ -44,8 +44,8 @@ dictionary GPIOInit {
     long read();
     void write(long value);
     void close();
-    attribute ChangeCallback onchange;
-};

callback ChangeCallback = void (GPIOEvent event);

dictionary GPIOEvent { + attribute gpio_ChangeCallback onchange; +};

callback gpio_ChangeCallback = void (GPIOEvent event);

dictionary GPIOEvent { long value; };

enum GPIOMode { "out", "in" }; enum GPIOEdge { "none", "rising", "falling", "any" }; @@ -112,7 +112,7 @@ writing anymore. ### pin.onchange -* `onchange` *ChangeCallback* +* `onchange` *gpio_ChangeCallback* Set this attribute to a function that will receive events whenever the pin changes according to the edge condition specified at pin initialization. The diff --git a/docs/pme.md b/docs/pme.md index 148e95099..12264b38e 100644 --- a/docs/pme.md +++ b/docs/pme.md @@ -70,8 +70,8 @@ interface PME { void setClassifierMode(unsigned short mode); unsigned short getDistanceMode(); void setDistanceMode(unsigned short mode); - sequence < Json > saveNeurons(); - void restoreNeurons(sequence < Json > objects); + sequence < JSON > saveNeurons(); + void restoreNeurons(sequence < JSON > objects);

attribute unsigned short RBF_MODE; // RBF classification mode attribute unsigned short KNN_MODE; // KNN classification mode diff --git a/docs/sensors.md b/docs/sensors.md index 5f6d0f0d6..9baed6044 100644 --- a/docs/sensors.md +++ b/docs/sensors.md @@ -37,21 +37,21 @@ explaining [ZJS WebIDL conventions](Notes_on_WebIDL.md).

Click to show WebIDL
 interface Sensor {
-    readonly attribute boolean activated;   // whether the sensor is activated or not
-    readonly attribute boolean hasReading;  // whether the sensor has readings available
-    readonly attribute double timestamp;    // timestamp of the latest reading in milliseconds
-    attribute double frequency;             // sampling frequency in hertz
-    void start();                           // starts the sensor
-    void stop();                            // stops the sensor
-    attribute ChangeCallback onreading;     // callback handler for change events
-    attribute ActivateCallback onactivate;  // callback handler for activate events
-    attribute ErrorCallback onerror;        // callback handler for error events
+    readonly attribute boolean activated;      // whether the sensor is activated or not
+    readonly attribute boolean hasReading;     // whether the sensor has readings available
+    readonly attribute double timestamp;       // timestamp of the latest reading in milliseconds
+    attribute double frequency;                // sampling frequency in hertz
+    void start();                              // starts the sensor
+    void stop();                               // stops the sensor
+    attribute sensor_ChangeCallback onreading; // callback handler for change events
+    attribute ActivateCallback onactivate;     // callback handler for activate events
+    attribute ErrorCallback onerror;           // callback handler for error events
 };

dictionary SensorOptions { double frequency; // desired frequency, default is 20 if unset };

interface SensorErrorEvent { attribute Error error; -};

callback ChangeCallback = void(); +};

callback sensor_ChangeCallback = void(); callback ActivateCallback = void(); callback ErrorCallback = void(SensorErrorEvent error);

[Constructor(optional AccelerometerOptions accelerometerOptions)] interface Accelerometer : Sensor {