other minor feedback

This commit is contained in:
Valerie Young 2019-01-10 10:21:32 -05:00
parent 477c307304
commit ac29927c22
2 changed files with 8 additions and 25 deletions

View file

@ -3,6 +3,7 @@ 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 MathUtil = require('../../util/math-util');
const BLE = require('../../io/ble'); const BLE = require('../../io/ble');
const godirect = require('@vernier/godirect/dist/godirect.min.umd.js'); const godirect = require('@vernier/godirect/dist/godirect.min.umd.js');
const ScratchLinkDeviceAdapter = require('./scratch-link-device-adapter'); const ScratchLinkDeviceAdapter = require('./scratch-link-device-adapter');
@ -52,8 +53,8 @@ class GdxFor {
this._scratchLinkSocket = null; this._scratchLinkSocket = null;
/** /**
* A godirect device * An @vernier/godirect Device
* @type {@vernier/goDirect device} * @type {Device}
* @private * @private
*/ */
this._device = null; this._device = null;
@ -65,21 +66,6 @@ class GdxFor {
*/ */
this._extensionId = extensionId; this._extensionId = extensionId;
/**
* The most recently received value for each sensor.
* @type {Object.<string, number>}
* @private
*/
this._sensors = {
force: 0,
accelerationX: 0,
accelerationY: 0,
accelerationZ: 0,
angularVelocityX: 0,
angularVelocityY: 0,
angularVelocityZ: 0
};
this.disconnect = this.disconnect.bind(this); this.disconnect = this.disconnect.bind(this);
this._onConnect = this._onConnect.bind(this); this._onConnect = this._onConnect.bind(this);
} }
@ -154,6 +140,9 @@ class GdxFor {
_startMeasurements () { _startMeasurements () {
this._device.sensors.forEach(sensor => { this._device.sensors.forEach(sensor => {
sensor.setEnabled(true); sensor.setEnabled(true);
// For now, clear the save sensor values. The unlimited saving
// will be fixed in a future @vernier/godirect release.
sensor.on('value-changed', changedSensor => { sensor.on('value-changed', changedSensor => {
if (changedSensor.values.length > 1000) { if (changedSensor.values.length > 1000) {
changedSensor.clear(); changedSensor.clear();
@ -169,13 +158,7 @@ class GdxFor {
let force = this._device.getSensor(1).value; let force = this._device.getSensor(1).value;
// Normalize the force, which can be measured between -50 and 50 N, // Normalize the force, which can be measured between -50 and 50 N,
// to be a value between -100 and 100. // to be a value between -100 and 100.
force = force * 2; force = MathUtil.clamp(force * 2, -100, 100);
if (force > 100) {
return 100;
}
if (force < -100) {
return -100;
}
return force; return force;
} }
return 0; return 0;