communicate with devices beyond a translator
webmonome
is a little library designed to enable communication with monome devices directly from the web browser (bypassing serialosc
). while serialosc
is the best choice 99% of the time, i thought that it might be nice to enable the creation of monome apps that required zero install/config.
<script src="https://unpkg.com/webmonome@alpha"></script>
const monome = new WebMonome();
const btn = document.createElement('button');
btn.innerHTML = 'connect';
btn.addEventListener('click', () => {
monome.connect();
});
document.body.appendChild(btn);
const keydown = e => {
monome.gridLed(e.x, e.y, true);
};
const keyup = e => {
monome.gridLed(e.x, e.y);
};
monome.on('gridKeyDown', keydown);
monome.on('gridKeyUp', keyup);
npm install webmonome@alpha
import WebMonome from 'webmonome';
const monome = new WebMonome();
const btn = document.createElement('button');
btn.innerHTML = 'connect';
btn.addEventListener('click', () => {
monome.connect();
});
document.body.appendChild(btn);
const keydown = e => {
monome.gridLed(e.x, e.y, true);
};
const keyup = e => {
monome.gridLed(e.x, e.y);
};
monome.on('gridKeyDown', keydown);
monome.on('gridKeyUp', keyup);
webmonome
relies on the WebUSB
api. information on browser support for the WebUSB
api can be found over at caniuse.
webmonome
is currently very bare bones (as i'm still working out the kinks with WebUSB and the monome serial protocol), but there is enough there to perform most grid operations.
-
initialize WebUSB and connect to device:
monome.connect()
system responses come in the form of events (see below), but this may be changed to include a callback or promise for ergonomics.
-
request device information:
monome.query()
-
request device id:
monome.getId()
-
request grid size:
monome.getGridSize()
-
set a single LED on or off:
monome.gridLed(xCoord, yCoord, on)
xCoord
: integeryCoord
: integeron
: boolean
-
set all LEDs on or off:
monome.gridLedAll(on)
on
: boolean
-
set on/off state for column of LEDs:
monome.gridLedCol(xOffset, yOffset, state)
xOffset
: integeryOffset
: integer (floored to multiples of 8 by the device firmware)state
: array of up to 8 0/1 bits
-
set on/off state for row of LEDs:
monome.gridLedRow(xOffset, yOffset, state)
xOffset
: integer (floored to multiples of 8 by the device firmware)yOffset
: integerstate
: array of up to 8 0/1 bits
-
set on/off state for an 8x8 quad of LEDs:
monome.gridLedMap(xOffset, yOffset, state)
xOffset
: integeryOffset
: integerstate
: array of up to 64 0/1 bits -
set system wide grid intensity:
monome.gridLedIntensity(intensity)
intensity
: integer (0-15)
-
set single LED to specific level:
monome.gridLedLevel(xCoord, yCoord, level)
xCoord
: integeryCoord
: integerlevel
: integer (0-15)
-
set all LEDs to specific level:
monome.gridLedLevelAll(level)
level
: integer (0-15)
-
set level state for column of LEDs:
monome.gridLedLevelCol(num: xOffset, num: yOffset, []num: state)
xOffset
: integeryOffset
: integer (floored to multiples of 8 by the device firmware)state
: array of up to 8 integers (0-15)
-
set level state for row of LEDs:
monome.gridLedLevelRow(num: xOffset, num: yOffset, []num: state)
xOffset
: integer (floored to multiples of 8 by the device firmware)yOffset
: integerstate
: array of up to 8 integers (0-15)
-
set level state for an 8x8 quad of LEDs:
monome.gridLedLevelMap(num: xOffset, num: yOffset, []num: state)
xOffset
: integeryOffset
: integerstate
: array of up to 64 integers (0-15)
-
subscribe to events:
monome.on(eventName, callback)
eventName
: stringcallback
: function
-
unsubscribe from events:
monome.off(eventName, callback)
eventName
: stringcallback
: function
query
{type: num, count: num}
getId
str
getGridSize
{x: num, y: num}
gridKeyDown
{x: num, y: num}
gridKeyUp
{x: num, y: num}
- remaining /sys/ commands
- grid offsets
- addr scan
- firmware version
- arc ops
- add any additional ops in the monome serial protocol (reaching something similar to libmonome)