Rename spin speed, make hat blocks work

This commit is contained in:
Valerie Young 2019-01-08 11:53:51 -05:00
parent be35eb1f70
commit a0e1b5aa5b

View file

@ -1,7 +1,7 @@
const ArgumentType = require('../../extension-support/argument-type'); const ArgumentType = require('../../extension-support/argument-type');
const BlockType = require('../../extension-support/block-type'); const BlockType = require('../../extension-support/block-type');
const log = require('../../util/log'); const log = require('../../util/log');
// const cast = require('../../util/cast'); const Cast = require('../../util/cast');
const formatMessage = require('format-message'); const formatMessage = require('format-message');
const BLE = require('../../io/ble'); const BLE = require('../../io/ble');
const createDevice = require('@vernier/godirect').default.createDevice; const createDevice = require('@vernier/godirect').default.createDevice;
@ -193,21 +193,21 @@ class GdxFor {
return 0; return 0;
} }
getAngularSpeedX () { getSpinSpeedX () {
if (this.isConnected()) { if (this.isConnected()) {
return this._device.getSensor(5).value; return this._device.getSensor(5).value;
} }
return 0; return 0;
} }
getAngularSpeedY () { getSpinSpeedY () {
if (this.isConnected()) { if (this.isConnected()) {
return this._device.getSensor(6).value; return this._device.getSensor(6).value;
} }
return 0; return 0;
} }
getAngularSpeedZ () { getSpinSpeedZ () {
if (this.isConnected()) { if (this.isConnected()) {
return this._device.getSensor(7).value; return this._device.getSensor(7).value;
} }
@ -327,10 +327,10 @@ class Scratch3GdxForBlocks {
} }
}, },
{ {
opcode: 'whenAngularSpeedCompare', opcode: 'whenSpinSpeedCompare',
text: formatMessage({ text: formatMessage({
id: 'gdxfor.whenAngularSpeedCompare', id: 'gdxfor.whenSpinSpeedCompare',
default: 'when angular speed [DIRECTION] [COMPARE] [VALUE]', default: 'when spin speed [DIRECTION] [COMPARE] [VALUE]',
description: 'when the degrees/second value measured by the gyroscope sensor is compared to some value' description: 'when the degrees/second value measured by the gyroscope sensor is compared to some value'
}), }),
blockType: BlockType.HAT, blockType: BlockType.HAT,
@ -363,7 +363,7 @@ class Scratch3GdxForBlocks {
COMPARE: { COMPARE: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'compareOptions', menu: 'compareOptions',
defaultValue: 'x' defaultValue: ComparisonOptions.GREATER_THAN
}, },
VALUE: { VALUE: {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
@ -388,11 +388,11 @@ class Scratch3GdxForBlocks {
} }
}, },
{ {
opcode: 'getAngularSpeed', opcode: 'getSpinSpeed',
text: formatMessage({ text: formatMessage({
id: 'gdxfor.getAngularSpeed', id: 'gdxfor.getSpinSpeed',
default: 'angular speed [DIRECTION]', default: 'spin speed [DIRECTION]',
description: 'gets angular speed' description: 'gets spin speed'
}), }),
blockType: BlockType.REPORTER, blockType: BlockType.REPORTER,
arguments: { arguments: {
@ -420,14 +420,72 @@ class Scratch3GdxForBlocks {
}; };
} }
whenAccelerationCompare () { whenAccelerationCompare (args) {
return Promise.resolve(); let currentVal = 0;
switch (args.DIRECTION) {
case 'x':
currentVal = this._peripheral.getAccelerationX();
break;
case 'y':
currentVal = this._peripheral.getAccelerationY();
break;
case 'z':
currentVal = this._peripheral.getAccelerationZ();
break;
default:
log.warn(`Unknown direction in whenAccelerationCompare: ${args.DIRECTION}`);
return false;
}
switch (args.COMPARE) {
case ComparisonOptions.LESS_THAN:
return currentVal < Cast.toNumber(args.VALUE);
case ComparisonOptions.GREATER_THAN:
return currentVal > Cast.toNumber(args.VALUE);
default:
log.warn(`Unknown comparison operator in whenAccelerationCompare: ${args.COMPARE}`);
return false;
}
} }
whenAngularSpeedCompare () { whenSpinSpeedCompare (args) {
return Promise.resolve(); let currentVal = 0;
switch (args.DIRECTION) {
case 'x':
currentVal = this._peripheral.getSpinSpeedX();
break;
case 'y':
currentVal = this._peripheral.getSpinSpeedY();
break;
case 'z':
currentVal = this._peripheral.getSpinSpeedZ();
break;
default:
log.warn(`Unknown direction in whenSpinSpeedCompare: ${args.DIRECTION}`);
return false;
}
switch (args.COMPARE) {
case ComparisonOptions.LESS_THAN:
return currentVal < Cast.toNumber(args.VALUE);
case ComparisonOptions.GREATER_THAN:
return currentVal > Cast.toNumber(args.VALUE);
default:
log.warn(`Unknown comparison operator in whenSpinSpeedCompare: ${args.COMPARE}`);
return false;
}
} }
whenForceCompare () { whenForceCompare (args) {
return Promise.resolve(); switch (args.COMPARE) {
case ComparisonOptions.LESS_THAN:
return this._peripheral.getForce() < Cast.toNumber(args.VALUE);
case ComparisonOptions.GREATER_THAN:
return this._peripheral.getForce() > Cast.toNumber(args.VALUE);
default:
log.warn(`Unknown comparison operator in whenForceCompare: ${args.COMPARE}`);
return false;
}
} }
getAcceleration (args) { getAcceleration (args) {
switch (args.DIRECTION) { switch (args.DIRECTION) {
@ -441,16 +499,16 @@ class Scratch3GdxForBlocks {
log.warn(`Unknown direction in getAcceleration: ${args.DIRECTION}`); log.warn(`Unknown direction in getAcceleration: ${args.DIRECTION}`);
} }
} }
getAngularSpeed (args) { getSpinSpeed (args) {
switch (args.DIRECTION) { switch (args.DIRECTION) {
case 'x': case 'x':
return this._peripheral.getAngularSpeedX(); return this._peripheral.getSpinSpeedX();
case 'y': case 'y':
return this._peripheral.getAngularSpeedY(); return this._peripheral.getSpinSpeedY();
case 'z': case 'z':
return this._peripheral.getAngularSpeedZ(); return this._peripheral.getSpinSpeedZ();
default: default:
log.warn(`Unknown direction in getAngularSpeed: ${args.DIRECTION}`); log.warn(`Unknown direction in getSpinSpeed: ${args.DIRECTION}`);
} }
} }
getForce () { getForce () {