Clean up some null checks.

This commit is contained in:
Evelyn Eastmond 2019-06-14 11:38:36 -04:00
parent 6b9c3d12ef
commit c237f1326d

View file

@ -710,7 +710,7 @@ class EV3 {
return; return;
} }
const cmds = []; // a compound command const cmds = []; // compound command
let allocation = 0; let allocation = 0;
let sensorCount = 0; let sensorCount = 0;
@ -734,35 +734,30 @@ class EV3 {
} else { } else {
// GET SENSOR VALUES FOR CONNECTED SENSORS // GET SENSOR VALUES FOR CONNECTED SENSORS
let index = 0; let index = 0;
// eslint-disable-next-line no-undefined for (let i = 0; i < 4; i++) {
if (!this._sensorPorts.includes(undefined)) { // TODO: why is this needed? // Must check that sensor value isn't undefined (which is sometimes returned by EV3)
for (let i = 0; i < 4; i++) { if (this._sensorPorts[i] && this._sensorPorts[i] !== 'none') {
if (this._sensorPorts[i] !== 'none') { cmds[index + 0] = Ev3Opcode.OPINPUT_READSI;
cmds[index + 0] = Ev3Opcode.OPINPUT_READSI; cmds[index + 1] = Ev3Value.LAYER;
cmds[index + 1] = Ev3Value.LAYER; cmds[index + 2] = i; // PORT
cmds[index + 2] = i; // PORT cmds[index + 3] = Ev3Value.DO_NOT_CHANGE_TYPE;
cmds[index + 3] = Ev3Value.DO_NOT_CHANGE_TYPE; cmds[index + 4] = Ev3Mode[this._sensorPorts[i]];
cmds[index + 4] = Ev3Mode[this._sensorPorts[i]]; cmds[index + 5] = 225; // 0xE1 one byte to follow // TODO: document
cmds[index + 5] = 225; // 0xE1 one byte to follow // TODO: document cmds[index + 6] = sensorCount * 4; // global index // TODO: document
cmds[index + 6] = sensorCount * 4; // global index // TODO: document index += 7;
index += 7;
}
sensorCount++;
} }
sensorCount++;
} }
// GET MOTOR POSITION VALUES, EVEN IF NO MOTOR PRESENT // GET MOTOR POSITION VALUES, EVEN IF NO MOTOR PRESENT
// eslint-disable-next-line no-undefined for (let i = 0; i < 4; i++) {
if (!this._motorPorts.includes(undefined)) { cmds[index + 0] = Ev3Opcode.OPOUTPUT_GET_COUNT;
for (let i = 0; i < 4; i++) { cmds[index + 1] = Ev3Value.LAYER;
cmds[index + 0] = Ev3Opcode.OPOUTPUT_GET_COUNT; cmds[index + 2] = i; // PORT TODO: explain incorrect documentation as 'Output bit field'
cmds[index + 1] = Ev3Value.LAYER; cmds[index + 3] = 225; // 0xE1 byte following TODO: document
cmds[index + 2] = i; // PORT TODO: explain incorrect documentation as 'Output bit field' cmds[index + 4] = sensorCount * 4; // global index TODO: document
cmds[index + 3] = 225; // 0xE1 byte following TODO: document index += 5;
cmds[index + 4] = sensorCount * 4; // global index TODO: document sensorCount++;
index += 5;
sensorCount++;
}
} }
// Command and payload lengths // Command and payload lengths