- Controller
- .enable() ⇒
Promise
- .getPairedDevice() ⇒
Promise
- .autoConnect() ⇒
Promise
- .connect() ⇒
Promise
- .send(data) ⇒
Promise
- .updateUniverse(channel, value)
- .disconnect() ⇒
Promise
- .enable() ⇒
The controller is creating a connection to the USB device (Arduino) to send data over WebUSB.
By using the default args
you will only see the following Arduino in the user prompt:
- Arduino Leonardo
- Arduino Leonardo ETH
- Seeeduino Lite
Param | Type | Description |
---|---|---|
args | Object |
Arguments to configure the controller |
args.filters | Array.<Object> |
List of devices that are whitelisted when opening the user prompt to select an Arduino |
args.device | Object |
The selected Arduino to use as the DMX512 controller |
args.universe | Array.<number> |
Holds all the values for each channel of the DMX512 universe |
Example
import Controller from 'webusb-dmx512-controller/controller.js'
// Create a new controller using the default properties
const controller = new Controller()
Enable WebUSB and save the selected Arduino into controller.device
Note: This function has to be triggered by a user gesture
Example
controller.enable().then(() => {
// Create a connection to the selected Arduino
controller.connect().then(() => {
// Successfully created a connection
})
})
.catch(error => {
// No Arduino was selected by the user
})
Get a USB device that was already paired with the browser.
Automatically connect to a USB device that was already paired with the Browser and save it into controller.device
Example
controller.autoConnect()
.then(() => {
// Connected to already paired Arduino
})
.catch(error => {
// Nothing found or found paired Arduino, but it's not connected to computer
})
Open a connection to the selected USB device and tell the device that we are ready to send data to it.
Example
controller.connect().then(() => {
// Successfully created a connection to the selected Arduino
})
Send data to the USB device to update the DMX512 universe
Param | Type | Description |
---|---|---|
data | Array |
List containing all channels that should be updated in the universe |
Example
controller.send([255, 0, 0])
Update the channel
(s) of the DMX512 universe with the provided value
Param | Type | Description |
---|---|---|
channel | number |
The channel to update |
value | number | Array.<number> |
The value to update the channel, supporting two different modes: single (= number ) & multi (= Array ) |
Example (Update a single channel)
// Update channel #1
controller.updateUniverse(1, 255)
Example (Update multiple channels starting with channel)
// Update channel #5 with 255, #6 with 0 & #7 with 20
controller.updateUniverse(5, [255, 0, 20])
Disconnect from the USB device
Note: The device is still paired to the browser!
Example
controller.disconnect().then(() => {
// Destroyed connection to USB device, but USB device is still paired with the browser
})