UNPKG

swarms

Version:

The ultimate node.js library for controlling Bitcraze Crazyflie 2.0 drones

62 lines 1.69 kB
"use strict"; /** * @file Wrappers around the node-usb stuff to be a node.js stream */ Object.defineProperty(exports, "__esModule", { value: true }); const stream_1 = require("stream"); class InStream extends stream_1.Readable { /** * Stream from dongle --> PC */ constructor(endpoint) { super(); this.endpoint = endpoint; this.polling = false; this.endpoint.on('data', this.onData.bind(this)); this.endpoint.on('error', this.onError.bind(this)); this.endpoint.on('end', this.onEnd.bind(this)); } _read(size) { if (!this.polling) { this.polling = true; this.endpoint.startPoll(3, 64); } } onData(chunk) { if (!this.push(chunk)) { this.polling = false; // Disable line because callback is required, but we don't need anything in it (?) // tslint:disable-next-line:no-empty this.endpoint.stopPoll(() => { }); } } onError(err) { this.emit('error', err); } onEnd() { this.push(null); } } exports.InStream = InStream; class OutStream extends stream_1.Writable { /** * Stream from PC --> dongle */ constructor(endpoint) { super({ decodeStrings: false }); this.endpoint = endpoint; this.endpoint.on('error', this.onError.bind(this)); } _write(chunk, encoding, callback) { this.endpoint.transfer(chunk, err => { callback(new Error(err)); }); } onError(err) { this.emit('error', err); } } exports.OutStream = OutStream; //# sourceMappingURL=usbstreams.js.map