noticed several instances of getting especially power and direction properties from private variables instead of using the getter

This commit is contained in:
Kevin Andersen 2019-04-08 17:48:30 -04:00
parent e986b0f4cb
commit e24ace83a0

View file

@ -446,8 +446,8 @@ class BoostMotor {
BoostOutputExecution.EXECUTE_IMMEDIATELY, BoostOutputExecution.EXECUTE_IMMEDIATELY,
BoostOutputSubCommand.START_SPEED, BoostOutputSubCommand.START_SPEED,
[ [
this._power * this._direction, this.power * this.direction,
MathUtil.clamp(this._power + BoostMotorMaxPowerAdd, 0, 100), MathUtil.clamp(this.power + BoostMotorMaxPowerAdd, 0, 100),
BoostMotorProfile.DO_NOT_USE BoostMotorProfile.DO_NOT_USE
]); ]);
this._status = BoostPortFeedback.BUSY_OR_FULL; this._status = BoostPortFeedback.BUSY_OR_FULL;
@ -462,7 +462,7 @@ class BoostMotor {
* @param {number} milliseconds - run the motor for this long. * @param {number} milliseconds - run the motor for this long.
*/ */
turnOnFor (milliseconds) { turnOnFor (milliseconds) {
if (this._power === 0) return; if (this.power === 0) return;
milliseconds = Math.max(0, milliseconds); milliseconds = Math.max(0, milliseconds);
this.turnOn(); this.turnOn();
@ -475,7 +475,7 @@ class BoostMotor {
* @param {number} direction - rotate in this direction * @param {number} direction - rotate in this direction
*/ */
turnOnForDegrees (degrees, direction) { turnOnForDegrees (degrees, direction) {
if (this._power === 0) return; if (this.power === 0) return;
degrees = Math.max(0, degrees); degrees = Math.max(0, degrees);
const cmd = this._parent.generateOutputCommand( const cmd = this._parent.generateOutputCommand(
@ -484,15 +484,15 @@ class BoostMotor {
BoostOutputSubCommand.START_SPEED_FOR_DEGREES, BoostOutputSubCommand.START_SPEED_FOR_DEGREES,
[ [
...numberToInt32Array(degrees), ...numberToInt32Array(degrees),
this._power * this._direction * direction, this.power * this.direction * direction,
MathUtil.clamp(this._power + BoostMotorMaxPowerAdd, 0, 100), MathUtil.clamp(this.power + BoostMotorMaxPowerAdd, 0, 100),
BoostMotorEndState.BRAKE, BoostMotorEndState.BRAKE,
BoostMotorProfile.DO_NOT_USE BoostMotorProfile.DO_NOT_USE
] ]
); );
this._pendingPositionOrigin = this._position; this._pendingPositionOrigin = this.position;
this._pendingPositionDestination = this._position + (degrees * this._direction * direction); this._pendingPositionDestination = this.position + (degrees * this.direction * direction);
this._parent.send(BoostBLE.characteristic, cmd); this._parent.send(BoostBLE.characteristic, cmd);
} }
@ -501,7 +501,7 @@ class BoostMotor {
* @param {boolean} [useLimiter=true] - if true, use the rate limiter * @param {boolean} [useLimiter=true] - if true, use the rate limiter
*/ */
turnOff (useLimiter = true) { turnOff (useLimiter = true) {
if (this._power === 0) return; if (this.power === 0) return;
const cmd = this._parent.generateOutputCommand( const cmd = this._parent.generateOutputCommand(
this._index, this._index,
@ -1794,7 +1794,7 @@ class Scratch3BoostBlocks {
log.warn('Asked for a motor position that doesnt exist!'); log.warn('Asked for a motor position that doesnt exist!');
return false; return false;
} }
if (portID && this._peripheral._motors[portID]) { if (portID && this.motor([portID])) {
return MathUtil.wrapClamp(this._peripheral._motors[portID].position, 0, 360); return MathUtil.wrapClamp(this._peripheral._motors[portID].position, 0, 360);
} }
return 0; return 0;