node-poweredup/docs/index.html
Nathan Kellenicki 42f34269f2
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Improved scanning in browser, added DualShock 4 browser example
2019-04-04 14:09:04 -07:00

406 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>node-poweredup Index</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">
</head>
<body>
<div class="navbar navbar-default navbar-fixed-top navbar-inverse">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">node-poweredup</a>
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse" id="topNavigation">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html">BoostMoveHub</a></li><li><a href="DuploTrainBase.html">DuploTrainBase</a></li><li><a href="Hub.html">Hub</a></li><li><a href="LPF2Hub.html">LPF2Hub</a></li><li><a href="PoweredUP.html">PoweredUP</a></li><li><a href="PUPHub.html">PUPHub</a></li><li><a href="PUPRemote.html">PUPRemote</a></li><li><a href="WeDo2SmartHub.html">WeDo2SmartHub</a></li>
</ul>
</li>
<li class="dropdown">
<a href="events.list.html" class="dropdown-toggle" data-toggle="dropdown">Events<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="BoostMoveHub.html#event:attach">BoostMoveHub#event:attach</a></li><li><a href="BoostMoveHub.html#event:button">BoostMoveHub#event:button</a></li><li><a href="BoostMoveHub.html#event:color">BoostMoveHub#event:color</a></li><li><a href="BoostMoveHub.html#event:colorAndDistance">BoostMoveHub#event:colorAndDistance</a></li><li><a href="BoostMoveHub.html#event:detach">BoostMoveHub#event:detach</a></li><li><a href="BoostMoveHub.html#event:distance">BoostMoveHub#event:distance</a></li><li><a href="BoostMoveHub.html#event:rotate">BoostMoveHub#event:rotate</a></li><li><a href="BoostMoveHub.html#event:tilt">BoostMoveHub#event:tilt</a></li><li><a href="DuploTrainBase.html#event:color">DuploTrainBase#event:color</a></li><li><a href="DuploTrainBase.html#event:speed">DuploTrainBase#event:speed</a></li><li><a href="Hub.html#event:attach">Hub#event:attach</a></li><li><a href="Hub.html#event:detach">Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:attach">LPF2Hub#event:attach</a></li><li><a href="LPF2Hub.html#event:button">LPF2Hub#event:button</a></li><li><a href="LPF2Hub.html#event:color">LPF2Hub#event:color</a></li><li><a href="LPF2Hub.html#event:colorAndDistance">LPF2Hub#event:colorAndDistance</a></li><li><a href="LPF2Hub.html#event:detach">LPF2Hub#event:detach</a></li><li><a href="LPF2Hub.html#event:distance">LPF2Hub#event:distance</a></li><li><a href="LPF2Hub.html#event:rotate">LPF2Hub#event:rotate</a></li><li><a href="LPF2Hub.html#event:speed">LPF2Hub#event:speed</a></li><li><a href="LPF2Hub.html#event:tilt">LPF2Hub#event:tilt</a></li><li><a href="PoweredUP.html#event:discover">PoweredUP#event:discover</a></li><li><a href="PUPHub.html#event:attach">PUPHub#event:attach</a></li><li><a href="PUPHub.html#event:button">PUPHub#event:button</a></li><li><a href="PUPHub.html#event:color">PUPHub#event:color</a></li><li><a href="PUPHub.html#event:colorAndDistance">PUPHub#event:colorAndDistance</a></li><li><a href="PUPHub.html#event:detach">PUPHub#event:detach</a></li><li><a href="PUPHub.html#event:distance">PUPHub#event:distance</a></li><li><a href="PUPHub.html#event:tilt">PUPHub#event:tilt</a></li><li><a href="PUPRemote.html#event:button">PUPRemote#event:button</a></li><li><a href="PUPRemote.html#event:colorAndDistance">PUPRemote#event:colorAndDistance</a></li><li><a href="WeDo2SmartHub.html#event:attach">WeDo2SmartHub#event:attach</a></li><li><a href="WeDo2SmartHub.html#event:button">WeDo2SmartHub#event:button</a></li><li><a href="WeDo2SmartHub.html#event:color">WeDo2SmartHub#event:color</a></li><li><a href="WeDo2SmartHub.html#event:detach">WeDo2SmartHub#event:detach</a></li><li><a href="WeDo2SmartHub.html#event:distance">WeDo2SmartHub#event:distance</a></li><li><a href="WeDo2SmartHub.html#event:rotate">WeDo2SmartHub#event:rotate</a></li><li><a href="WeDo2SmartHub.html#event:tilt">WeDo2SmartHub#event:tilt</a></li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li><a href="global.html">Global</a></li>
</ul>
</li>
</ul>
<div class="col-sm-3 col-md-3">
<form class="navbar-form" role="search">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
<div class="input-group-btn">
<button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container" id="toc-content">
<div class="row">
<div class="col-md-8">
<div id="main">
<section class="readme-section">
<article><p><a href="https://drone.kellenicki.com/nkellenicki/node-poweredup"><img src="https://drone.kellenicki.com/api/badges/nkellenicki/node-poweredup/status.svg" alt="Drone"></a><br><a href="https://www.npmjs.com/package/node-poweredup"><img src="https://img.shields.io/npm/v/node-poweredup.svg?style=flat" alt="NPM Version"></a></p>
<h1><strong>node-poweredup</strong> - A Javascript module to interface with LEGO Powered UP components.</h1><h3>Introduction</h3><p>LEGO Powered UP is the successor to Power Functions, the system for adding electronics to LEGO models. Powered UP is a collection of ranges - starting with LEGO WeDo 2.0 released in 2016, LEGO Boost released in 2017, and LEGO Powered UP released in 2018. It also includes the 2018 Duplo App-Controlled Train sets.</p>
<p>This library allows communication and control of Powered UP devices and peripherals via Javascript, both from Node.js and from the browser using Web Bluetooth.</p>
<h3>Node.js Installation</h3><p>Node.js v8.0 required.</p>
<pre class="prettyprint source lang-javascript"><code>npm install node-poweredup --save</code></pre><p>node-poweredup uses the Noble BLE library by Sandeep Mistry. On macOS everything should function out of the box. On Linux and Windows there are <a href="https://github.com/noble/noble#prerequisites">certain dependencies which may need installed first</a>.</p>
<p>Note: node-poweredup has been tested on macOS 10.13 and Debian/Raspbian on the Raspberry Pi 3 Model B.</p>
<h3>Compatibility</h3><p>While most Powered UP components and Hubs are compatible with each other, there are exceptions. For example, there is limited backwards compatibility between newer components and the WeDo 2.0 Smart Hub. However WeDo 2.0 components are fully forwards compatible with newer Hubs.</p>
<table>
<thead>
<tr>
<th>Device Name</th>
<th>Product Code</th>
<th>Type</th>
<th>WeDo 2.0 Smart Hub</th>
<th>Boost Move Hub</th>
<th>Powered UP Hub</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<tr>
<td>WeDo 2.0 Tilt Sensor</td>
<td><a href="https://brickset.com/sets/45305-1/">45305</a></td>
<td>Sensor</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
</tr>
<tr>
<td>WeDo 2.0 Motion Sensor</td>
<td><a href="https://brickset.com/sets/45304-1/">45304</a></td>
<td>Sensor</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
</tr>
<tr>
<td>WeDo 2.0 Medium Motor</td>
<td><a href="https://brickset.com/sets/45303-1/">45303</a></td>
<td>Motor</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/45300-1/">45300</a><br /> <a href="https://brickset.com/sets/76112-1/">76112</a></td>
</tr>
<tr>
<td>Boost Color and Distance Sensor</td>
<td><a href="https://brickset.com/sets/88007-1/">88007</a></td>
<td>Sensor</td>
<td><em>Partial</em></td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
</tr>
<tr>
<td>Boost Tacho Motor</td>
<td><a href="https://brickset.com/sets/88008-1/">88008</a></td>
<td>Motor/Sensor</td>
<td><em>Partial</em></td>
<td>Yes</td>
<td><em>Partial</em></td>
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
</tr>
<tr>
<td>Powered UP Train Motor</td>
<td><a href="https://brickset.com/sets/88011-1/">88011</a></td>
<td>Motor</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a></td>
</tr>
<tr>
<td>Powered UP LED Lights</td>
<td><a href="https://brickset.com/sets/88005-1/">88005</a></td>
<td>Light</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td><a href="https://brickset.com/sets/88005-1/">88005</a></td>
</tr>
</tbody>
</table>
<p>In addition, the Hubs themselves have certain built-in features which this library exposes.</p>
<table>
<thead>
<tr>
<th>Hub Name</th>
<th>Product Code</th>
<th>Built-In Features</th>
<th>Availability</th>
</tr>
</thead>
<tbody>
<tr>
<td>WeDo 2.0 Smart hub</td>
<td><a href="https://brickset.com/sets/45301-1/">45301</a></td>
<td>RGB LED<br />Piezo Buzzer<br />Button</td>
<td><a href="https://brickset.com/sets/45300-1/">45300</a></td>
</tr>
<tr>
<td>Boost Move Hub</td>
<td><a href="https://brickset.com/sets/88006-1/">88006</a></td>
<td>RGB LED<br />Tilt Sensor<br />2x Tacho Motors<br />Button</td>
<td><a href="https://brickset.com/sets/17101-1/">17101</a></td>
</tr>
<tr>
<td>Powered UP Hub</td>
<td><a href="https://brickset.com/sets/88009-1/">88009</a></td>
<td>RGB LED<br />Button</td>
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a><br /><a href="https://brickset.com/sets/76112-1/">76112</a></td>
</tr>
<tr>
<td>Powered UP Remote</td>
<td><a href="https://brickset.com/sets/88010-1/">88010</a></td>
<td>RGB LED<br />Left and Right Control Buttons<br />Button</td>
<td><a href="https://brickset.com/sets/60197-1/">60197</a><br /><a href="https://brickset.com/sets/60198-1/">60198</a></td>
</tr>
<tr>
<td>Duplo Train Base</td>
<td>28743</td>
<td>RGB LED/Headlights<br />Speaker<br />Speedometer<br />Motor<br />Color and Distance Sensor<br />Button</td>
<td><a href="https://brickset.com/sets/10874-1/">10874</a><br /><a href="https://brickset.com/sets/10875-1/">10875</a></td>
</tr>
</tbody>
</table>
<h3>Known Issues and Limitations</h3><ul>
<li><p>The Boost Color and Distance sensor only works in color mode with the WeDo 2.0 Smart Hub.</p>
</li>
<li><p>When used with the WeDo 2.0 Smart Hub, the Boost Tacho Motor does not support rotating the motor by angle.</p>
</li>
<li><p>When used with the Powered UP Hub, the Boost Tacho Motor does not support rotating the motor by angle. It also does not support rotation detection.</p>
</li>
<li><p>Plugging two Boost Tacho Motors into the Powered UP Hub will crash the Hub (This requires a firmware update from LEGO to fix).</p>
</li>
</ul>
<h3>Documentation</h3><p><a href="https://nathankellenicki.github.io/node-poweredup/">Full documentation is available here.</a></p>
<h3>Node.js Sample Usage</h3><pre class="prettyprint source lang-javascript"><code>const PoweredUP = require(&quot;node-poweredup&quot;);
const poweredUP = new PoweredUP.PoweredUP();
poweredUP.on(&quot;discover&quot;, async (hub) => { // Wait to discover a Hub
console.log(`Discovered ${hub.name}!`);
await hub.connect(); // Connect to the Hub
console.log(&quot;Connected&quot;);
await hub.sleep(3000); // Sleep for 3 seconds before starting
while (true) { // Repeat indefinitely
console.log(&quot;Running motor B at speed 75&quot;);
hub.setMotorSpeed(&quot;B&quot;, 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
console.log(&quot;Running motor A at speed 100 for 2 seconds&quot;);
await hub.setMotorSpeed(&quot;A&quot;, 100, 2000); // Run a motor attached to port A for 2 seconds at maximum speed (100) then stop
await hub.sleep(1000); // Do nothing for 1 second
console.log(&quot;Running motor A at speed -50 for 1 seconds&quot;);
await hub.setMotorSpeed(&quot;A&quot;, -50, 1000); // Run a motor attached to port A for 1 second at 1/2 speed in reverse (-50) then stop
await hub.sleep(1000); // Do nothing for 1 second
}
});
poweredUP.scan(); // Start scanning for Hubs
console.log(&quot;Scanning for Hubs...&quot;);</code></pre><p>More examples are available in the &quot;examples&quot; directory.</p>
<h3>Credits</h3><p>Thanks go to Jorge Pereira (<a href="https://github.com/JorgePe">@JorgePe</a>), Sebastian Raff (<a href="https://github.com/hobbyquaker">@hobbyquaker</a>), Valentin Heun (<a href="https://github.com/vheun">@vheun</a>), Johan Korten (<a href="https://github.com/jakorten">@jakorten</a>), and Andrey Pokhilko (<a href="https://github.com/undera">@undera</a>) for their various works, contributions, and assistance on figuring out the LEGO Boost, WeDo 2.0, and Powered UP protocols.</p></article>
</section>
</div>
</div>
<div class="clearfix"></div>
<div class="col-md-3">
<div id="toc" class="col-md-3 hidden-xs hidden-sm hidden-md"></div>
</div>
</div>
</div>
<div class="modal fade" id="searchResults">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Search results</h4>
</div>
<div class="modal-body"></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<footer>
<span class="copyright">
node-poweredup by Nathan Kellenicki licensed under the MIT license.
</span>
<span class="jsdoc-message">
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
on Thu Apr 4th 2019
using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>
<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>
<script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>
<script>
$( function () {
$( "[id*='$']" ).each( function () {
var $this = $( this );
$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
} );
$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
var $this = $( this );
var example = $this.find( "code" );
exampleText = example.html();
var lang = /{@lang (.*?)}/.exec( exampleText );
if ( lang && lang[1] ) {
exampleText = exampleText.replace( lang[0], "" );
example.html( exampleText );
lang = lang[1];
} else {
var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
lang = langClassMatch ? langClassMatch[1] : "javascript";
}
if ( lang ) {
$this
.addClass( "sunlight-highlight-" + lang )
.addClass( "linenums" )
.html( example.html() );
}
} );
Sunlight.highlightAll( {
lineNumbers : true,
showMenu : true,
enableDoclinks : true
} );
$.catchAnchorLinks( {
navbarOffset: 10
} );
$( "#toc" ).toc( {
anchorName : function ( i, heading, prefix ) {
return $( heading ).attr( "id" ) || ( prefix + i );
},
selectors : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
showAndHide : false,
smoothScrolling: true
} );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
$( '.dropdown-toggle' ).dropdown();
$( "table" ).each( function () {
var $this = $( this );
$this.addClass('table');
} );
} );
</script>
<!--Navigation and Symbol Display-->
<!--Google Analytics-->
<script type="text/javascript">
$(document).ready(function() {
SearcherDisplay.init();
});
</script>
</body>
</html>