385 lines
11 KiB
HTML
385 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<title>node-poweredup Source: poweredup-node.js</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="PoweredUP.html">PoweredUP</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="PoweredUP.html#event:discover">PoweredUP#event:discover</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-12">
|
|
|
|
<div id="main">
|
|
|
|
|
|
<h1 class="page-title">Source: poweredup-node.js</h1>
|
|
|
|
<section>
|
|
<article>
|
|
<pre
|
|
class="sunlight-highlight-javascript linenums">"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const nobleabstraction_1 = require("./nobleabstraction");
|
|
const duplotrainbase_1 = require("./hubs/duplotrainbase");
|
|
const hub_1 = require("./hubs/hub");
|
|
const movehub_1 = require("./hubs/movehub");
|
|
const remotecontrol_1 = require("./hubs/remotecontrol");
|
|
const technicmediumhub_1 = require("./hubs/technicmediumhub");
|
|
const wedo2smarthub_1 = require("./hubs/wedo2smarthub");
|
|
const events_1 = require("events");
|
|
const Debug = require("debug");
|
|
const debug = Debug("poweredup");
|
|
const noble = require("@abandonware/noble");
|
|
let ready = false;
|
|
let wantScan = false;
|
|
let discoveryEventAttached = false;
|
|
const startScanning = () => {
|
|
noble.startScanning();
|
|
};
|
|
noble.on("stateChange", (state) => {
|
|
ready = (state === "poweredOn");
|
|
if (ready) {
|
|
if (wantScan) {
|
|
debug("Scanning started");
|
|
startScanning();
|
|
}
|
|
}
|
|
else {
|
|
noble.stopScanning();
|
|
}
|
|
});
|
|
/**
|
|
* @class PoweredUP
|
|
* @extends EventEmitter
|
|
*/
|
|
class PoweredUP extends events_1.EventEmitter {
|
|
constructor() {
|
|
super();
|
|
this._connectedHubs = {};
|
|
this._discoveryEventHandler = this._discoveryEventHandler.bind(this);
|
|
}
|
|
/**
|
|
* Begin scanning for Powered UP Hub devices.
|
|
* @method PoweredUP#scan
|
|
*/
|
|
async scan() {
|
|
wantScan = true;
|
|
if (!discoveryEventAttached) {
|
|
noble.on("discover", this._discoveryEventHandler);
|
|
discoveryEventAttached = true;
|
|
}
|
|
if (ready) {
|
|
debug("Scanning started");
|
|
startScanning();
|
|
}
|
|
return true;
|
|
}
|
|
/**
|
|
* Stop scanning for Powered UP Hub devices.
|
|
* @method PoweredUP#stop
|
|
*/
|
|
stop() {
|
|
wantScan = false;
|
|
if (discoveryEventAttached) {
|
|
noble.removeListener("discover", this._discoveryEventHandler);
|
|
discoveryEventAttached = false;
|
|
}
|
|
noble.stopScanning();
|
|
}
|
|
/**
|
|
* Retrieve a list of Powered UP Hubs.
|
|
* @method PoweredUP#getHubs
|
|
* @returns {BaseHub[]}
|
|
*/
|
|
getHubs() {
|
|
return Object.values(this._connectedHubs);
|
|
}
|
|
/**
|
|
* Retrieve a Powered UP Hub by UUID.
|
|
* @method PoweredUP#getHubByUUID
|
|
* @param {string} uuid
|
|
* @returns {BaseHub | null}
|
|
*/
|
|
getHubByUUID(uuid) {
|
|
return this._connectedHubs[uuid];
|
|
}
|
|
/**
|
|
* Retrieve a Powered UP Hub by primary MAC address.
|
|
* @method PoweredUP#getHubByPrimaryMACAddress
|
|
* @param {string} address
|
|
* @returns {BaseHub}
|
|
*/
|
|
getHubByPrimaryMACAddress(address) {
|
|
return Object.values(this._connectedHubs).filter((hub) => hub.primaryMACAddress === address)[0];
|
|
}
|
|
/**
|
|
* Retrieve a list of Powered UP Hub by name.
|
|
* @method PoweredUP#getHubsByName
|
|
* @param {string} name
|
|
* @returns {BaseHub[]}
|
|
*/
|
|
getHubsByName(name) {
|
|
return Object.values(this._connectedHubs).filter((hub) => hub.name === name);
|
|
}
|
|
/**
|
|
* Retrieve a list of Powered UP Hub by type.
|
|
* @method PoweredUP#getHubsByType
|
|
* @param {string} name
|
|
* @returns {BaseHub[]}
|
|
*/
|
|
getHubsByType(hubType) {
|
|
return Object.values(this._connectedHubs).filter((hub) => hub.type === hubType);
|
|
}
|
|
async _discoveryEventHandler(peripheral) {
|
|
peripheral.removeAllListeners();
|
|
const device = new nobleabstraction_1.NobleDevice(peripheral);
|
|
let hub;
|
|
if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) {
|
|
hub = new wedo2smarthub_1.WeDo2SmartHub(device);
|
|
}
|
|
else if (await movehub_1.MoveHub.IsMoveHub(peripheral)) {
|
|
hub = new movehub_1.MoveHub(device);
|
|
}
|
|
else if (await hub_1.Hub.IsHub(peripheral)) {
|
|
hub = new hub_1.Hub(device);
|
|
}
|
|
else if (await remotecontrol_1.RemoteControl.IsRemoteControl(peripheral)) {
|
|
hub = new remotecontrol_1.RemoteControl(device);
|
|
}
|
|
else if (await duplotrainbase_1.DuploTrainBase.IsDuploTrainBase(peripheral)) {
|
|
hub = new duplotrainbase_1.DuploTrainBase(device);
|
|
}
|
|
else if (await technicmediumhub_1.TechnicMediumHub.IsTechnicMediumHub(peripheral)) {
|
|
hub = new technicmediumhub_1.TechnicMediumHub(device);
|
|
}
|
|
else {
|
|
return;
|
|
}
|
|
device.on("discoverComplete", () => {
|
|
hub.on("connect", () => {
|
|
debug(`Hub ${hub.uuid} connected`);
|
|
this._connectedHubs[hub.uuid] = hub;
|
|
});
|
|
hub.on("disconnect", () => {
|
|
debug(`Hub ${hub.uuid} disconnected`);
|
|
delete this._connectedHubs[hub.uuid];
|
|
if (wantScan) {
|
|
startScanning();
|
|
}
|
|
});
|
|
debug(`Hub ${hub.uuid} discovered`);
|
|
/**
|
|
* Emits when a Powered UP Hub device is found.
|
|
* @event PoweredUP#discover
|
|
* @param {WeDo2SmartHub | MoveHub | TechnicMediumHub | Hub | RemoteControl | DuploTrainBase} hub
|
|
*/
|
|
this.emit("discover", hub);
|
|
});
|
|
}
|
|
}
|
|
exports.PoweredUP = PoweredUP;
|
|
//# sourceMappingURL=poweredup-node.js.map</pre>
|
|
</article>
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="clearfix"></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.6.3</a>
|
|
|
|
on Fri Feb 7th 2020
|
|
|
|
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>
|