Removing commented code

This commit is contained in:
Nathan Kellenicki 2019-12-10 08:21:56 +09:00
parent 5c03e5c3b6
commit 1793eb05e0
4 changed files with 79 additions and 261 deletions

View File

@ -146,68 +146,6 @@ export class BoostMoveHub extends LPF2Hub {
// }
// /**
// * Ramp the motor speed on a given port.
// * @method BoostMoveHub#rampMotorSpeed
// * @param {string} port
// * @param {number} fromSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
// * @param {number} toSpeed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0.
// * @param {number} time How long the ramp should last (in milliseconds).
// * @returns {Promise} Resolved upon successful completion of command.
// */
// public rampMotorSpeed (port: string, fromSpeed: number, toSpeed: number, time: number) {
// const portObj = this._portLookup(port);
// portObj.cancelEventTimer();
// return new Promise((resolve, reject) => {
// this._calculateRamp(fromSpeed, toSpeed, time, portObj)
// .on("changeSpeed", (speed) => {
// this.setMotorSpeed(port, speed, true);
// })
// .on("finished", resolve);
// });
// }
// /**
// * Rotate a motor by a given angle.
// * @method BoostMoveHub#setMotorAngle
// * @param {string} port
// * @param {number} angle How much the motor should be rotated (in degrees).
// * @param {number | Array.<number>} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
// * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
// */
// public setMotorAngle (port: string, angle: number, speed: number | [number, number] = 100) {
// const portObj = this._portLookup(port);
// if (!(
// portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
// portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
// )) {
// throw new Error("Angle rotation is only available when using a Boost Tacho Motor, Boost Move Hub Motor, Control+ Medium Motor, or Control+ Large Motor");
// }
// if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
// throw new Error(`Port ${portObj.id} can only accept a single speed`);
// }
// portObj.cancelEventTimer();
// return new Promise((resolve, reject) => {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// data.writeUInt32LE(angle, 4);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// });
// }
// /**
// * Tell motor to goto an absolute position
// * @method BoostMoveHub#setAbsolutePosition
@ -267,45 +205,6 @@ export class BoostMoveHub extends LPF2Hub {
// }
// /**
// * Fully (hard) stop the motor on a given port.
// * @method BoostMoveHub#brakeMotor
// * @param {string} port
// * @returns {Promise} Resolved upon successful completion of command.
// */
// public brakeMotor (port: string) {
// return this.setMotorSpeed(port, 127);
// }
// /**
// * Set the light brightness on a given port.
// * @method BoostMoveHub#setLightBrightness
// * @param {string} port
// * @param {number} brightness Brightness value between 0-100 (0 is off)
// * @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
// * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
// */
// public setLightBrightness (port: string, brightness: number, time?: number) {
// const portObj = this._portLookup(port);
// portObj.cancelEventTimer();
// return new Promise((resolve, reject) => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// if (time) {
// const timeout = global.setTimeout(() => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// return resolve();
// }, time);
// portObj.setEventTimer(timeout);
// } else {
// return resolve();
// }
// });
// }
protected _checkFirmware (version: string) {
if (compareVersion("2.0.00.0017", version) === 1) {
throw new Error(`Your Boost Move Hub's (${this.name}) firmware is out of date and unsupported by this library. Please update it via the official Powered Up app.`);

View File

@ -65,88 +65,88 @@ export class ControlPlusHub extends LPF2Hub {
}
/**
* Set the motor speed on a given port.
* @method ControlPlusHub#setMotorSpeed
* @param {string} port
* @param {number | Array.<number>} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
* @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
* @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
*/
public setMotorSpeed (port: string, speed: number | [number, number], time?: number | boolean) {
// const portObj = this._portLookup(port);
// if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
// throw new Error(`Port ${portObj.id} can only accept a single speed`);
// }
// let cancelEventTimer = true;
// if (typeof time === "boolean") {
// if (time === true) {
// cancelEventTimer = false;
// }
// time = undefined;
// }
// if (cancelEventTimer) {
// portObj.cancelEventTimer();
// }
// return new Promise((resolve, reject) => {
// if (time && typeof time === "number") {
// /**
// * Set the motor speed on a given port.
// * @method ControlPlusHub#setMotorSpeed
// * @param {string} port
// * @param {number | Array.<number>} speed For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
// * @param {number} [time] How long to activate the motor for (in milliseconds). Leave empty to turn the motor on indefinitely.
// * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the motor is finished.
// */
// public setMotorSpeed (port: string, speed: number | [number, number], time?: number | boolean) {
// const portObj = this._portLookup(port);
// if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
// throw new Error(`Port ${portObj.id} can only accept a single speed`);
// }
// let cancelEventTimer = true;
// if (typeof time === "boolean") {
// if (time === true) {
// cancelEventTimer = false;
// }
// time = undefined;
// }
// if (cancelEventTimer) {
// portObj.cancelEventTimer();
// }
// return new Promise((resolve, reject) => {
// if (time && typeof time === "number") {
// if (
// portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
// portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
// ) {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0a, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// data.writeUInt16LE(time > 65535 ? 65535 : time, 4);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// const timeout = global.setTimeout(() => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// return resolve();
// // @ts-ignore: The type of time is properly checked at the start
// }, time);
// portObj.setEventTimer(timeout);
// }
// if (
// portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
// portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
// ) {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0a, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x09, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// data.writeUInt16LE(time > 65535 ? 65535 : time, 4);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// const timeout = global.setTimeout(() => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// return resolve();
// // @ts-ignore: The type of time is properly checked at the start
// }, time);
// portObj.setEventTimer(timeout);
// }
// } else {
// } else {
// if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// }
// if (portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR || portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR) {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x02, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x01, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, this._mapSpeed(speed)]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// }
// }
// });
}
// }
// });
// }
// /**
@ -171,46 +171,6 @@ export class ControlPlusHub extends LPF2Hub {
// }
// /**
// * Rotate a motor by a given angle.
// * @method ControlPlusHub#setMotorAngle
// * @param {string} port
// * @param {number} angle How much the motor should be rotated (in degrees).
// * @param {number | Array.<number>} [speed=100] For forward, a value between 1 - 100 should be set. For reverse, a value between -1 to -100. Stop is 0. If you are specifying port AB to control both motors, you can optionally supply a tuple of speeds.
// * @returns {Promise} Resolved upon successful completion of command (ie. once the motor is finished).
// */
// public setMotorAngle (port: string, angle: number, speed: number | [number, number] = 100) {
// const portObj = this._portLookup(port);
// if (!(
// portObj.type === Consts.DeviceType.BOOST_TACHO_MOTOR ||
// portObj.type === Consts.DeviceType.BOOST_MOVE_HUB_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_LARGE_MOTOR ||
// portObj.type === Consts.DeviceType.CONTROL_PLUS_XLARGE_MOTOR
// )) {
// throw new Error("Angle rotation is only available when using a Boost Tacho Motor, Boost Move Hub Motor, Control+ Medium Motor, or Control+ Large Motor");
// }
// if (!this._virtualPorts[portObj.id] && speed instanceof Array) {
// throw new Error(`Port ${portObj.id} can only accept a single speed`);
// }
// portObj.cancelEventTimer();
// return new Promise((resolve, reject) => {
// portObj.busy = true;
// let data = null;
// if (this._virtualPorts[portObj.id]) {
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed instanceof Array ? speed[0] : speed), this._mapSpeed(speed instanceof Array ? speed[1] : speed), 0x64, 0x7f, 0x03]);
// } else {
// // @ts-ignore: The type of speed is properly checked at the start
// data = Buffer.from([0x81, portObj.value, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, this._mapSpeed(speed), 0x64, 0x7f, 0x03]);
// }
// data.writeUInt32LE(angle, 4);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// portObj.finished = () => {
// return resolve();
// };
// });
// }
// /**
// * Tell motor to goto an absolute position
// * @method ControlPlusHub#setAbsolutePosition
@ -270,43 +230,4 @@ export class ControlPlusHub extends LPF2Hub {
// }
/**
* Fully (hard) stop the motor on a given port.
* @method ControlPlusHub#brakeMotor
* @param {string} port
* @returns {Promise} Resolved upon successful completion of command.
*/
public brakeMotor (port: string) {
return this.setMotorSpeed(port, 127);
}
// /**
// * Set the light brightness on a given port.
// * @method ControlPlusHub#setLightBrightness
// * @param {string} port
// * @param {number} brightness Brightness value between 0-100 (0 is off)
// * @param {number} [time] How long to turn the light on (in milliseconds). Leave empty to turn the light on indefinitely.
// * @returns {Promise} Resolved upon successful completion of command. If time is specified, this is once the light is turned off.
// */
// public setLightBrightness (port: string, brightness: number, time?: number) {
// const portObj = this._portLookup(port);
// portObj.cancelEventTimer();
// return new Promise((resolve, reject) => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, brightness]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// if (time) {
// const timeout = global.setTimeout(() => {
// const data = Buffer.from([0x81, portObj.value, 0x11, 0x51, 0x00, 0x00]);
// this.send(data, Consts.BLECharacteristic.LPF2_ALL);
// return resolve();
// }, time);
// portObj.setEventTimer(timeout);
// } else {
// return resolve();
// }
// });
// }
}

View File

@ -50,6 +50,7 @@ export class DuploTrainBase extends LPF2Hub {
return new Promise(async (resolve, reject) => {
debug("Connecting to Duplo Train Base");
await super.connect();
this.subscribe(0x01, 0x01);
debug("Connect completed");
return resolve();
});

View File

@ -46,9 +46,6 @@ export class LPF2Hub extends Hub {
if (this._currentPort !== undefined) {
this.subscribe(this._currentPort, 0x00); // Activate currrent reports
}
if (this.type === Consts.HubType.DUPLO_TRAIN_HUB) {
this.subscribe(0x01, 0x01);
}
await this.sleep(100);
this.send(Buffer.from([0x01, 0x02, 0x02]), Consts.BLECharacteristic.LPF2_ALL); // Activate button reports
this.send(Buffer.from([0x01, 0x03, 0x05]), Consts.BLECharacteristic.LPF2_ALL); // Request firmware version