408 lines
16 KiB
HTML
408 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<title>DocStrap 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">DocStrap</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://circleci.com/gh/nathankellenicki/node-poweredup"><img src="https://circleci.com/gh/nathankellenicki/node-poweredup.svg?style=shield" alt="CircleCI"></a><br><a href="https://gitter.im/node-poweredup?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"><img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter"></a><br><img src="https://img.shields.io/npm/v/node-poweredup.svg?style=flat" alt="NPM Version"></p>
|
|
<h1><strong>node-poweredup</strong> - A Node.js 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>Powered UP has a few improvements over Power Functions:</p>
|
|
<ol>
|
|
<li><p>The use of Bluetooth Low Energy makes it easy to control from a computer, and even write code for.</p>
|
|
</li>
|
|
<li><p>The ability to use sensors to react to events happening in the real world opens up a whole new world of possibilities.</p>
|
|
</li>
|
|
<li><p>As Powered UP hubs and remotes pair with each other, the system allows for a near unlimited number of independently controlled models in the same room. Power Functions was limited to 8 due to the use of infra-red for communication.</p>
|
|
</li>
|
|
</ol>
|
|
<h3>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>Sample Usage</h3><pre class="prettyprint source lang-javascript"><code>const PoweredUP = require("node-poweredup");
|
|
const poweredUP = new PoweredUP.PoweredUP();
|
|
|
|
poweredUP.on("discover", async (hub) => { // Wait to discover a Hub
|
|
await hub.connect(); // Connect to the Hub
|
|
await hub.sleep(3000); // Sleep for 3 seconds before starting
|
|
|
|
while (true) { // Repeat indefinitely
|
|
hub.setMotorSpeed("B", 75); // Start a motor attached to port B to run a 3/4 speed (75) indefinitely
|
|
await hub.setMotorSpeed("A", 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
|
|
await hub.setMotorSpeed("A", -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</code></pre><p>More examples are available in the "examples" 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">×</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 Fri Feb 1st 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> |