diff --git a/docs/BoostMoveHub.html b/docs/BoostMoveHub.html index af5a482..41ea8bb 100644 --- a/docs/BoostMoveHub.html +++ b/docs/BoostMoveHub.html @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3499,7 +3499,7 @@ @@ -3719,7 +3719,7 @@ @@ -3895,7 +3895,7 @@ @@ -4072,7 +4072,7 @@ @@ -4280,7 +4280,7 @@ @@ -4969,7 +4969,7 @@ diff --git a/docs/DuploTrainBase.html b/docs/DuploTrainBase.html index 78bb13f..28bf8e4 100644 --- a/docs/DuploTrainBase.html +++ b/docs/DuploTrainBase.html @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3162,7 +3162,7 @@ @@ -3382,7 +3382,7 @@ @@ -3558,7 +3558,7 @@ @@ -3735,7 +3735,7 @@ diff --git a/docs/Hub.html b/docs/Hub.html index 82ee874..399164b 100644 --- a/docs/Hub.html +++ b/docs/Hub.html @@ -1096,7 +1096,7 @@ @@ -1208,7 +1208,7 @@ @@ -1366,7 +1366,7 @@ @@ -1525,7 +1525,7 @@ @@ -1731,7 +1731,7 @@ @@ -1893,7 +1893,7 @@ @@ -2056,7 +2056,7 @@ @@ -2250,7 +2250,7 @@ @@ -2388,7 +2388,7 @@ diff --git a/docs/LPF2Hub.html b/docs/LPF2Hub.html index 2c2695d..4323086 100644 --- a/docs/LPF2Hub.html +++ b/docs/LPF2Hub.html @@ -1173,7 +1173,7 @@ @@ -1294,7 +1294,7 @@ @@ -1461,7 +1461,7 @@ @@ -2275,7 +2275,7 @@ @@ -2490,7 +2490,7 @@ @@ -2661,7 +2661,7 @@ @@ -2833,7 +2833,7 @@ @@ -3036,7 +3036,7 @@ @@ -3693,7 +3693,7 @@ diff --git a/docs/PUPHub.html b/docs/PUPHub.html index b57a335..86b0c35 100644 --- a/docs/PUPHub.html +++ b/docs/PUPHub.html @@ -1376,7 +1376,7 @@ @@ -1502,7 +1502,7 @@ @@ -1674,7 +1674,7 @@ @@ -3242,7 +3242,7 @@ @@ -3462,7 +3462,7 @@ @@ -3638,7 +3638,7 @@ @@ -3815,7 +3815,7 @@ @@ -4023,7 +4023,7 @@ @@ -4712,7 +4712,7 @@ diff --git a/docs/PUPRemote.html b/docs/PUPRemote.html index e1da312..eb46b05 100644 --- a/docs/PUPRemote.html +++ b/docs/PUPRemote.html @@ -1214,7 +1214,7 @@ @@ -1340,7 +1340,7 @@ @@ -1512,7 +1512,7 @@ @@ -2359,7 +2359,7 @@ @@ -2579,7 +2579,7 @@ @@ -2755,7 +2755,7 @@ @@ -2932,7 +2932,7 @@ diff --git a/docs/PoweredUP.html b/docs/PoweredUP.html index d24c06c..7bc0355 100644 --- a/docs/PoweredUP.html +++ b/docs/PoweredUP.html @@ -148,8 +148,8 @@
@@ -315,8 +315,8 @@
@@ -426,8 +426,8 @@
@@ -584,8 +584,8 @@
@@ -692,8 +692,8 @@
@@ -780,8 +780,8 @@
@@ -938,8 +938,8 @@
diff --git a/docs/WeDo2SmartHub.html b/docs/WeDo2SmartHub.html index cd0ce42..3612b05 100644 --- a/docs/WeDo2SmartHub.html +++ b/docs/WeDo2SmartHub.html @@ -153,7 +153,7 @@ @@ -1092,7 +1092,7 @@ @@ -1339,7 +1339,7 @@ @@ -1460,7 +1460,7 @@ @@ -1627,7 +1627,7 @@ @@ -1809,7 +1809,7 @@ @@ -2043,7 +2043,7 @@ @@ -2205,7 +2205,7 @@ @@ -2415,7 +2415,7 @@ @@ -2653,7 +2653,7 @@ @@ -2891,7 +2891,7 @@ @@ -3053,7 +3053,7 @@ @@ -3165,7 +3165,7 @@ @@ -3337,7 +3337,7 @@ @@ -3552,7 +3552,7 @@ @@ -3723,7 +3723,7 @@ @@ -3895,7 +3895,7 @@ @@ -4098,7 +4098,7 @@ @@ -4260,7 +4260,7 @@ @@ -4422,7 +4422,7 @@ @@ -4569,7 +4569,7 @@ @@ -4731,7 +4731,7 @@ @@ -4893,7 +4893,7 @@ @@ -5079,7 +5079,7 @@ diff --git a/docs/boostmovehub.js.html b/docs/boostmovehub.js.html index 78dee7c..4fa2dea 100644 --- a/docs/boostmovehub.js.html +++ b/docs/boostmovehub.js.html @@ -115,8 +115,8 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub { peripheral.advertisement.serviceUuids && peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.BOOST_MOVE_HUB_ID); } - constructor(peripheral, autoSubscribe = true) { - super(peripheral, autoSubscribe); + constructor(device, autoSubscribe = true) { + super(device, autoSubscribe); this.type = Consts.HubType.BOOST_MOVE_HUB; this._ports = { "A": new port_1.Port("A", 55), @@ -306,7 +306,7 @@ class BoostMoveHub extends lpf2hub_1.LPF2Hub { } } exports.BoostMoveHub = BoostMoveHub; - +//# sourceMappingURL=boostmovehub.js.map diff --git a/docs/classes.list.html b/docs/classes.list.html index c104205..b3749a3 100644 --- a/docs/classes.list.html +++ b/docs/classes.list.html @@ -335,7 +335,7 @@ @@ -1024,7 +1024,7 @@ @@ -2065,7 +2065,7 @@ @@ -2203,7 +2203,7 @@ @@ -2374,7 +2374,7 @@ @@ -3031,7 +3031,7 @@ @@ -3852,8 +3852,8 @@
@@ -4029,7 +4029,7 @@ @@ -4718,7 +4718,7 @@ @@ -5621,7 +5621,7 @@ @@ -5783,7 +5783,7 @@ @@ -5945,7 +5945,7 @@ @@ -6092,7 +6092,7 @@ @@ -6254,7 +6254,7 @@ @@ -6416,7 +6416,7 @@ @@ -6602,7 +6602,7 @@ diff --git a/docs/consts.js.html b/docs/consts.js.html index 5a3b1da..ee40a49 100644 --- a/docs/consts.js.html +++ b/docs/consts.js.html @@ -237,7 +237,7 @@ var BLECharacteristic; BLECharacteristic["WEDO2_NAME_ID"] = "00001524-1212-efde-1523-785feabcd123"; BLECharacteristic["LPF2_ALL"] = "00001624-1212-efde-1623-785feabcd123"; })(BLECharacteristic = exports.BLECharacteristic || (exports.BLECharacteristic = {})); - +//# sourceMappingURL=consts.js.map diff --git a/docs/duplotrainbase.js.html b/docs/duplotrainbase.js.html index ec4c0c6..6091e16 100644 --- a/docs/duplotrainbase.js.html +++ b/docs/duplotrainbase.js.html @@ -139,8 +139,8 @@ class DuploTrainBase extends lpf2hub_1.LPF2Hub { peripheral.advertisement.serviceUuids && peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.DUPLO_TRAIN_HUB_ID); } - constructor(peripheral, autoSubscribe = true) { - super(peripheral, autoSubscribe); + constructor(device, autoSubscribe = true) { + super(device, autoSubscribe); this.type = Consts.HubType.DUPLO_TRAIN_HUB; this._ports = { "MOTOR": new port_1.Port("MOTOR", 0), @@ -255,7 +255,7 @@ class DuploTrainBase extends lpf2hub_1.LPF2Hub { } } exports.DuploTrainBase = DuploTrainBase; - +//# sourceMappingURL=duplotrainbase.js.map diff --git a/docs/hub.js.html b/docs/hub.js.html index ec3a935..b0f8741 100644 --- a/docs/hub.js.html +++ b/docs/hub.js.html @@ -175,7 +175,6 @@ class Hub extends events_1.EventEmitter { */ connect() { return new Promise(async (connectResolve, connectReject) => { - const self = this; if (this._isConnecting) { return connectReject("Already connecting"); } @@ -185,49 +184,6 @@ class Hub extends events_1.EventEmitter { this._isConnecting = true; await this._bleDevice.connect(); return connectResolve(); - // this._peripheral.connect((err: string) => { - // this._rssi = this._peripheral.rssi; - // const rssiUpdateInterval = setInterval(() => { - // this._peripheral.updateRssi((err: string, rssi: number) => { - // if (!err) { - // if (this._rssi !== rssi) { - // this._rssi = rssi; - // } - // } - // }); - // }, 2000); - // self._peripheral.on("disconnect", () => { - // clearInterval(rssiUpdateInterval); - // this._isConnecting = false; - // this._isConnected = false; - // this.emit("disconnect"); - // }); - // self._peripheral.discoverServices([], (err: string, services: Service[]) => { - // if (err) { - // this.emit("error", err); - // return; - // } - // debug("Service/characteristic discovery started"); - // const servicePromises: Array<Promise<null>> = []; - // services.forEach((service) => { - // servicePromises.push(new Promise((resolve, reject) => { - // service.discoverCharacteristics([], (err, characteristics) => { - // characteristics.forEach((characteristic) => { - // this._characteristics[characteristic.uuid] = characteristic; - // }); - // return resolve(); - // }); - // })); - // }); - // Promise.all(servicePromises).then(() => { - // debug("Service/characteristic discovery finished"); - // this._isConnecting = false; - // this._isConnected = true; - // this.emit("connect"); - // return connectResolve(); - // }); - // }); - // }); }); } /** @@ -444,7 +400,7 @@ class Hub extends events_1.EventEmitter { } } exports.Hub = Hub; - +//# sourceMappingURL=hub.js.map diff --git a/docs/lpf2hub.js.html b/docs/lpf2hub.js.html index d117ba4..7cb292d 100644 --- a/docs/lpf2hub.js.html +++ b/docs/lpf2hub.js.html @@ -460,7 +460,7 @@ class LPF2Hub extends hub_1.Hub { } } exports.LPF2Hub = LPF2Hub; - +//# sourceMappingURL=lpf2hub.js.map diff --git a/docs/poweredup-node.js.html b/docs/poweredup-node.js.html new file mode 100644 index 0000000..f8ff746 --- /dev/null +++ b/docs/poweredup-node.js.html @@ -0,0 +1,380 @@ + + + + + + + DocStrap Source: poweredup-node.js + + + + + + + + + + + + + +
+
+ + +
+ +
+ + +

Source: poweredup-node.js

+ +
+
+
"use strict";
+var __importStar = (this && this.__importStar) || function (mod) {
+    if (mod && mod.__esModule) return mod;
+    var result = {};
+    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
+    result["default"] = mod;
+    return result;
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const bledevice_1 = require("./bledevice");
+const boostmovehub_1 = require("./boostmovehub");
+const duplotrainbase_1 = require("./duplotrainbase");
+const puphub_1 = require("./puphub");
+const pupremote_1 = require("./pupremote");
+const wedo2smarthub_1 = require("./wedo2smarthub");
+const utils_1 = require("./utils");
+const Consts = __importStar(require("./consts"));
+const events_1 = require("events");
+const Debug = require("debug");
+const debug = Debug("poweredup");
+const noble = require("noble-mac");
+let ready = false;
+let wantScan = false;
+let discoveryEventAttached = false;
+const startScanning = () => {
+    if (utils_1.isBrowserContext) {
+        noble.startScanning([Consts.BLEService.WEDO2_SMART_HUB, Consts.BLEService.LPF2_HUB]);
+    }
+    else {
+        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.autoSubscribe = true;
+        this._connectedHubs = {};
+        this._discoveryEventHandler = this._discoveryEventHandler.bind(this);
+    }
+    /**
+     * Begin scanning for Powered UP Hub devices.
+     * @method PoweredUP#scan
+     */
+    scan() {
+        wantScan = true;
+        if (!discoveryEventAttached) {
+            noble.on("discover", this._discoveryEventHandler);
+            discoveryEventAttached = true;
+        }
+        if (ready) {
+            debug("Scanning started");
+            startScanning();
+        }
+    }
+    /**
+     * 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#getConnectedHubs
+     * @returns {Hub[]}
+     */
+    getConnectedHubs() {
+        return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]);
+    }
+    /**
+     * Retrieve a Powered UP Hub by UUID.
+     * @method PoweredUP#getConnectedHubByUUID
+     * @param {string} uuid
+     * @returns {Hub | null}
+     */
+    getConnectedHubByUUID(uuid) {
+        return this._connectedHubs[uuid];
+    }
+    /**
+     * Retrieve a list of Powered UP Hub by name.
+     * @method PoweredUP#getConnectedHubsByName
+     * @param {string} name
+     * @returns {Hub[]}
+     */
+    getConnectedHubsByName(name) {
+        return Object.keys(this._connectedHubs).map((uuid) => this._connectedHubs[uuid]).filter((hub) => hub.name === name);
+    }
+    async _discoveryEventHandler(peripheral) {
+        const device = new bledevice_1.BLEDevice(peripheral);
+        let hub;
+        if (await wedo2smarthub_1.WeDo2SmartHub.IsWeDo2SmartHub(peripheral)) {
+            hub = new wedo2smarthub_1.WeDo2SmartHub(device, this.autoSubscribe);
+        }
+        else if (await boostmovehub_1.BoostMoveHub.IsBoostMoveHub(peripheral)) {
+            hub = new boostmovehub_1.BoostMoveHub(device, this.autoSubscribe);
+        }
+        else if (await puphub_1.PUPHub.IsPUPHub(peripheral)) {
+            hub = new puphub_1.PUPHub(device, this.autoSubscribe);
+        }
+        else if (await pupremote_1.PUPRemote.IsPUPRemote(peripheral)) {
+            hub = new pupremote_1.PUPRemote(device, this.autoSubscribe);
+        }
+        else if (await duplotrainbase_1.DuploTrainBase.IsDuploTrainBase(peripheral)) {
+            hub = new duplotrainbase_1.DuploTrainBase(device, this.autoSubscribe);
+        }
+        else {
+            return;
+        }
+        peripheral.removeAllListeners();
+        // noble.stopScanning();
+        // if (!isBrowserContext) {
+        //     startScanning();
+        // }
+        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 | BoostMoveHub | PUPHub | PUPRemote | DuploTrainBase} hub
+             */
+            this.emit("discover", hub);
+        });
+    }
+}
+exports.PoweredUP = PoweredUP;
+//# sourceMappingURL=poweredup-node.js.map
+
+
+ + + + + +
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/puphub.js.html b/docs/puphub.js.html index c5d4a1c..095b652 100644 --- a/docs/puphub.js.html +++ b/docs/puphub.js.html @@ -119,8 +119,8 @@ class PUPHub extends lpf2hub_1.LPF2Hub { peripheral.advertisement.serviceUuids && peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_HUB_ID); } - constructor(peripheral, autoSubscribe = true) { - super(peripheral, autoSubscribe); + constructor(device, autoSubscribe = true) { + super(device, autoSubscribe); this.type = Consts.HubType.POWERED_UP_HUB; this._ports = { "A": new port_1.Port("A", 0), @@ -263,7 +263,7 @@ class PUPHub extends lpf2hub_1.LPF2Hub { } } exports.PUPHub = PUPHub; - +//# sourceMappingURL=puphub.js.map diff --git a/docs/pupremote.js.html b/docs/pupremote.js.html index 1d379ad..7ded315 100644 --- a/docs/pupremote.js.html +++ b/docs/pupremote.js.html @@ -139,8 +139,8 @@ class PUPRemote extends lpf2hub_1.LPF2Hub { peripheral.advertisement.serviceUuids && peripheral.advertisement.serviceUuids.indexOf(Consts.BLEService.LPF2_HUB.replace(/-/g, "")) >= 0 && peripheral.advertisement.manufacturerData[3] === Consts.BLEManufacturerData.POWERED_UP_REMOTE_ID); } - constructor(peripheral, autoSubscribe = true) { - super(peripheral, autoSubscribe); + constructor(device, autoSubscribe = true) { + super(device, autoSubscribe); this.type = Consts.HubType.POWERED_UP_REMOTE; this._ports = { "LEFT": new port_1.Port("LEFT", 0), @@ -193,7 +193,7 @@ class PUPRemote extends lpf2hub_1.LPF2Hub { } } exports.PUPRemote = PUPRemote; - +//# sourceMappingURL=pupremote.js.map diff --git a/docs/quicksearch.html b/docs/quicksearch.html index 36d0011..8f2491a 100644 --- a/docs/quicksearch.html +++ b/docs/quicksearch.html @@ -7,7 +7,7 @@ + + + + +
+ +
+ + + \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 7804c98..0f649ba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ "declaration": true, /* Generates corresponding '.d.ts' file. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ + "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ "outDir": "./dist", /* Redirect output structure to the directory. */ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..82e8787 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,26 @@ +const path = require("path"); + +module.exports = { + entry: "./src/index-browser.ts", + devtool: "source-map", + module: { + rules: [ + { + test: /\.ts?$/, + use: "ts-loader", + exclude: /node_modules/ + } + ], + }, + externals: { + "noble": "noble", + "noble-mac": "noble-mac" + }, + resolve: { + extensions: [".ts", ".js"] + }, + output: { + filename: "bundle.js", + path: path.resolve(__dirname, "dist") + } +}; \ No newline at end of file